Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/nanosleep.c @ 9309:bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 07 Oct 2007 19:14:58 +0200 |
parents | b31580167c2b |
children | 51cc8a81238b |
rev | line source |
---|---|
2052 | 1 /* Provide a replacement for the POSIX nanosleep function. |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
2 |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
3 Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006, 2007 Free |
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
4 Software Foundation, Inc. |
2052 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
2052 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
9 (at your option) any later version. |
2052 | 10 |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8146
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
2052 | 18 |
19 /* written by Jim Meyering */ | |
20 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
7298
diff
changeset
|
21 #include <config.h> |
2270 | 22 |
8146
b31580167c2b
New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
7897
diff
changeset
|
23 #include <time.h> |
2270 | 24 |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
25 #include "timespec.h" |
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
26 |
5159 | 27 #include <stdbool.h> |
2053 | 28 #include <stdio.h> |
7298
6948138d9f3a
* nanosleep.c: Include <sys/types.h> before sys/select.h, to avoid
Jim Meyering <jim@meyering.net>
parents:
7237
diff
changeset
|
29 #include <sys/types.h> |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
30 #if HAVE_SYS_SELECT_H |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
31 # include <sys/select.h> |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
32 #endif |
2053 | 33 #include <signal.h> |
2052 | 34 |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
35 #include <sys/time.h> |
2057 | 36 #include <errno.h> |
37 | |
6275 | 38 #include <unistd.h> |
2056 | 39 |
8146
b31580167c2b
New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
7897
diff
changeset
|
40 #undef nanosleep |
b31580167c2b
New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
7897
diff
changeset
|
41 |
7237
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
42 enum { BILLION = 1000 * 1000 * 1000 }; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
43 |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
44 #if HAVE_BUG_BIG_NANOSLEEP |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
45 |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
46 void |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
47 getnow (struct timespec *t) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
48 { |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
49 # if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
50 if (clock_gettime (CLOCK_MONOTONIC, t) == 0) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
51 return; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
52 # endif |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
53 gettime (t); |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
54 } |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
55 |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
56 int |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
57 rpl_nanosleep (const struct timespec *requested_delay, |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
58 struct timespec *remaining_delay) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
59 { |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
60 /* nanosleep mishandles large sleeps due to internal overflow |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
61 problems, so check that the proper amount of time has actually |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
62 elapsed. */ |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
63 |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
64 struct timespec delay = *requested_delay; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
65 struct timespec t0; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
66 getnow (&t0); |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
67 |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
68 for (;;) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
69 { |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
70 int r = nanosleep (&delay, remaining_delay); |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
71 if (r == 0) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
72 { |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
73 time_t secs_sofar; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
74 struct timespec now; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
75 getnow (&now); |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
76 |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
77 secs_sofar = now.tv_sec - t0.tv_sec; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
78 if (requested_delay->tv_sec < secs_sofar) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
79 return 0; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
80 delay.tv_sec = requested_delay->tv_sec - secs_sofar; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
81 delay.tv_nsec = requested_delay->tv_nsec - (now.tv_nsec - t0.tv_nsec); |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
82 if (delay.tv_nsec < 0) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
83 { |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
84 if (delay.tv_sec == 0) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
85 return 0; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
86 delay.tv_nsec += BILLION; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
87 delay.tv_sec--; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
88 } |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
89 else if (BILLION <= delay.tv_nsec) |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
90 { |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
91 delay.tv_nsec -= BILLION; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
92 delay.tv_sec++; |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
93 } |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
94 } |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
95 } |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
96 } |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
97 |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
98 #else |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
99 |
2687
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
100 /* Some systems (MSDOS) don't have SIGCONT. |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
101 Using SIGTERM here turns the signal-handling code below |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
102 into a no-op on such systems. */ |
7237
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
103 # ifndef SIGCONT |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
104 # define SIGCONT SIGTERM |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
105 # endif |
2687
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
106 |
7237
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
107 # if ! HAVE_SIGINTERRUPT |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
108 # define siginterrupt(sig, flag) /* empty */ |
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
109 # endif |
2052 | 110 |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
111 static sig_atomic_t volatile suspended; |
2052 | 112 |
2053 | 113 /* Handle SIGCONT. */ |
114 | |
115 static void | |
116 sighandler (int sig) | |
117 { | |
118 suspended = 1; | |
119 } | |
120 | |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
121 /* Suspend execution for at least *TS_DELAY seconds. */ |
2052 | 122 |
123 static void | |
2056 | 124 my_usleep (const struct timespec *ts_delay) |
2052 | 125 { |
126 struct timeval tv_delay; | |
127 tv_delay.tv_sec = ts_delay->tv_sec; | |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
128 tv_delay.tv_usec = (ts_delay->tv_nsec + 999) / 1000; |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
129 if (tv_delay.tv_usec == 1000000) |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
130 { |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
131 time_t t1 = tv_delay.tv_sec + 1; |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
132 if (t1 < tv_delay.tv_sec) |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
133 tv_delay.tv_usec = 1000000 - 1; /* close enough */ |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
134 else |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
135 { |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
136 tv_delay.tv_sec = t1; |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
137 tv_delay.tv_usec = 0; |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
138 } |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
139 } |
5813 | 140 select (0, NULL, NULL, NULL, &tv_delay); |
2052 | 141 } |
142 | |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
143 /* Suspend execution for at least *REQUESTED_DELAY seconds. The |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
144 *REMAINING_DELAY part isn't implemented yet. */ |
2058 | 145 |
2052 | 146 int |
2270 | 147 rpl_nanosleep (const struct timespec *requested_delay, |
2341 | 148 struct timespec *remaining_delay) |
2052 | 149 { |
5159 | 150 static bool initialized; |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
151 |
2058 | 152 /* set up sig handler */ |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
153 if (! initialized) |
2058 | 154 { |
7237
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
155 # ifdef SA_NOCLDSTOP |
5813 | 156 struct sigaction oldact, newact; |
2058 | 157 newact.sa_handler = sighandler; |
158 sigemptyset (&newact.sa_mask); | |
159 newact.sa_flags = 0; | |
2053 | 160 |
2058 | 161 sigaction (SIGCONT, NULL, &oldact); |
162 if (oldact.sa_handler != SIG_IGN) | |
163 sigaction (SIGCONT, &newact, NULL); | |
7237
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
164 # else |
2058 | 165 if (signal (SIGCONT, SIG_IGN) != SIG_IGN) |
5813 | 166 { |
167 signal (SIGCONT, sighandler); | |
168 siginterrupt (SIGCONT, 1); | |
169 } | |
7237
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
170 # endif |
5159 | 171 initialized = true; |
2058 | 172 } |
2052 | 173 |
5813 | 174 suspended = 0; |
175 | |
2056 | 176 my_usleep (requested_delay); |
2052 | 177 |
2056 | 178 if (suspended) |
2052 | 179 { |
180 /* Calculate time remaining. */ | |
181 /* FIXME: the code in sleep doesn't use this, so there's no | |
182 rush to implement it. */ | |
2058 | 183 |
184 errno = EINTR; | |
2052 | 185 } |
186 | |
187 /* FIXME: Restore sig handler? */ | |
188 | |
2056 | 189 return suspended; |
2052 | 190 } |
7237
119870bc83d7
Work around a bug in both the Linux and SunOS 64-bit kernels:
Paul Eggert <eggert@cs.ucla.edu>
parents:
6795
diff
changeset
|
191 #endif |