commit a4cbbfd8806e093580b8fcb9105573f5adf69ee3
parent 2e5f20c86aa22b7e200c15241ce479bec9fb95b7
Author: sin <sin@2f30.org>
Date: Thu, 3 Jul 2014 14:02:44 +0100
Reload rules on SIGHUP
Diffstat:
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/TODO b/TODO
@@ -1,2 +1 @@
* Dry run to check config (low importance)
-* Preload rules and keep them in memory, reload on SIGHUP.
diff --git a/crond.c b/crond.c
@@ -5,6 +5,7 @@
#include <sys/wait.h>
#include <limits.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
@@ -37,6 +38,7 @@ struct ctabentry {
};
char *argv0;
+static sig_atomic_t reload;
static TAILQ_HEAD(ctabhead, ctabentry) ctabhead;
static char *config = "/etc/crontab";
static int dflag;
@@ -204,6 +206,7 @@ unloadentries(void)
for (cte = TAILQ_FIRST(&ctabhead); cte; cte = tmp) {
tmp = TAILQ_NEXT(cte, entry);
+ TAILQ_REMOVE(&ctabhead, cte, entry);
free(cte->cmd);
free(cte);
}
@@ -300,6 +303,20 @@ loadentries(void)
}
static void
+reloadentries(void)
+{
+ unloadentries();
+ loadentries();
+}
+
+static void
+sighup(int sig)
+{
+ (void) sig;
+ reload = 1;
+}
+
+static void
usage(void)
{
fprintf(stderr, VERSION " (c) 2014\n");
@@ -337,12 +354,20 @@ main(int argc, char *argv[])
daemon(0, 0);
}
+ signal(SIGHUP, sighup);
+
loadentries();
while (1) {
t = time(NULL);
sleep(60 - t % 60);
+ if (reload == 1) {
+ reloadentries();
+ reload = 0;
+ continue;
+ }
+
TAILQ_FOREACH(cte, &ctabhead, entry) {
t = time(NULL);
tm = localtime(&t);