- case 'f':
- ForegroundOpt = 1;
- break;
- case 'b':
- ForegroundOpt = 0;
- break;
- case 'S': /* select logging to syslog */
- LoggerOpt = 0;
- break;
- case 'L': /* select internal file logger */
- LoggerOpt = 1;
- if (*optarg != 0) LogFile = optarg;
- break;
- case 'c':
- if (*optarg != 0) CDir = optarg;
- break;
- default: /* parse error */
- bb_show_usage();
- }
- }
-
- /*
- * change directory
- */
-
- if (chdir(CDir) != 0)
- bb_perror_msg_and_die("chdir");
-
- /*
- * close stdin and stdout, stderr.
- * close unused descriptors - don't need.
- * optional detach from controlling terminal
- */
-
- if (ForegroundOpt == 0) {
- if(daemon(1, 0) < 0)
- bb_perror_msg_and_die("daemon");
- }
-
- (void)startlogger(); /* need if syslog mode selected */
- signal(SIGHUP,SIG_IGN); /* hmm.. but, if kill -HUP original
- * version - his died. ;(
- */
-
- /*
- * main loop - synchronize to 1 second after the minute, minimum sleep
- * of 1 second.
- */
-
- log(9,"%s " VERSION " dillon, started, log level %d\n", av[0], LogLevel);
-
- SynchronizeDir();
-
- {
- time_t t1 = time(NULL);
- time_t t2;
- long dt;
- short rescan = 60;
- short sleep_time = 60;
-
- for (;;) {
- sleep((sleep_time + 1) - (short)(time(NULL) % sleep_time));
-
- t2 = time(NULL);
- dt = t2 - t1;
-
- /*
- * The file 'cron.update' is checked to determine new cron
- * jobs. The directory is rescanned once an hour to deal
- * with any screwups.
- *
- * check for disparity. Disparities over an hour either way
- * result in resynchronization. A reverse-indexed disparity
- * less then an hour causes us to effectively sleep until we
- * match the original time (i.e. no re-execution of jobs that
- * have just been run). A forward-indexed disparity less then
- * an hour causes intermediate jobs to be run, but only once
- * in the worst case.
- *
- * when running jobs, the inequality used is greater but not
- * equal to t1, and less then or equal to t2.
- */
-
- if (--rescan == 0) {
- rescan = 60;
- SynchronizeDir();
- }
- CheckUpdates();
+ if (LogFile == 0) {
+ vsyslog(type, fmt, va);
+ } else {
+ int logfd = open(LogFile, O_WRONLY | O_CREAT | O_APPEND, 0600);
+ if (logfd >= 0) {
+ vdprintf(logfd, fmt, va);
+ close(logfd);