Commit 3cc38afd authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Reindent. Return with a non-zero exit status on failure.

parent bd5cb9e9
......@@ -73,77 +73,81 @@ sig_atomic_t ctr = 0;
static void
my_sighandler(int UNUSED(x))
{
ctr++;
ctr++;
}
int
main(void)
{
fd_set r;
struct timeval timeout;
fd_set r;
struct timeval timeout;
#ifdef HAVE_STRUCT_SIGACTION
struct sigaction act;
struct sigaction act;
#endif
int rv;
int er;
time_t before;
time_t after;
pid_t pid;
int rv;
int er;
time_t before;
time_t after;
pid_t pid;
if ((pid = fork()) < 0)
if ((pid = fork()) < 0)
{
perror("fork");
return 1;
perror("fork");
return 1;
}
if (pid == 0)
if (pid == 0)
{
sleep(1);
kill(getppid(), SIGHUP);
sleep(5); /* avoid triggering a SIGCHLD */
return 0;
sleep(1);
kill(getppid(), SIGHUP);
sleep(5); /* avoid triggering a SIGCHLD */
return 0;
}
#ifdef HAVE_STRUCT_SIGACTION
sigemptyset(&act.sa_mask);
act.sa_flags = SA_RESTART;
act.sa_handler = my_sighandler;
if (sigaction(SIGHUP, &act, NULL) < 0)
{
perror("sigaction");
return 1;
}
sigemptyset(&act.sa_mask);
act.sa_flags = SA_RESTART;
act.sa_handler = my_sighandler;
if (sigaction(SIGHUP, &act, NULL) < 0)
{
perror("sigaction");
return 1;
}
#else
if (signal(SIGHUP, my_sighandler) == SIG_ERR)
{
perror("signal");
return 1;
}
if (signal(SIGHUP, my_sighandler) == SIG_ERR)
{
perror("signal");
return 1;
}
#endif
FD_ZERO(&r);
FD_SET(0, &r);
timeout.tv_sec = 5;
timeout.tv_usec = 0;
time(&before);
rv = select(1, &r, NULL, NULL, &timeout);
er = errno;
time(&after);
FD_ZERO(&r);
FD_SET(0, &r);
timeout.tv_sec = 5;
timeout.tv_usec = 0;
if (rv == 0)
printf("select: timeout\n");
else if (rv > 0)
printf("select: input available\n");
else if (er != EINTR)
printf("select: fail: %s\n", strerror(er));
time(&before);
rv = select(1, &r, NULL, NULL, &timeout);
er = errno;
time(&after);
if (after - before < 3 && rv < 0 && er == EINTR && ctr == 1)
printf("PASS: select returns EINTR\n");
else
printf("FAIL: select returns EINTR (got %d signals) (%d seconds)"
" (retval=%d)\n",
(int)ctr, (int)(after - before), (int)rv);
if (rv == 0)
printf("select: timeout\n");
else if (rv > 0)
printf("select: input available\n");
else if (er != EINTR)
printf("select: fail: %s\n", strerror(er));
return 0;
if (after - before < 3 && rv < 0 && er == EINTR && ctr == 1)
{
printf("PASS: select returns EINTR\n");
return 0;
}
else
{
printf("FAIL: select returns EINTR (got %d signals) (%d seconds)"
" (retval=%d)\n",
(int)ctr, (int)(after - before), (int)rv);
return 1;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment