73 lines
1.4 KiB
C
Raw Normal View History

2023-07-02 19:51:09 +02:00
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OpenBSD__)
/* NOLINTNEXTLINE(bugprone-reserved-identifier) */
# define _XOPEN_SOURCE 600
#endif
2020-08-30 11:54:41 +02:00
#if defined(_WIN32)
# include <windows.h>
#else
2022-11-16 20:14:03 +01:00
# include <sched.h>
2020-08-30 11:54:41 +02:00
# include <unistd.h>
#endif
#include <stdio.h>
2023-07-02 19:51:09 +02:00
#ifdef SIGNAL
# include <errno.h>
# include <signal.h>
# include <string.h>
static unsigned int signal_count;
static void signal_handler(int signum)
{
(void)signum;
++signal_count;
}
#endif
2020-08-30 11:54:41 +02:00
int main(void)
{
#ifdef FORK
pid_t pid = fork();
if (pid != 0) {
return 0;
}
#endif
2023-07-02 19:51:09 +02:00
#ifdef SIGNAL
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = signal_handler;
while ((sigaction(SIGUSR1, &sa, NULL) < 0) && (errno == EINTR))
;
#endif
2020-08-30 11:54:41 +02:00
#if defined(_WIN32)
Sleep((TIMEOUT + 4) * 1000);
2023-07-02 19:51:09 +02:00
#elif defined(SIGNAL_IGNORE)
2023-12-23 22:40:16 +01:00
# if defined(__CYGWIN__) || defined(__sun__) || defined(__GNU__)
2023-07-02 19:51:09 +02:00
# define ERRNO_IS_EINTR (errno == EINTR || errno == 0)
# else
# define ERRNO_IS_EINTR (errno == EINTR)
# endif
{
unsigned int timeLeft = (TIMEOUT + 4 + SIGNAL_IGNORE);
while ((timeLeft = sleep(timeLeft), timeLeft > 0 && ERRNO_IS_EINTR)) {
printf("EINTR: timeLeft=%u\n", timeLeft);
fflush(stdout);
}
}
2020-08-30 11:54:41 +02:00
#else
sleep((TIMEOUT + 4));
#endif
2023-07-02 19:51:09 +02:00
#ifdef SIGNAL
if (signal_count > 0) {
printf("SIGUSR1: count=%u\n", signal_count);
fflush(stdout);
}
#endif
2020-08-30 11:54:41 +02:00
return 0;
}