Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/nanosleep.c @ 8146:b31580167c2b
New module 'time', so that apps can include <time.h> as per
POSIX and GNU instead of separate include files like time_r.h
and timegm.h. This implementation tries out a simpler approach
for replacing decls in standard include files (as compared to
the string module), somewhat as an experiment.
* config/srclist.txt: Comment out mktime.c for now.
* doc/gnulib-tool.texi (Initial import): Don't use time_r as an example
since it doesn't apply any more. Use generic wording instead.
* MODULES.html.sh (Support for systems lacking POSIX:2001): New module
'time'.
* lib/time_.h, m4/time_h.m4, modules/time: New files.
* lib/strptime.h, lib/time_r.h, lib/timegm.h: Remove.
* lib/mktime.c: Include config.h depending on _LIBC, not HAVE_CONFIG_H.
Don't include <sys/types.h>; no longer needed since we assume C89.
* lib/mktime.c: Don't include "time_r.h"; no longer needed.
* lib/strftime.c: Likewise.
* lib/time_r.c: Likewise.
* lib/nanosleep.c (nanosleep): #undef after include files, not before.
* lib/nanosleep.c: Include <time.h> first, to check interface.
* lib/strptime.c: Likewise.
* lib/time_r.c: Likewise.
* lib/timegm.c: Likewise.
* lib/strptime.c: Don't include strptime.h or time_r.h; no longer
needed.
* lib/timegm.c: Don't include timegm.h; no longer needed.
* lib/timespec.h: Don't include <sys/time.h> before <time.h>;
time.h now handles any problems in that area.
(struct timespec, nanosleep): Remove; time.h now arranges for these.
* lib/xnanosleep.c: Don't include timespec.h; no longer needed now
that time.h defines struct timespec.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Check that nanosleep is declared.
Set REPLACE_NANOSLEEP. Don't AC_DEFINE nanosleep; the time module now
handles that.
* m4/strptime.m4 (gl_FUNC_STPRTIME): Set REPLACE_STRPTIME.
* m4/time_r.m4 (gl_TIME_R): Don't define HAVE_TIME_R_POSIX; no longer
needed. Set REPLACE_LOCALTIME.
* m4/timegm.m4 (gl_FUNC_TIMEGM): Set REPLACE_TIMEGM.
* m4/timespec.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Move to time_h.m4.
(gl_TIMESPEC): Don't check for sys/time.h or struct timespec or
nanosleep; time_h.m4 now does that. Don't require
gl_USE_SYSTEM_EXTENSIONS; no longer needed directly, and the time
module handles this now.
* modules/getdate (Depends-on): Remove timespec. Add time.
* modules/nanosleep (Depends-on): Likewise.
* modules/stat-time (Depends-on): Likewise.
* modules/nanosleep (Include): Include time.h, not timespec.h.
* modules/strptime (Files): Remove lib/strptime.h.
(Depends-on): Add extensions, time.
(Include): Include time.h, not strptime.h.
* modules/time_r (Files): Remove lib/time_r.h.
(Depends-on): Add time.
(Include): Include time.h, not time_r.h.
* modules/timegm: Likewise.
* modules/timespec (Description): Now does timespec-related decls
of our own, instead of struct timespec itself.
(Depends-on): Add time; remove extensions.
(Maintainer): Add self.
* modules/utimecmp (Depends-on): Add time; remove timespec.
* modules/utimens (Depends-on): Likewise.
* modules/xnanosleep (Depends-on): Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 12 Feb 2007 18:49:19 +0000 |
parents | b7a83a69ac23 |
children | bbbbbf4cd1c5 |
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 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
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 | |
17 along with this program; if not, write to the Free Software Foundation, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5813
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
2052 | 19 |
20 /* written by Jim Meyering */ | |
21 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
7298
diff
changeset
|
22 #include <config.h> |
2270 | 23 |
8146
b31580167c2b
New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
7897
diff
changeset
|
24 #include <time.h> |
2270 | 25 |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
26 #include "timespec.h" |
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
27 |
5159 | 28 #include <stdbool.h> |
2053 | 29 #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
|
30 #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
|
31 #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
|
32 # 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
|
33 #endif |
2053 | 34 #include <signal.h> |
2052 | 35 |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
36 #include <sys/time.h> |
2057 | 37 #include <errno.h> |
38 | |
6275 | 39 #include <unistd.h> |
2056 | 40 |
8146
b31580167c2b
New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
7897
diff
changeset
|
41 #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
|
42 |
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
|
43 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
|
44 |
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 #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
|
46 |
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 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
|
48 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
|
49 { |
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 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
|
51 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
|
52 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
|
53 # 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
|
54 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
|
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 |
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 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
|
58 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
|
59 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
|
60 { |
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 /* 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
|
62 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
|
63 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
|
64 |
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 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
|
66 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
|
67 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
|
68 |
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 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
|
70 { |
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 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
|
72 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
|
73 { |
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 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
|
75 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
|
76 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
|
77 |
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 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 { |
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 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
|
86 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
|
87 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
|
88 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
|
89 } |
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 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
|
91 { |
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_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
|
93 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
|
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 |
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 #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
|
100 |
2687
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
101 /* Some systems (MSDOS) don't have SIGCONT. |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
102 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
|
103 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
|
104 # 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
|
105 # 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
|
106 # endif |
2687
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
107 |
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
|
108 # 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
|
109 # 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
|
110 # endif |
2052 | 111 |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
112 static sig_atomic_t volatile suspended; |
2052 | 113 |
2053 | 114 /* Handle SIGCONT. */ |
115 | |
116 static void | |
117 sighandler (int sig) | |
118 { | |
119 suspended = 1; | |
120 } | |
121 | |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
122 /* Suspend execution for at least *TS_DELAY seconds. */ |
2052 | 123 |
124 static void | |
2056 | 125 my_usleep (const struct timespec *ts_delay) |
2052 | 126 { |
127 struct timeval tv_delay; | |
128 tv_delay.tv_sec = ts_delay->tv_sec; | |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
129 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
|
130 if (tv_delay.tv_usec == 1000000) |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
131 { |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 else |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
136 { |
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_sec = t1; |
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
138 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
|
139 } |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
140 } |
5813 | 141 select (0, NULL, NULL, NULL, &tv_delay); |
2052 | 142 } |
143 | |
6795
9dc5bb3f3359
* lib/nanosleep.c [HAVE_SYS_SELECT_H]: Include <sys/select.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
144 /* 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
|
145 *REMAINING_DELAY part isn't implemented yet. */ |
2058 | 146 |
2052 | 147 int |
2270 | 148 rpl_nanosleep (const struct timespec *requested_delay, |
2341 | 149 struct timespec *remaining_delay) |
2052 | 150 { |
5159 | 151 static bool initialized; |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
152 |
2058 | 153 /* set up sig handler */ |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
154 if (! initialized) |
2058 | 155 { |
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
|
156 # ifdef SA_NOCLDSTOP |
5813 | 157 struct sigaction oldact, newact; |
2058 | 158 newact.sa_handler = sighandler; |
159 sigemptyset (&newact.sa_mask); | |
160 newact.sa_flags = 0; | |
2053 | 161 |
2058 | 162 sigaction (SIGCONT, NULL, &oldact); |
163 if (oldact.sa_handler != SIG_IGN) | |
164 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
|
165 # else |
2058 | 166 if (signal (SIGCONT, SIG_IGN) != SIG_IGN) |
5813 | 167 { |
168 signal (SIGCONT, sighandler); | |
169 siginterrupt (SIGCONT, 1); | |
170 } | |
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
|
171 # endif |
5159 | 172 initialized = true; |
2058 | 173 } |
2052 | 174 |
5813 | 175 suspended = 0; |
176 | |
2056 | 177 my_usleep (requested_delay); |
2052 | 178 |
2056 | 179 if (suspended) |
2052 | 180 { |
181 /* Calculate time remaining. */ | |
182 /* FIXME: the code in sleep doesn't use this, so there's no | |
183 rush to implement it. */ | |
2058 | 184 |
185 errno = EINTR; | |
2052 | 186 } |
187 | |
188 /* FIXME: Restore sig handler? */ | |
189 | |
2056 | 190 return suspended; |
2052 | 191 } |
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
|
192 #endif |