extern int klogd_main(int argc, char **argv) { /* no options, no getopt */ int opt; int doFork = TRUE; unsigned char console_log_level = -1; /* do normal option parsing */ while ((opt = getopt(argc, argv, "c:n")) > 0) { switch (opt) { case 'c': if ((optarg == NULL) || (optarg[1] != '\0')) { bb_show_usage(); } /* Valid levels are between 1 and 8 */ console_log_level = *optarg - '1'; if (console_log_level > 7) { bb_show_usage(); } console_log_level++; break; case 'n': doFork = FALSE; break; default: bb_show_usage(); } } if (doFork) { #if defined(__uClinux__) vfork_daemon_rexec(0, 1, argc, argv, "-n"); #else /* __uClinux__ */ if (daemon(0, 1) < 0) bb_perror_msg_and_die("daemon"); #endif /* __uClinux__ */ } doKlogd(console_log_level); return EXIT_SUCCESS; }
int crond_main(int ac, char **av) { unsigned long opt; char *lopt, *Lopt, *copt; #ifdef FEATURE_DEBUG_OPT char *dopt; bb_opt_complementally = "f-b:b-f:S-L:L-S:d-l"; #else bb_opt_complementally = "f-b:b-f:S-L:L-S"; #endif opterr = 0; /* disable getopt 'errors' message. */ opt = bb_getopt_ulflags(ac, av, "l:L:fbSc:" #ifdef FEATURE_DEBUG_OPT "d:" #endif , &lopt, &Lopt, &copt #ifdef FEATURE_DEBUG_OPT , &dopt #endif ); if (opt & 1) { LogLevel = atoi(lopt); } if (opt & 2) { if (*Lopt != 0) { LogFile = Lopt; } } if (opt & 32) { if (*copt != 0) { CDir = copt; } } #ifdef FEATURE_DEBUG_OPT if (opt & 64) { DebugOpt = atoi(dopt); LogLevel = 0; } #endif /* * change directory */ if (chdir(CDir) != 0) { bb_perror_msg_and_die("%s", CDir); } signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original * version - his died. ;( */ /* * close stdin and stdout, stderr. * close unused descriptors - don't need. * optional detach from controlling terminal */ if (!(opt & 4)) { #if defined(__uClinux__) /* reexec for vfork() do continue parent */ vfork_daemon_rexec(1, 0, ac, av, "-f"); #else /* uClinux */ if (daemon(1, 0) < 0) { bb_perror_msg_and_die("daemon"); } #endif /* uClinux */ } (void) startlogger(); /* need if syslog mode selected */ /* * main loop - synchronize to 1 second after the minute, minimum sleep * of 1 second. */ crondlog("\011%s " VERSION " dillon, started, log level %d\n", bb_applet_name, 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(); #ifdef FEATURE_DEBUG_OPT if (DebugOpt) crondlog("\005Wakeup dt=%d\n", dt); #endif if (dt < -60 * 60 || dt > 60 * 60) { t1 = t2; crondlog("\111time disparity of %d minutes detected\n", dt / 60); } else if (dt > 0) { TestJobs(t1, t2); RunJobs(); sleep(5); if (CheckJobs() > 0) { sleep_time = 10; } else { sleep_time = 60; } t1 = t2; } } } /* not reached */ }
extern int syslogd_main(int argc, char **argv) { int opt; int doFork = TRUE; char *p; /* do normal option parsing */ /*BRCM begin*/ /* while ((opt = getopt(argc, argv, "m:nO:s:b:R:LC::")) > 0) { */ /* brcm, l - local log level, r - remote log level */ while ((opt = getopt(argc, argv, "m:nO:s:Sb:R:l:r:LC")) > 0) { /*BRCM end*/ switch (opt) { case 'm': MarkInterval = atoi(optarg) * 60; break; case 'n': doFork = FALSE; break; case 'O': logFilePath = optarg; break; #ifdef CONFIG_FEATURE_ROTATE_LOGFILE case 's': logFileSize = atoi(optarg) * 1024; break; case 'b': logFileRotate = atoi(optarg); if( logFileRotate > 99 ) logFileRotate = 99; break; #endif #ifdef CONFIG_FEATURE_REMOTE_LOG case 'R': RemoteHost = bb_xstrdup(optarg); if ((p = strchr(RemoteHost, ':'))) { RemotePort = atoi(p + 1); *p = '\0'; } doRemoteLog = TRUE; break; case 'L': local_logging = TRUE; break; #endif #ifdef CONFIG_FEATURE_IPC_SYSLOG case 'C': if (optarg) { int buf_size = atoi(optarg); if (buf_size >= 4) { shm_size = buf_size * 1024; } } circular_logging = TRUE; break; #endif case 'S': small = true; break; /*BRCM begin*/ case 'l': localLogLevel = atoi(optarg); break; case 'r': remoteLogLevel = atoi(optarg); break; /*BRCM end*/ default: bb_show_usage(); } } #ifdef CONFIG_FEATURE_REMOTE_LOG /* If they have not specified remote logging, then log locally */ if (doRemoteLog == FALSE) local_logging = TRUE; #endif /* Store away localhost's name before the fork */ gethostname(LocalHostName, sizeof(LocalHostName)); if ((p = strchr(LocalHostName, '.'))) { *p = '\0'; } umask(0); if (doFork == TRUE) { #if defined(__uClinux__) vfork_daemon_rexec(0, 1, argc, argv, "-n"); #else /* __uClinux__ */ if(daemon(0, 1) < 0) bb_perror_msg_and_die("daemon"); #endif /* __uClinux__ */ } doSyslogd(); return EXIT_SUCCESS; }