uk_UA: Add alternative month names (bug 10871).
[glibc.git] / support / delayed_exit.c
blob2780d9a6fe61ac5e4b04547ad9c13e1259809cd1
1 /* Time-triggered process termination.
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <support/xthread.h>
20 #include <support/xsignal.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <support/check.h>
26 #include <time.h>
28 static void *
29 delayed_exit_thread (void *seconds_as_ptr)
31 int seconds = (uintptr_t) seconds_as_ptr;
32 struct timespec delay = { seconds, 0 };
33 struct timespec remaining = { 0 };
34 if (nanosleep (&delay, &remaining) != 0)
35 FAIL_EXIT1 ("nanosleep: %m");
36 /* Exit the process sucessfully. */
37 exit (0);
38 return NULL;
41 void
42 delayed_exit (int seconds)
44 /* Create the new thread with all signals blocked. */
45 sigset_t all_blocked;
46 sigfillset (&all_blocked);
47 sigset_t old_set;
48 xpthread_sigmask (SIG_SETMASK, &all_blocked, &old_set);
49 /* Create a detached thread. */
50 pthread_t thr = xpthread_create
51 (NULL, delayed_exit_thread, (void *) (uintptr_t) seconds);
52 xpthread_detach (thr);
53 /* Restore the original signal mask. */
54 xpthread_sigmask (SIG_SETMASK, &old_set, NULL);