aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile3
-rw-r--r--src/start-stop-daemon.c35
2 files changed, 25 insertions, 13 deletions
diff --git a/src/Makefile b/src/Makefile
index 14cd69f8..14a44bd3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -65,6 +65,7 @@ endif
ifeq ($(OS),Linux)
LDLIBS_RC = -ldl
LDLIBS_RS = -ldl
+LDLIBS_SSD = -lrt
# Shouldn't need this, but it's the easiest workaround for silly
# Linux headers that don't work with -std=c99
override CPPFLAGS += -D_GNU_SOURCE
@@ -76,7 +77,7 @@ endif
HAVE_PAM =
ifdef HAVE_PAM
CPPFLAGS_SSD = -DHAVE_PAM
-LDLIBS_SSD = -lpam
+LDLIBS_SSD += -lpam
endif
# We also define _BSD_SOURCE so both Linux and the BSDs get a few
diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c
index 2257b339..c0fa417b 100644
--- a/src/start-stop-daemon.c
+++ b/src/start-stop-daemon.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#ifdef HAVE_PAM
@@ -90,6 +91,20 @@ static void cleanup (void)
rc_strlist_free (newenv);
}
+static int get_time(struct timeval *tp)
+{
+ struct timespec ts;
+
+ if (clock_gettime (CLOCK_MONOTONIC, &ts) == -1) {
+ eerror ("clock_gettime: %s", strerror (errno));
+ return (-1);
+ }
+
+ tp->tv_sec = ts.tv_sec;
+ tp->tv_usec = ts.tv_nsec / 1000;
+ return (0);
+}
+
static int parse_signal (const char *sig)
{
typedef struct signalpair
@@ -374,10 +389,8 @@ static int run_stop_schedule (const char *exec, const char *cmd,
break;
}
- if (gettimeofday (&stopat, NULL) != 0) {
- eerror ("%s: gettimeofday: %s", progname, strerror (errno));
+ if (get_time (&stopat) != 0)
return (0);
- }
stopat.tv_sec += item->value;
while (1) {
@@ -396,10 +409,8 @@ static int run_stop_schedule (const char *exec, const char *cmd,
}
}
- if (gettimeofday (&now, NULL) != 0) {
- eerror ("%s: gettimeofday: %s", progname, strerror (errno));
+ if (get_time (&now) != 0)
return (0);
- }
if (timercmp (&now, &stopat, >))
break;
}
@@ -966,8 +977,8 @@ int main (int argc, char **argv)
struct timeval now;
bool retestpid = false;
- if (gettimeofday (&stopat, NULL) != 0)
- eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
+ if (get_time (&stopat) != 0)
+ exit (EXIT_FAILURE);
stopat.tv_usec += START_WAIT;
while (1) {
@@ -981,9 +992,6 @@ int main (int argc, char **argv)
eerrorx ("%s: select: %s", progname, strerror (errno));
}
- if (gettimeofday (&now, NULL) != 0)
- eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
-
/* This is knarly.
If we backgrounded then we know the exact pid.
Otherwise if we have a pidfile then it *may* know the exact pid.
@@ -1000,6 +1008,7 @@ int main (int argc, char **argv)
alive = true;
retestpid = true;
} else {
+ printf ("%d\n", get_pid (pidfile, true));
retestpid = false;
if (do_stop (NULL, NULL, pidfile, uid, 0,
true, false, true) > 0)
@@ -1015,7 +1024,9 @@ int main (int argc, char **argv)
if (! alive)
eerrorx ("%s: %s died", progname, exec);
- if (timercmp (&now, &stopat, >))
+ if (get_time (&now) != 0)
+ exit (EXIT_FAILURE);
+ if (timercmp (&now, &stopat, >))
break;
}