]> granicus.if.org Git - cronie/commitdiff
@reboot jobs should be run only after reboot instead
authorMarcela Mašláňová <mmaslano@redhat.com>
Mon, 28 Jul 2008 12:27:56 +0000 (14:27 +0200)
committerMarcela Mašláňová <mmaslano@redhat.com>
Mon, 28 Jul 2008 12:27:56 +0000 (14:27 +0200)
of every daemon's restart.
Patch inspired by debian.

man/crontab.5
src/cron.c
src/pathnames.h

index f6b18bd7d5a18b1a819d02930bfc17adfd8b20fb..098b3b0db5729c586a39114e7c044af3ac2303fc 100644 (file)
@@ -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 * *".
index ff77bf3844e27da981b1d40d6d75c337e5b9d04c..0816901cd71bad74cd574b99d19c4d068659aa99 100644 (file)
@@ -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) {
index 839f742cc9c0efce7883fb3b3a3e7eafb8cb9b87..2ce322b91da29461a6cfab5acf2c27e3464eed15 100644 (file)
@@ -30,6 +30,8 @@
 # include <paths.h>
 #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