mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-06 13:51:28 +00:00
Before, pause() was emulated by sleeping for 1s in a loop until signal interrupted it. If signal arrived in-between these invocations then pause() could never return. Also, pause() incorrectly returned 0 instead of -1 and errno=EINTR. This patch emulates pause() by sleeping for a very long time (years). Also, it correctly returns EINTR.
28 lines
451 B
C
28 lines
451 B
C
#include <assert.h>
|
|
#include <errno.h>
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
void handler(int signal)
|
|
{
|
|
printf("hello world\n");
|
|
}
|
|
|
|
int main(int argc, char ** argv)
|
|
{
|
|
if (signal(SIGALRM, &handler) < 0)
|
|
return EXIT_FAILURE;
|
|
|
|
if (alarm(1) < 0)
|
|
return EXIT_FAILURE;
|
|
|
|
int ret = pause();
|
|
assert(ret == -1);
|
|
assert(errno == EINTR);
|
|
|
|
printf("good bye\n");
|
|
return 0;
|
|
}
|