+/* vi: set sw=4 ts=4: */
/*
* crond -d[#] -c <crondir> -f -b
*
* run as root, but NOT setuid root
*
* Copyright 1994 Matthew Dillon (dillon@apollo.west.oic.com)
- * May be distributed under the GNU General Public License
+ * Vladimir Oleynik <dzo@simtreas.ru> (C) 2002
*
- * Vladimir Oleynik <dzo@simtreas.ru> (C) 2002 to be used in busybox
+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
#define VERSION "2.3.2"
-#undef FEATURE_DEBUG_OPT
-
-
+#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/resource.h>
-#include "busybox.h"
-
#define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
#ifndef CRONTABS
#define DaemonUid 0
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
static short DebugOpt;
#endif
static void RunJob(const char *user, CronLine * line);
-#ifdef CONFIG_FEATURE_CROND_CALL_SENDMAIL
+#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
static void EndJob(const char *user, CronLine * line);
#else
#define EndJob(user, line) line->cl_Pid = 0
fmt = ctl + 1;
if (level >= LogLevel) {
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt) {
vfprintf(stderr, fmt, va);
} else
if (LogFile == 0) {
vsyslog(type, fmt, va);
} else {
- int logfd = open(LogFile, O_WRONLY | O_CREAT | O_APPEND, 600);
+ int logfd = open(LogFile, O_WRONLY | O_CREAT | O_APPEND, 0600);
if (logfd >= 0) {
vdprintf(logfd, fmt, va);
close(logfd);
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
} else {
bb_perror_msg("Can't open log file");
#endif
unsigned long opt;
char *lopt, *Lopt, *copt;
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
char *dopt;
- bb_opt_complementaly = "f-b:b-f:S-L:L-S:d-l";
+ bb_opt_complementally = "f-b:b-f:S-L:L-S:d-l";
#else
- bb_opt_complementaly = "f-b:b-f:S-L:L-S";
+ 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
+#if ENABLE_DEBUG_CROND_OPTION
"d:"
#endif
, &lopt, &Lopt, &copt
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
, &dopt
#endif
);
CDir = copt;
}
}
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (opt & 64) {
DebugOpt = atoi(dopt);
LogLevel = 0;
* change directory
*/
- if (chdir(CDir) != 0) {
- bb_perror_msg_and_die("%s", CDir);
- }
+ bb_xchdir(CDir);
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
* version - his died. ;(
*/
*/
if (!(opt & 4)) {
-#if defined(__uClinux__)
+#ifdef BB_NOMMU
/* 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 */
+#else
+ bb_xdaemon(1, 0);
+#endif
}
(void) startlogger(); /* need if syslog mode selected */
time_t t1 = time(NULL);
time_t t2;
long dt;
- short rescan = 60;
+ int rescan = 60;
short sleep_time = 60;
for (;;) {
SynchronizeDir();
}
CheckUpdates();
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt)
crondlog("\005Wakeup dt=%d\n", dt);
#endif
}
}
}
- /* not reached */
-}
-
-#if defined(FEATURE_DEBUG_OPT) || defined(CONFIG_FEATURE_CROND_CALL_SENDMAIL)
-/*
- write to temp file..
-*/
-static void fdprintf(int fd, const char *ctl, ...)
-{
- va_list va;
-
- va_start(va, ctl);
- vdprintf(fd, ctl, va);
- va_end(va);
+ bb_fflush_stdout_and_exit(EXIT_SUCCESS); /* not reached */
}
-#endif
-
static int ChangeUser(const char *user)
{
const char *err_msg;
/*
- * Obtain password entry and change privilages
+ * Obtain password entry and change privileges
*/
pas = getpwnam(user);
if (pas == 0) {
if (LogFile == 0) {
openlog(bb_applet_name, LOG_CONS | LOG_PID, LOG_CRON);
}
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
else { /* test logfile */
int logfd;
- if ((logfd = open(LogFile, O_WRONLY | O_CREAT | O_APPEND, 600)) >= 0) {
+ if ((logfd = open(LogFile, O_WRONLY | O_CREAT | O_APPEND, 0600)) >= 0) {
close(logfd);
} else {
bb_perror_msg("Failed to open log file '%s' reason", LogFile);
while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') {
++ptr;
}
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt) {
int i;
static void FixDayDow(CronLine * line)
{
- short i;
- short weekUsed = 0;
- short daysUsed = 0;
+ int i;
+ int weekUsed = 0;
+ int daysUsed = 0;
- for (i = 0; i < arysize(line->cl_Dow); ++i) {
+ for (i = 0; i < (int)(arysize(line->cl_Dow)); ++i) {
if (line->cl_Dow[i] == 0) {
weekUsed = 1;
break;
}
}
- for (i = 0; i < arysize(line->cl_Days); ++i) {
+ for (i = 0; i < (int)(arysize(line->cl_Days)); ++i) {
if (line->cl_Days[i] == 0) {
daysUsed = 1;
break;
CronLine line;
char *ptr;
- if (buf[0]) {
- buf[strlen(buf) - 1] = 0;
- }
- if (buf[0] == 0 || buf[0] == '#' || buf[0] == ' ' || buf[0] == '\t') {
+ trim(buf);
+ if (buf[0] == 0 || buf[0] == '#') {
continue;
}
if (--maxEntries == 0) {
}
memset(&line, 0, sizeof(line));
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt) {
crondlog("\111User %s Entry %s\n", fileName, buf);
}
/* copy command */
(*pline)->cl_Shell = strdup(ptr);
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt) {
crondlog("\111 Command %s\n", ptr);
}
static int TestJobs(time_t t1, time_t t2)
{
- short nJobs = 0;
+ int nJobs = 0;
time_t t;
/* Find jobs > t1 and <= t2 */
CronLine *line;
for (file = FileBase; file; file = file->cf_Next) {
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt)
crondlog("\005FILE %s:\n", file->cf_User);
#endif
if (file->cf_Deleted)
continue;
for (line = file->cf_LineBase; line; line = line->cl_Next) {
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt)
crondlog("\005 LINE %s\n", line->cl_Shell);
#endif
if (line->cl_Mins[tp->tm_min] && line->cl_Hrs[tp->tm_hour] &&
(line->cl_Days[tp->tm_mday] || line->cl_Dow[tp->tm_wday])
&& line->cl_Mons[tp->tm_mon]) {
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt) {
crondlog("\005 JobToDo: %d %s\n",
line->cl_Pid, line->cl_Shell);
}
-#ifdef CONFIG_FEATURE_CROND_CALL_SENDMAIL
+#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
static void
ForkJob(const char *user, CronLine * line, int mailFd,
const char *prog, const char *cmd, const char *arg, const char *mailf)
if (ChangeUser(user) < 0) {
exit(0);
}
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt) {
crondlog("\005Child Running %s\n", prog);
}
ForkJob(user, line, mailFd, SENDMAIL, SENDMAIL_ARGS, NULL);
}
#else
-/* crond whithout sendmail */
+/* crond without sendmail */
static void RunJob(const char *user, CronLine * line)
{
if (ChangeUser(user) < 0) {
exit(0);
}
-#ifdef FEATURE_DEBUG_OPT
+#if ENABLE_DEBUG_CROND_OPTION
if (DebugOpt) {
crondlog("\005Child Running %s\n", DEFAULT_SHELL);
}
}
line->cl_Pid = pid;
}
-#endif /* CONFIG_FEATURE_CROND_CALL_SENDMAIL */
+#endif /* ENABLE_FEATURE_CROND_CALL_SENDMAIL */