aboutsummaryrefslogtreecommitdiff
path: root/src/librc.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-05-11 08:58:19 +0000
committerRoy Marples <roy@marples.name>2007-05-11 08:58:19 +0000
commit46cd245ee3b6bfc7e6a34de6d43e5930274bd37a (patch)
treed05d21bc6faca01b3f031039771050d87032a122 /src/librc.c
parent7cdd8d4a0e2a5ef44df37e7879cb726aac45826d (diff)
Use clock MONOTONIC to timeout, not localtime, #177514
Diffstat (limited to 'src/librc.c')
-rw-r--r--src/librc.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/librc.c b/src/librc.c
index 67a4174d..cd085102 100644
--- a/src/librc.c
+++ b/src/librc.c
@@ -567,26 +567,38 @@ void rc_schedule_clear (const char *service)
}
librc_hidden_def(rc_schedule_clear)
+static time_t get_uptime(void)
+{
+#ifdef __linux__
+ struct sysinfo info;
+
+ sysinfo (&info);
+ return (time_t) info.uptime;
+#else
+ struct timespec tp;
+
+ if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) {
+ eerror ("clock_gettime: %s", strerror (errno));
+ return -1;
+ }
+
+ return tp.tv_sec;
+#endif
+}
+
bool rc_wait_service (const char *service)
{
char *svc;
char *base;
char *fifo;
struct timeval tv;
- struct timeval stopat;
- struct timeval now;
+ time_t start = get_uptime ();
bool retval = false;
bool forever = false;
if (! service)
return (false);
- if (gettimeofday (&stopat, NULL) != 0) {
- eerror ("gettimeofday: %s", strerror (errno));
- return (false);
- }
- stopat.tv_sec += WAIT_MAX;
-
svc = rc_xstrdup (service);
base = basename (svc);
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
@@ -612,13 +624,8 @@ bool rc_wait_service (const char *service)
}
if (! forever) {
- /* Don't hang around forever */
- if (gettimeofday (&now, NULL) != 0) {
- eerror ("gettimeofday: %s", strerror (errno));
- break;
- }
-
- if (timercmp (&now, &stopat, >))
+ time_t now = get_uptime();
+ if (now - start > WAIT_MAX)
break;
}
}