scron

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

commit df3011fb893a8246878294523fe1b9a94134f31d
parent f8fddb39a9c2f0df3eb6087e22af43e414f1f406
Author: sin <sin@2f30.org>
Date:   Wed,  2 Jul 2014 14:14:27 +0100

Use daemon(3)

* Ensure config is null-terminated.
* Do not log to syslog if daemonizing fails.

Diffstat:
Mcrond.c | 22+++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/crond.c b/crond.c @@ -21,26 +21,22 @@ arg(int argc, char *argv[]) pid_t pid; for (i = 1; i < argc; i++) { - if (!strcmp("-d", argv[i])) { + if (strcmp("-d", argv[i]) == 0) { pid = fork(); - if (pid < 0) { + if (pid < 0) fprintf(stderr, "error: failed to fork daemon\n"); - syslog(LOG_WARNING, "error: failed to fork daemon"); - } else if (pid == 0) { - setsid(); - fclose(stdin); - fclose(stdout); - fclose(stderr); - } else { + else if (pid == 0) + daemon(0, 0); + else exit(EXIT_SUCCESS); - } - } else if (!strcmp("-f", argv[i])) { - if (argv[i+1] == NULL || argv[i+1][0] == '-') { + } else if (strcmp("-f", argv[i]) == 0) { + if (argv[i + 1] == NULL || argv[i + 1][0] == '-') { fprintf(stderr, "error: -f needs parameter\n"); syslog(LOG_WARNING, "error: -f needs parameter"); exit(EXIT_FAILURE); } - strncpy(config, argv[++i], PATH_MAX-1); + strncpy(config, argv[++i], sizeof(config)); + config[sizeof(config) - 1] = '\0'; } else { fprintf(stderr, "usage: %s [options]\n", argv[0]); fprintf(stderr, "-h help\n");