commit c63bcfc81973ad3b39562cb3d6947097cc40202d
parent db6ec83bdf9dbb6730b756af71c82805b2312009
Author: Ari Malinen <ari.malinen@gmail.com>
Date: Thu, 12 Jun 2014 02:21:08 +0300
fixed bug, cleaned code
Diffstat:
3 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/Makefile b/Makefile
@@ -3,14 +3,14 @@ CFLAGS=-std=c99 -Wall -Wpedantic -Wextra
all: dcron
install: dcron
- mkdir -p ${DESTDIR}/bin
+ mkdir -p ${DESTDIR}/sbin
mkdir -p ${DESTDIR}/etc/init.d
- install -m 755 dcron ${DESTDIR}/bin/
+ install -m 755 dcron ${DESTDIR}/sbin/
install -m 755 init.d/dcron ${DESTDIR}/etc/init.d/
install -m 644 dcron.conf ${DESTDIR}/etc/
uninstall:
- rm -f ${DESTDIR}/bin/dcron
+ rm -f ${DESTDIR}/sbin/dcron
rm ${DESTDIR}/etc/init.d/dcron
rm ${DESTDIR}/etc/dcron.conf
diff --git a/README b/README
@@ -1,11 +1,11 @@
dcron - simple cron daemon
-info:
+features:
Single daemon, config and initscript.
Logs to stdout and syslog.
usage:
-usage: ./dcron [options]
+usage: dcron [options]
-h help
-d daemon
-f <file> config file
diff --git a/dcron.c b/dcron.c
@@ -2,8 +2,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <ctype.h>
+#include <time.h>
#include <unistd.h>
#include <syslog.h>
@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
char config[MAXLEN+1] = "/etc/dcron.conf";
char line[MAXLEN+1];
char cmd[MAXLEN+1];
- char *argv0, *col;
+ char *col;
int i, l, date[5];
time_t t;
struct tm *tm;
@@ -21,35 +21,31 @@ int main(int argc, char *argv[]) {
openlog(argv[0], LOG_CONS | LOG_PID, LOG_LOCAL1);
- for (argv0 = argv[0]; argc > 0; argc--, argv++) {
- if (!strcmp("-h", argv[0])) {
- fprintf(stderr, "usage: %s [options]\n", argv0);
+ for (i = 0; i < argc; i++) {
+ if (!strcmp("-h", argv[i])) {
+ fprintf(stderr, "usage: %s [options]\n", argv[0]);
fprintf(stderr, "-h help\n");
fprintf(stderr, "-d daemon\n");
fprintf(stderr, "-f <file> config file\n");
return 1;
- } else if (!strcmp("-d", argv[0])) {
+ } else if (!strcmp("-d", argv[i])) {
if (daemon(1, 0) != 0) {
fprintf(stderr, "error: failed to daemonize\n");
syslog(LOG_NOTICE, "error: failed to daemonize");
return 1;
}
- } else if (!strcmp("-f", argv[0])) {
- if (argc < 2 || argv[1][0] == '-') {
+ } else if (!strcmp("-f", argv[i])) {
+ if (argv[i+1] == NULL || argv[i+1][0] == '-') {
fprintf(stderr, "error: -f needs parameter\n");
syslog(LOG_NOTICE, "error: -f needs parameter");
return 1;
}
- strncpy(config, argv[1], MAXLEN);
+ strncpy(config, argv[++i], MAXLEN);
printf("config: %s\n", config);
syslog(LOG_NOTICE, "config: %s", config);
- argc--, argv++;
}
}
- printf("start uid:%d\n", getuid());
- syslog(LOG_NOTICE, "start uid:%d", getuid());
-
while (1) {
t = time(NULL);
tm = localtime(&t);
@@ -72,7 +68,7 @@ int main(int argc, char *argv[]) {
else if (ispunct(col[0]))
date[i] = -1;
else {
- date[i] = 0;
+ date[i] = -2;
fprintf(stderr, "error: %s line %d column %d\n", config, l+1, i+1);
syslog(LOG_NOTICE, "error: %s line %d column %d", config, l+1, i+1);
}