Stop using getimeofday for timeouts incase the clock changes.
This commit is contained in:
parent
66d7150750
commit
1ac8d86ebe
@ -65,6 +65,7 @@ endif
|
|||||||
ifeq ($(OS),Linux)
|
ifeq ($(OS),Linux)
|
||||||
LDLIBS_RC = -ldl
|
LDLIBS_RC = -ldl
|
||||||
LDLIBS_RS = -ldl
|
LDLIBS_RS = -ldl
|
||||||
|
LDLIBS_SSD = -lrt
|
||||||
# Shouldn't need this, but it's the easiest workaround for silly
|
# Shouldn't need this, but it's the easiest workaround for silly
|
||||||
# Linux headers that don't work with -std=c99
|
# Linux headers that don't work with -std=c99
|
||||||
override CPPFLAGS += -D_GNU_SOURCE
|
override CPPFLAGS += -D_GNU_SOURCE
|
||||||
@ -76,7 +77,7 @@ endif
|
|||||||
HAVE_PAM =
|
HAVE_PAM =
|
||||||
ifdef HAVE_PAM
|
ifdef HAVE_PAM
|
||||||
CPPFLAGS_SSD = -DHAVE_PAM
|
CPPFLAGS_SSD = -DHAVE_PAM
|
||||||
LDLIBS_SSD = -lpam
|
LDLIBS_SSD += -lpam
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# We also define _BSD_SOURCE so both Linux and the BSDs get a few
|
# We also define _BSD_SOURCE so both Linux and the BSDs get a few
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef HAVE_PAM
|
#ifdef HAVE_PAM
|
||||||
@ -90,6 +91,20 @@ static void cleanup (void)
|
|||||||
rc_strlist_free (newenv);
|
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)
|
static int parse_signal (const char *sig)
|
||||||
{
|
{
|
||||||
typedef struct signalpair
|
typedef struct signalpair
|
||||||
@ -374,10 +389,8 @@ static int run_stop_schedule (const char *exec, const char *cmd,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gettimeofday (&stopat, NULL) != 0) {
|
if (get_time (&stopat) != 0)
|
||||||
eerror ("%s: gettimeofday: %s", progname, strerror (errno));
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
|
||||||
|
|
||||||
stopat.tv_sec += item->value;
|
stopat.tv_sec += item->value;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -396,10 +409,8 @@ static int run_stop_schedule (const char *exec, const char *cmd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gettimeofday (&now, NULL) != 0) {
|
if (get_time (&now) != 0)
|
||||||
eerror ("%s: gettimeofday: %s", progname, strerror (errno));
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
|
||||||
if (timercmp (&now, &stopat, >))
|
if (timercmp (&now, &stopat, >))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -966,8 +977,8 @@ int main (int argc, char **argv)
|
|||||||
struct timeval now;
|
struct timeval now;
|
||||||
bool retestpid = false;
|
bool retestpid = false;
|
||||||
|
|
||||||
if (gettimeofday (&stopat, NULL) != 0)
|
if (get_time (&stopat) != 0)
|
||||||
eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
|
exit (EXIT_FAILURE);
|
||||||
|
|
||||||
stopat.tv_usec += START_WAIT;
|
stopat.tv_usec += START_WAIT;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -981,9 +992,6 @@ int main (int argc, char **argv)
|
|||||||
eerrorx ("%s: select: %s", progname, strerror (errno));
|
eerrorx ("%s: select: %s", progname, strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gettimeofday (&now, NULL) != 0)
|
|
||||||
eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
|
|
||||||
|
|
||||||
/* This is knarly.
|
/* This is knarly.
|
||||||
If we backgrounded then we know the exact pid.
|
If we backgrounded then we know the exact pid.
|
||||||
Otherwise if we have a pidfile then it *may* 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;
|
alive = true;
|
||||||
retestpid = true;
|
retestpid = true;
|
||||||
} else {
|
} else {
|
||||||
|
printf ("%d\n", get_pid (pidfile, true));
|
||||||
retestpid = false;
|
retestpid = false;
|
||||||
if (do_stop (NULL, NULL, pidfile, uid, 0,
|
if (do_stop (NULL, NULL, pidfile, uid, 0,
|
||||||
true, false, true) > 0)
|
true, false, true) > 0)
|
||||||
@ -1015,6 +1024,8 @@ int main (int argc, char **argv)
|
|||||||
if (! alive)
|
if (! alive)
|
||||||
eerrorx ("%s: %s died", progname, exec);
|
eerrorx ("%s: %s died", progname, exec);
|
||||||
|
|
||||||
|
if (get_time (&now) != 0)
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
if (timercmp (&now, &stopat, >))
|
if (timercmp (&now, &stopat, >))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user