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> --- configure.ac | 1 + hwclock/kd.c | 8 ++------ include/Makefile.am | 1 + include/usleep.h | 18 ++++++++++++++++++ login-utils/shutdown.c | 3 ++- mount/fstab.c | 1 + sys-utils/rtcwake.c | 1 + text-utils/tailf.c | 1 + 8 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 include/usleep.h
diff --git a/configure.ac b/configure.ac index 8999826..7e13a61 100644 --- a/configure.ac +++ b/configure.ac @@ -140,6 +140,7 @@ AC_CHECK_FUNCS( fsync \ getdomainname \ get_current_dir_name \ + usleep \ nanosleep \ personality \ updwtmp \ diff --git a/hwclock/kd.c b/hwclock/kd.c index 3b5708a..3e718e2 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 + 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..f64477c --- /dev/null +++ b/include/usleep.h @@ -0,0 +1,18 @@ +#ifndef UTIL_LINUX_USLEEP_H +#define UTIL_LINUX_USLEEP_H + +#ifndef HAVE_USLEEP +/* + * This function is marked obsolete in POSIX.1-2001 and removed in + * POSIX.1-2008. It is replaced with nanosleep(). + */ +# define usleep(x) \ + do { \ + struct timespec xsleep; \ + xsleep.tv_sec = x / 1000 / 1000; \ + xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \ + nanosleep(&xsleep, NULL); \ + } while (0) +#endif + +#endif /* UTIL_LINUX_USLEEP_H */ diff --git a/login-utils/shutdown.c b/login-utils/shutdown.c index 58600b9..ae9c35a 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 */ + 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..8cd35d6 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) diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 4b84373..d75a69f 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 diff --git a/text-utils/tailf.c b/text-utils/tailf.c index 6a76ef4..ec6e1c4 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