#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "common.h"
int
main(void)
{
int res, err, fd;
res = signalfd(-1, NULL, 0);
err = errno;
if (res != -1 || err != EFAULT) {
test_fail("expected EFAULT for NULL signal mask"
", found res=%d errno=%d", res, err);
}
sigset_t mask;
assert(sigemptyset(&mask) == 0);
res = signalfd(-1, &mask, ~0);
err = errno;
if (res != -1 || err != EINVAL) {
test_fail("expected EINVAL bad flags"
", found res=%d errno=%d", res, err);
}
res = signalfd(-1, &mask, 0);
err = errno;
if (res < 0) {
test_fail("failed to open signalfd, found res=%d errno=%d",
res, err);
}
fd = res;
res = fcntl(fd, F_GETFL, 0);
assert(res >= 0);
if ((res & O_NONBLOCK) != 0) {
test_fail("expected no O_NONBLOCK, found flags=0x%x", res);
}
res = fcntl(fd, F_GETFD, 0);
assert(res >= 0);
if ((res & FD_CLOEXEC) != 0) {
test_fail("expected no FD_CLOEXEC, found fdflags=0x%x", res);
}
(void) close(fd);
res = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
err = errno;
if (res < 0) {
test_fail("failed to open signalfd, found res=%d errno=%d",
res, err);
}
fd = res;
res = fcntl(fd, F_GETFL, 0);
assert(res >= 0);
if ((res & O_NONBLOCK) == 0) {
test_fail("missing O_NONBLOCK, found flags=0x%x", res);
}
res = fcntl(fd, F_GETFD, 0);
assert(res >= 0);
if ((res & FD_CLOEXEC) == 0) {
test_fail("missing FD_CLOEXEC, found fdflags=0x%x", res);
}
(void) close(fd);
test_pass();
}