This function is marked obsolete in POSIX.1-2001 and removed in POSIX.1-2008. Replaced with nanosleep(). Signed-off-by: Daniel Mierswa <impulze@xxxxxxxxxxx> --- hwclock/kd.c | 8 ++------ include/Makefile.am | 1 + include/usleep.h | 14 ++++++++++++++ login-utils/shutdown.c | 3 ++- mount/fstab.c | 5 +++-- sys-utils/rtcwake.c | 3 ++- text-utils/tailf.c | 3 ++- 7 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 include/usleep.h
diff --git a/hwclock/kd.c b/hwclock/kd.c index 3b5708a..f98346d 100644 --- a/hwclock/kd.c +++ b/hwclock/kd.c @@ -17,6 +17,7 @@ probe_for_kd_clock() { #include <sys/ioctl.h> #include "nls.h" +#include "usleep.h" static int con_fd = -1; /* opened by probe_for_kd_clock() */ /* never closed */ @@ -66,12 +67,7 @@ synchronize_to_clock_tick_kd(void) { /* Christian T. Steigies: 1 instead of 1000000 is still sufficient to keep the machine from freezing. */ -#ifdef HAVE_NANOSLEEP - struct timespec xsleep = { 0, 1 }; - nanosleep( &xsleep, NULL ); -#else - usleep(1); -#endif + my_usleep(1); if (i++ >= 1000000) { fprintf(stderr, _("Timed out waiting for time change.\n")); diff --git a/include/Makefile.am b/include/Makefile.am index f959659..5669421 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,6 +16,7 @@ dist_noinst_HEADERS = \ pttype.h \ setproctitle.h \ swapheader.h \ + usleep.h \ wholedisk.h \ widechar.h \ xstrncpy.h diff --git a/include/usleep.h b/include/usleep.h new file mode 100644 index 0000000..7e980e7 --- /dev/null +++ b/include/usleep.h @@ -0,0 +1,14 @@ +#ifndef UTIL_LINUX_USLEEP_H +#define UTIL_LINUX_USLEEP_H + +#ifdef HAVE_NANOSLEEP +# define my_usleep(x) \ + struct timespec xsleep; \ + xsleep.tv_sec = x / 1000 / 1000; \ + xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \ + nanosleep(&xsleep, NULL); +#else +# define my_usleep usleep +#endif + +#endif /* UTIL_LINUX_USLEEP_H */ diff --git a/login-utils/shutdown.c b/login-utils/shutdown.c index 58600b9..b4f8889 100644 --- a/login-utils/shutdown.c +++ b/login-utils/shutdown.c @@ -76,6 +76,7 @@ #include "pathnames.h" #include "xstrncpy.h" #include "nls.h" +#include "usleep.h" static void usage(void), int_handler(int), write_user(struct utmp *); static void wall(void), write_wtmp(void), unmount_disks(void); @@ -391,7 +392,7 @@ main(int argc, char *argv[]) stop_finalprog (); sleep (1); /* Time for saves to start */ kill (1, SIGTERM); /* Tell init to kill spawned gettys */ - usleep (100000); /* Wait for gettys to die */ + my_usleep (100000); my_puts (""); /* Get past the login prompt */ system ("/sbin/initctl -r"); /* Roll back services */ syncwait (1); diff --git a/mount/fstab.c b/mount/fstab.c index 82e90f3..f53b60a 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -19,6 +19,7 @@ #include "fsprobe.h" #include "pathnames.h" #include "nls.h" +#include "usleep.h" #define streq(s, t) (strcmp ((s), (t)) == 0) @@ -958,7 +959,7 @@ main(int argc, char **argv) if (synctime && synctime - tv.tv_sec > 1) { usecs = ((synctime - tv.tv_sec) * 1000000UL) - (1000000UL - tv.tv_usec); - usleep(usecs); + my_usleep(usecs); } for (i = 0; i < nloops; i++) { @@ -1004,7 +1005,7 @@ main(int argc, char **argv) * simulate this via short sleep -- it's also enough to make * concurrent processes happy. */ - usleep(50000); + my_usleep(50000); } fprintf(stderr, "%05d (pid=%05d): DONE\n", id, pid); diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 4b84373..7c6b339 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -36,6 +36,7 @@ #include <linux/rtc.h> #include "nls.h" +#include "usleep.h" /* constants from legacy PC/AT hardware */ #define RTC_PF 0x40 @@ -457,7 +458,7 @@ int main(int argc, char **argv) progname, suspend, devname, ctime(&alarm)); fflush(stdout); - usleep(10 * 1000); + my_usleep(10 * 1000); if (strcmp(suspend, "no") == 0) exit(EXIT_SUCCESS); diff --git a/text-utils/tailf.c b/text-utils/tailf.c index 6a76ef4..28c4c4b 100644 --- a/text-utils/tailf.c +++ b/text-utils/tailf.c @@ -41,6 +41,7 @@ #include <sys/inotify.h> #endif #include "nls.h" +#include "usleep.h" #define DEFAULT_LINES 10 @@ -119,7 +120,7 @@ watch_file(const char *filename, off_t *size) { do { roll_file(filename, size); - usleep(250000); + my_usleep(250000); } while(1); }