aboutsummaryrefslogtreecommitdiff
path: root/src/rc
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-01-12 23:53:13 +0000
committerRoy Marples <roy@marples.name>2009-01-12 23:53:13 +0000
commit3d37005a3d0c9a90578fcb249b823f08a6c58f49 (patch)
tree005e0d07af432e9fa6723bfbcc315654929e6758 /src/rc
parent2243c013900f1d3d850acf066dde2e83f41b3ed9 (diff)
We now warn about clock skews
rc-update -u will force a regen of the dep tree rc_newer_than and rc_olderthan now take another two parameters for newest/oldest file and mtime
Diffstat (limited to 'src/rc')
-rw-r--r--src/rc/builtins.h4
-rw-r--r--src/rc/rc-applets.c6
-rw-r--r--src/rc/rc-depend.c63
-rw-r--r--src/rc/rc-status.c6
-rw-r--r--src/rc/rc-update.c11
-rw-r--r--src/rc/rc.c6
-rw-r--r--src/rc/runscript.c8
7 files changed, 67 insertions, 37 deletions
diff --git a/src/rc/builtins.h b/src/rc/builtins.h
index 0cd03d3c..d7fab143 100644
--- a/src/rc/builtins.h
+++ b/src/rc/builtins.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2008 Roy Marples <roy@marples.name>
+ * Copyright 2007-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,7 @@ int start_stop_daemon(int, char **);
void run_applets(int, char **);
/* Handy function so we can wrap einfo around our deptree */
-RC_DEPTREE *_rc_deptree_load (int *);
+RC_DEPTREE *_rc_deptree_load (int, int *);
/* Test to see if we can see pid 1 or not */
bool _rc_can_find_pids(void);
diff --git a/src/rc/rc-applets.c b/src/rc/rc-applets.c
index 57d03446..3d6ce90c 100644
--- a/src/rc/rc-applets.c
+++ b/src/rc/rc-applets.c
@@ -7,7 +7,7 @@
*/
/*
- * Copyright 2007-2008 Roy Marples <roy@marples.name>
+ * Copyright 2007-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -451,7 +451,7 @@ void run_applets(int argc, char **argv)
if (argc < 3)
exit (EXIT_FAILURE);
while (i < argc) {
- if (!rc_newer_than(argv[1], argv[i++]))
+ if (!rc_newer_than(argv[1], argv[i++], NULL, NULL))
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
@@ -461,7 +461,7 @@ void run_applets(int argc, char **argv)
if (argc < 3)
exit (EXIT_FAILURE);
while (i < argc) {
- if (!rc_newer_than(argv[1], argv[i++]))
+ if (!rc_newer_than(argv[1], argv[i++], NULL, NULL))
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
diff --git a/src/rc/rc-depend.c b/src/rc/rc-depend.c
index 1cd32ffd..5d10da10 100644
--- a/src/rc/rc-depend.c
+++ b/src/rc/rc-depend.c
@@ -4,7 +4,7 @@
*/
/*
- * Copyright 2007-2008 Roy Marples <roy@marples.name>
+ * Copyright 2007-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -29,17 +29,21 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
-#include <getopt.h>
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
+#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
+#include <utime.h>
#include "builtins.h"
#include "einfo.h"
@@ -49,13 +53,19 @@
extern const char *applet;
RC_DEPTREE *
-_rc_deptree_load(int *regen) {
+_rc_deptree_load(int force, int *regen) {
int fd;
int retval;
int serrno = errno;
int merrno;
-
- if (rc_deptree_update_needed()) {
+ time_t t;
+ char file[PATH_MAX];
+ struct stat st;
+ struct utimbuf ut;
+ FILE *fp;
+
+ t = 0;
+ if (rc_deptree_update_needed(file, &t) || force != 0) {
/* Test if we have permission to update the deptree */
fd = open(RC_DEPTREE_CACHE, O_WRONLY);
merrno = errno;
@@ -67,8 +77,30 @@ _rc_deptree_load(int *regen) {
if (regen)
*regen = 1;
ebegin("Caching service dependencies");
- retval = rc_deptree_update();
- eend (retval ? 0 : -1, "Failed to update the dependency tree");
+ retval = rc_deptree_update() ? 0 : -1;
+ eend (retval, "Failed to update the dependency tree");
+
+ if (retval == 0) {
+ stat(RC_DEPTREE_CACHE, &st);
+ if (st.st_mtime < t) {
+ eerror("Clock skew detected with `%s'", file);
+ eerrorn("Adjusting mtime of `" RC_DEPTREE_CACHE
+ "' to %s", ctime(&t));
+ fp = fopen(RC_DEPTREE_SKEWED, "w");
+ if (fp != NULL) {
+ fprintf(fp, RC_DEPTREE_SKEWED "\n");
+ fclose(fp);
+ }
+ ut.actime = t;
+ ut.modtime = t;
+ utime(RC_DEPTREE_CACHE, &ut);
+ } else {
+ if (exists(RC_DEPTREE_SKEWED))
+ unlink(RC_DEPTREE_SKEWED);
+ }
+ }
+ if (force == -1 && regen != NULL)
+ *regen = retval;
}
return rc_deptree_load();
}
@@ -104,9 +136,8 @@ rc_depend(int argc, char **argv)
RC_STRINGLIST *depends;
RC_STRING *s;
RC_DEPTREE *deptree = NULL;
- int options = RC_DEP_TRACE;
+ int options = RC_DEP_TRACE, update = 0;
bool first = true;
- bool update = false;
char *runlevel = xstrdup(getenv("RC_RUNLEVEL"));
int opt;
char *token;
@@ -130,7 +161,7 @@ rc_depend(int argc, char **argv)
rc_stringlist_add(types, token);
break;
case 'u':
- update = true;
+ update = 1;
break;
case 'T':
options &= RC_DEP_TRACE;
@@ -140,15 +171,7 @@ rc_depend(int argc, char **argv)
}
}
- if (update) {
- ebegin("Caching service dependencies");
- update = rc_deptree_update();
- eend(update ? 0 : -1, "%s: %s", applet, strerror(errno));
- if (!update)
- eerrorx("Failed to update the dependency tree");
- }
-
- if (!(deptree = _rc_deptree_load(NULL)))
+ if (!(deptree = _rc_deptree_load(update, NULL)))
eerrorx("failed to load deptree");
if (!runlevel)
diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index 619b68c3..88018262 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -4,7 +4,7 @@
*/
/*
- * Copyright 2007-2008 Roy Marples <roy@marples.name>
+ * Copyright 2007-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -140,7 +140,7 @@ print_services(const char *runlevel, RC_STRINGLIST *svcs)
if (!svcs)
return;
if (!deptree)
- deptree = _rc_deptree_load(NULL);
+ deptree = _rc_deptree_load(0, NULL);
if (!deptree) {
TAILQ_FOREACH(s, svcs, entries)
if (!runlevel ||
@@ -260,7 +260,7 @@ rc_status(int argc, char **argv)
}
/* Output the services in the order in which they would start */
- deptree = _rc_deptree_load(NULL);
+ deptree = _rc_deptree_load(0, NULL);
TAILQ_FOREACH(l, levels, entries) {
print_level(l->value);
diff --git a/src/rc/rc-update.c b/src/rc/rc-update.c
index 64e24000..5a0264cd 100644
--- a/src/rc/rc-update.c
+++ b/src/rc/rc-update.c
@@ -4,7 +4,7 @@
*/
/*
- * Copyright 2007-2008 Roy Marples <roy@marples.name>
+ * Copyright 2007-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -138,11 +138,13 @@ show(RC_STRINGLIST *runlevels, bool verbose)
"Usage: rc-update [options] add service <runlevel>\n" \
" rc-update [options] del service <runlevel>\n" \
" rc-update [options] show"
-#define getoptstring getoptstring_COMMON
+#define getoptstring "u" getoptstring_COMMON
static const struct option longopts[] = {
+ { "update", 0, NULL, 'u' },
longopts_COMMON
};
static const char * const longopts_help[] = {
+ "Force an update of the dependency tree",
longopts_help_COMMON
};
#include "_usage.c"
@@ -167,8 +169,11 @@ rc_update(int argc, char **argv)
int ret;
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *) 0)) != -1)
+ longopts, (int *)0)) != -1)
switch (opt) {
+ case 'u':
+ _rc_deptree_load(-1, &ret);
+ return ret;
case_RC_COMMON_GETOPT
}
diff --git a/src/rc/rc.c b/src/rc/rc.c
index d0748a99..b5459601 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -9,7 +9,7 @@
*/
/*
- * Copyright 2007-2008 Roy Marples <roy@marples.name>
+ * Copyright 2007-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -944,8 +944,10 @@ main(int argc, char **argv)
}
/* Load our deptree */
- if ((deptree = _rc_deptree_load(&regen)) == NULL)
+ if ((deptree = _rc_deptree_load(0, &regen)) == NULL)
eerrorx("failed to load deptree");
+ if (exists(RC_DEPTREE_SKEWED))
+ ewarn("WARNING: clock skew detected!");
/* Clean the failed services state dir */
clean_failed();
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index e5077d8d..b7e9f352 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -4,7 +4,7 @@
*/
/*
- * Copyright 2007-2008 Roy Marples <roy@marples.name>
+ * Copyright 2007-2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
@@ -748,7 +748,7 @@ svc_start(bool deps)
depoptions |= RC_DEP_STRICT;
if (deps) {
- if (!deptree && ((deptree = _rc_deptree_load(NULL)) == NULL))
+ if (!deptree && ((deptree = _rc_deptree_load(0, NULL)) == NULL))
eerrorx("failed to load deptree");
if (!types_b)
setup_types();
@@ -977,7 +977,7 @@ svc_stop(bool deps)
if (rc_conf_yesno("rc_depend_strict") || errno == ENOENT)
depoptions |= RC_DEP_STRICT;
- if (!deptree && ((deptree = _rc_deptree_load(NULL)) == NULL))
+ if (!deptree && ((deptree = _rc_deptree_load(0, NULL)) == NULL))
eerrorx("failed to load deptree");
if (!types_m)
@@ -1368,7 +1368,7 @@ runscript(int argc, char **argv)
depoptions |= RC_DEP_STRICT;
if (!deptree &&
- ((deptree = _rc_deptree_load(NULL)) == NULL))
+ ((deptree = _rc_deptree_load(0, NULL)) == NULL))
eerrorx("failed to load deptree");
tmplist = rc_stringlist_new();