summaryrefslogtreecommitdiff
path: root/utils/start-stop-daemon.c
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2015-04-21 09:07:42 +0200
committerGuillem Jover <guillem@debian.org>2015-05-09 04:55:45 +0200
commit033b2950694fc3fa6d90dca34de1e4f8fa06c934 (patch)
tree407469532849d224241988945975ea10d2675638 /utils/start-stop-daemon.c
parent7131cdd1dacf12ba9735cc62f0d1691d60e8cc72 (diff)
downloaddpkg-033b2950694fc3fa6d90dca34de1e4f8fa06c934.tar.gz
s-s-d: Switch to use a monotonic clock if available
Use clock_gettime(CLOCK_MONOTONIC) if available instead of gettimeofday() which gets affected by abrupt system clock changes, and might mess with the timeout calculations. Closes: #783014 Suggested-by: Jose M Calhariz <jose.calhariz@hds.com>
Diffstat (limited to 'utils/start-stop-daemon.c')
-rw-r--r--utils/start-stop-daemon.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index a7e96c970..ce95fd1d1 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -73,6 +73,7 @@
#include <assert.h>
#include <errno.h>
#include <limits.h>
+#include <time.h>
#include <fcntl.h>
#include <dirent.h>
#include <ctype.h>
@@ -309,6 +310,11 @@ xstrdup(const char *str)
static void
timespec_gettime(struct timespec *ts)
{
+#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && \
+ defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0
+ if (clock_gettime(CLOCK_MONOTONIC, ts) < 0)
+ fatal("clock_gettime failed");
+#else
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
@@ -316,6 +322,7 @@ timespec_gettime(struct timespec *ts)
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * NANOSEC_IN_MICROSEC;
+#endif
}
#define timespec_cmp(a, b, OP) \