Hello,
I have read on the usleep man page that usleep is obsolete and should
be replaced by nanosleep. It is done with the attached patch, together
with some changes in configure.ac to find time.h. From a very quick
search on the web it seems that nanosleep is available on windows.
Some features of nanosleep aren't used by usleep (possibility to
restart the sleep on signal interruption).
I have only checked that it builds, not that it does what is intended...
There is another advantage for nanosleep over usleep, it is that
a gnulib module exists, in case we want to use gnulib for portability
at some point.
I can install that patch and do the same for kdbMonitorKeys_default
if you agree on that change. Thoughts?
note: error handling could be enhanced, but there was no error
handling, so I didn't add any ;-).
--
Pat
Index: src/libelektra/kdb.c
===================================================================
--- src/libelektra/kdb.c (révision 848)
+++ src/libelektra/kdb.c (copie de travail)
@@ -113,19 +113,26 @@
#include <errno.h>
#include <stdio.h>
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+
/* kdbbackend.h will include kdb.h and kdbprivate.h */
#include "kdbbackend.h"
#include "kdbprivate.h"
#include "kdbLibLoader.h"
-/* usleep doesn't exist on win32, so we use Sleep() */
-#ifdef WIN32
-#define usleep(x) Sleep(x)
-#endif
-
struct _KDBBackend {
/* environment for which this backend was opened */
pid_t pid;
@@ -838,11 +845,14 @@
Key *start,*current;
uint32_t diff;
int infinitum=0;
+ struct timespec sleep_time;
if (!interests || !interests->size) return 0;
/* Unacceptable 0 usecs sleep. Defaults to 1 second */
if (!sleeptime) sleeptime=1000;
+ sleep_time.tv_sec=0;
+ sleep_time.tv_nsec=sleeptime*1000;
if (!iterations) infinitum=1;
else infinitum=0;
@@ -857,7 +867,7 @@
} while (current!=start);
/* Test if some iterations left . . . */
- if (infinitum || iterations) usleep(sleeptime);
+ if (infinitum || iterations) nanosleep(&sleep_time,NULL);
}
return 0;
}
Index: configure.ac
===================================================================
--- configure.ac (révision 848)
+++ configure.ac (copie de travail)
@@ -228,7 +228,8 @@
# Checks for header files.
#
AC_HEADER_STDC
-AC_CHECK_HEADERS([langinfo.h locale.h mntent.h stdlib.h string.h strings.h
unistd.h regex.h pwd.h grp.h])
+AC_HEADER_TIME
+AC_CHECK_HEADERS([langinfo.h locale.h mntent.h stdlib.h string.h strings.h
unistd.h regex.h pwd.h grp.h sys/time.h])
#
# Checks for typedefs, structures, and compiler characteristics.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Registry-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/registry-list