From: Marcela Mašláňová Date: Mon, 28 Jul 2008 12:27:56 +0000 (+0200) Subject: @reboot jobs should be run only after reboot instead X-Git-Tag: cronie1.3~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2abb46f60f496e2725333a86ade0f3913981761d;p=cronie @reboot jobs should be run only after reboot instead of every daemon's restart. Patch inspired by debian. --- diff --git a/man/crontab.5 b/man/crontab.5 index f6b18bd..098b3b0 100644 --- a/man/crontab.5 +++ b/man/crontab.5 @@ -263,7 +263,7 @@ either). These special time specification "nicknames" are supported, which replace the 5 initial time and date fields, and are prefixed by the '@' character: .nf -@reboot : Run once, at startup. +@reboot : Run once after reboot. @yearly : Run once a year, ie. "0 0 1 1 *". @annually : Run once a year, ie. "0 0 1 1 *". @monthly : Run once a month, ie. "0 0 1 * *". diff --git a/src/cron.c b/src/cron.c index ff77bf3..0816901 100644 --- a/src/cron.c +++ b/src/cron.c @@ -380,6 +380,19 @@ static void run_reboot_jobs(cron_db *db) { user *u; entry *e; + int reboot; + pid_t pid = getpid(); + + /* lock exist - skip reboot jobs */ + if (access(REBOOT_LOCK, F_OK)) { + log_it("CRON", pid, "INFO", "@reboot jobs will be run at computer's startup.", 0); + return; + } + /* lock doesn't exist - create lock, run reboot jobs */ + if ((reboot = creat(REBOOT_LOCK, S_IRUSR&S_IWUSR)) < 0) + log_it("CRON", pid, "INFO", "Can't create lock for reboot jobs.", errno); + else + close(reboot); for (u = db->head; u != NULL; u = u->next) { for (e = u->crontab; e != NULL; e = e->next) { diff --git a/src/pathnames.h b/src/pathnames.h index 839f742..2ce322b 100644 --- a/src/pathnames.h +++ b/src/pathnames.h @@ -30,6 +30,8 @@ # include #endif /*BSD*/ +#define REBOOT_LOCK "/var/run/cron.reboot" + #ifndef CRONDIR /* CRONDIR is where cron(8) and crontab(1) both chdir * to; SPOOL_DIR, CRON_ALLOW, CRON_DENY, and LOG_FILE