scron

simple cron daemon
git clone git://git.2f30.org/scron
Log | Files | Refs | README | LICENSE

commit 11f86993a9e7d93e5da29d6d7562955e13d940d5
parent e3fc172d26984d7a81ae49942e35452c3ea4329a
Author: sin <sin@2f30.org>
Date:   Wed,  2 Jul 2014 15:16:46 +0100

Don't use rewind()

Open the file every time to allow editing the file without restarting
the daemon.

Ideally we'd use SIGHUP for this.

Diffstat:
Mcrond.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/crond.c b/crond.c @@ -178,11 +178,6 @@ main(int argc, char *argv[]) if (argc > 0) usage(); - if ((fp = fopen(config, "r")) == NULL) { - fprintf(stderr, "error: cant read %s\n", config); - return EXIT_FAILURE; - } - if (dflag == 1) { openlog(argv[0], LOG_CONS | LOG_PID, LOG_DAEMON); daemon(0, 0); @@ -192,6 +187,13 @@ main(int argc, char *argv[]) t = time(NULL); sleep(60 - t % 60); + if ((fp = fopen(config, "r")) == NULL) { + if (dflag == 1) + syslog(LOG_WARNING, "error: cant read %s", config); + fprintf(stderr, "error: cant read %s\n", config); + continue; + } + for (y = 0; fgets(line, sizeof(line), fp); y++) { if (line[0] == '#' || line[0] == '\n' || line[0] == '\0') continue; @@ -207,11 +209,10 @@ main(int argc, char *argv[]) } } - rewind(fp); + fclose(fp); waitjob(); } - fclose(fp); if (dflag == 1) closelog();