12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include <support/xthread.h>
- #include <support/xsignal.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <support/check.h>
- #include <time.h>
- static void *
- delayed_exit_thread (void *seconds_as_ptr)
- {
- int seconds = (uintptr_t) seconds_as_ptr;
- struct timespec delay = { seconds, 0 };
- struct timespec remaining = { 0 };
- if (nanosleep (&delay, &remaining) != 0)
- FAIL_EXIT1 ("nanosleep: %m");
-
- exit (0);
- return NULL;
- }
- void
- delayed_exit (int seconds)
- {
-
- sigset_t all_blocked;
- sigfillset (&all_blocked);
- sigset_t old_set;
- xpthread_sigmask (SIG_SETMASK, &all_blocked, &old_set);
-
- pthread_t thr = xpthread_create
- (NULL, delayed_exit_thread, (void *) (uintptr_t) seconds);
- xpthread_detach (thr);
-
- xpthread_sigmask (SIG_SETMASK, &old_set, NULL);
- }
|