Re: [PATCH] replace usleep()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 20.08.2009 16:14, Karel Zak wrote:
>  I've committed the patch below. The patch uses usleep(1) rather than
>  nanosleep() with 1 nanosecond. It would be better to remove the sleep
>  at all, but I don't have Amiga with A2000 RTCs to test that the
>  workaround is unnecessary...
Attached is a new patch that considers your recent changes.

-- 
Mierswa, Daniel

If you still don't like it, that's ok: that's why I'm boss. I simply
know better than you do.
               --- Linus Torvalds, comp.os.linux.advocacy, 1996/07/22
>From 1f50c7c9b729cbf23be2d477d449209bf3823bd2 Mon Sep 17 00:00:00 2001
From: Daniel Mierswa <impulze@xxxxxxxxxxx>
Date: Mon, 17 Aug 2009 21:22:02 +0200
Subject: [PATCH] replace usleep() for systems that don't have them

This function is marked obsolete in POSIX.1-2001 and removed in
POSIX.1-2008.

Conditionally replaced with nanosleep().

Signed-off-by: Daniel Mierswa <impulze@xxxxxxxxxxx>
---
 configure.ac           |    1 +
 hwclock/kd.c           |    1 +
 include/Makefile.am    |    1 +
 include/usleep.h       |   18 ++++++++++++++++++
 login-utils/shutdown.c |    1 +
 mount/fstab.c          |    1 +
 sys-utils/rtcwake.c    |    1 +
 text-utils/tailf.c     |    1 +
 8 files changed, 25 insertions(+), 0 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 b0e55d1..3da87ca 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 */
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..f7bc000 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);
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
 
-- 
1.6.4


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux