commit 53dae3860e54979e5b5aa1c13b7d1aee3a2b4fc8
parent 2d7328ec86dfc0ac30f87565ebde219966fe2616
Author: Ari Malinen <ari.malinen@gmail.com>
Date: Tue, 10 Jun 2014 22:36:31 +0300
fixed few issues
Diffstat:
M | dcron.c | | | 25 | ++++++------------------- |
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/dcron.c b/dcron.c
@@ -3,7 +3,6 @@
#include <string.h>
#include <time.h>
#include <ctype.h>
-#include <signal.h>
#include <unistd.h>
#include <syslog.h>
@@ -12,17 +11,8 @@
static const char config[] = "/etc/dcron.conf";
-FILE *fp;
-
-void inthandler(int sig) {
- puts("quit");
- syslog(LOG_NOTICE, "quit");
- closelog();
- fclose(fp);
- exit(0);
-}
-
int main(int argc, char *argv[]) {
+ FILE *fp;
char line[MAXLEN+1];
char *col;
int min, hour, mday, mon, wday;
@@ -35,11 +25,9 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "usage: %s [-h = help] [-d = daemon]\n", argv[0]);
return 1;
} else if (argc > 1 && !strcmp("-d", argv[1])) {
- if (!daemon(1, 0))
- return 1;
+ daemon(1, 0);
}
- signal(SIGINT, inthandler);
openlog(argv[0], LOG_CONS | LOG_PID, LOG_LOCAL1);
syslog(LOG_NOTICE, "start uid:%d", getuid());
@@ -51,6 +39,7 @@ int main(int argc, char *argv[]) {
fp = fopen(config, "r");
if (fp == NULL) {
fprintf(stderr, "error: cant read %s\n", config);
+ syslog(LOG_NOTICE, "error: cant read %s", config);
sleep(SLEEP);
continue;
}
@@ -109,10 +98,7 @@ int main(int argc, char *argv[]) {
tm->tm_mday, tm->tm_mon, tm->tm_year+1900);
printf("run: %s", cmd);
syslog(LOG_NOTICE, "run: %s", cmd);
- if (system(cmd)) {
- puts("ok");
- syslog(LOG_NOTICE, "ok");
- }
+ system(cmd);
}
}
}
@@ -123,6 +109,7 @@ int main(int argc, char *argv[]) {
fclose(fp);
sleep(SLEEP);
}
- inthandler(SIGINT);
+ syslog(LOG_NOTICE, "quit");
+ closelog();
return 0;
}