Fixup braces (patch from Thomas Geulig), run through indent and manually
adjust.
This commit is contained in:
@ -99,6 +99,7 @@ static void RunJobs(void);
|
|||||||
static int CheckJobs(void);
|
static int CheckJobs(void);
|
||||||
|
|
||||||
static void RunJob(const char *user, CronLine * line);
|
static void RunJob(const char *user, CronLine * line);
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_CROND_CALL_SENDMAIL
|
#ifdef CONFIG_FEATURE_CROND_CALL_SENDMAIL
|
||||||
static void EndJob(const char *user, CronLine * line);
|
static void EndJob(const char *user, CronLine * line);
|
||||||
#else
|
#else
|
||||||
@ -110,8 +111,7 @@ static void DeleteFile(const char *userName);
|
|||||||
static CronFile *FileBase;
|
static CronFile *FileBase;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void crondlog(const char *ctl, ...)
|
||||||
crondlog(const char *ctl, ...)
|
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
@ -125,14 +125,15 @@ crondlog(const char *ctl, ...)
|
|||||||
if (level >= LogLevel) {
|
if (level >= LogLevel) {
|
||||||
|
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
if (DebugOpt) vfprintf(stderr, fmt, va);
|
if (DebugOpt) {
|
||||||
else
|
vfprintf(stderr, fmt, va);
|
||||||
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (LogFile == 0) vsyslog(type, fmt, va);
|
if (LogFile == 0) {
|
||||||
else {
|
vsyslog(type, fmt, va);
|
||||||
int logfd;
|
} else {
|
||||||
|
int logfd = open(LogFile, O_WRONLY | O_CREAT | O_APPEND, 600);
|
||||||
if ((logfd = open(LogFile, O_WRONLY|O_CREAT|O_APPEND, 600)) >= 0) {
|
if (logfd >= 0) {
|
||||||
vdprintf(logfd, fmt, va);
|
vdprintf(logfd, fmt, va);
|
||||||
close(logfd);
|
close(logfd);
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
@ -143,17 +144,19 @@ crondlog(const char *ctl, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
if(ctl[0] & 0200)
|
if (ctl[0] & 0200) {
|
||||||
exit(20);
|
exit(20);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int crond_main(int ac, char **av)
|
||||||
crond_main(int ac, char **av)
|
|
||||||
{
|
{
|
||||||
unsigned long opt;
|
unsigned long opt;
|
||||||
char *lopt, *Lopt, *copt;
|
char *lopt, *Lopt, *copt;
|
||||||
|
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
char *dopt;
|
char *dopt;
|
||||||
|
|
||||||
bb_opt_complementaly = "f-b:b-f:S-L:L-S:d-l";
|
bb_opt_complementaly = "f-b:b-f:S-L:L-S:d-l";
|
||||||
#else
|
#else
|
||||||
bb_opt_complementaly = "f-b:b-f:S-L:L-S";
|
bb_opt_complementaly = "f-b:b-f:S-L:L-S";
|
||||||
@ -169,12 +172,18 @@ crond_main(int ac, char **av)
|
|||||||
, &dopt
|
, &dopt
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if(opt & 1)
|
if (opt & 1) {
|
||||||
LogLevel = atoi(lopt);
|
LogLevel = atoi(lopt);
|
||||||
if(opt & 2)
|
}
|
||||||
if (*Lopt != 0) LogFile = Lopt;
|
if (opt & 2) {
|
||||||
|
if (*Lopt != 0) {
|
||||||
|
LogFile = Lopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (opt & 32) {
|
if (opt & 32) {
|
||||||
if (*copt != 0) CDir = copt;
|
if (*copt != 0) {
|
||||||
|
CDir = copt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
if (opt & 64) {
|
if (opt & 64) {
|
||||||
@ -187,9 +196,9 @@ crond_main(int ac, char **av)
|
|||||||
* change directory
|
* change directory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (chdir(CDir) != 0)
|
if (chdir(CDir) != 0) {
|
||||||
bb_perror_msg_and_die("%s", CDir);
|
bb_perror_msg_and_die("%s", CDir);
|
||||||
|
}
|
||||||
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
|
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
|
||||||
* version - his died. ;(
|
* version - his died. ;(
|
||||||
*/
|
*/
|
||||||
@ -206,6 +215,7 @@ crond_main(int ac, char **av)
|
|||||||
#else /* uClinux */
|
#else /* uClinux */
|
||||||
if (daemon(1, 0) < 0) {
|
if (daemon(1, 0) < 0) {
|
||||||
bb_perror_msg_and_die("daemon");
|
bb_perror_msg_and_die("daemon");
|
||||||
|
}
|
||||||
#endif /* uClinux */
|
#endif /* uClinux */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,8 +226,8 @@ crond_main(int ac, char **av)
|
|||||||
* of 1 second.
|
* of 1 second.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
crondlog("\011%s " VERSION " dillon, started, log level %d\n", bb_applet_name,
|
crondlog("\011%s " VERSION " dillon, started, log level %d\n",
|
||||||
LogLevel);
|
bb_applet_name, LogLevel);
|
||||||
|
|
||||||
SynchronizeDir();
|
SynchronizeDir();
|
||||||
|
|
||||||
@ -267,24 +277,23 @@ crond_main(int ac, char **av)
|
|||||||
TestJobs(t1, t2);
|
TestJobs(t1, t2);
|
||||||
RunJobs();
|
RunJobs();
|
||||||
sleep(5);
|
sleep(5);
|
||||||
if (CheckJobs() > 0)
|
if (CheckJobs() > 0) {
|
||||||
sleep_time = 10;
|
sleep_time = 10;
|
||||||
else
|
} else {
|
||||||
sleep_time = 60;
|
sleep_time = 60;
|
||||||
|
}
|
||||||
t1 = t2;
|
t1 = t2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* not reached */
|
/* not reached */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(FEATURE_DEBUG_OPT) || defined(CONFIG_FEATURE_CROND_CALL_SENDMAIL)
|
#if defined(FEATURE_DEBUG_OPT) || defined(CONFIG_FEATURE_CROND_CALL_SENDMAIL)
|
||||||
/*
|
/*
|
||||||
write to temp file..
|
write to temp file..
|
||||||
*/
|
*/
|
||||||
static void
|
static void fdprintf(int fd, const char *ctl, ...)
|
||||||
fdprintf(int fd, const char *ctl, ...)
|
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
@ -295,8 +304,7 @@ fdprintf(int fd, const char *ctl, ...)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int ChangeUser(const char *user)
|
||||||
ChangeUser(const char *user)
|
|
||||||
{
|
{
|
||||||
struct passwd *pas;
|
struct passwd *pas;
|
||||||
const char *err_msg;
|
const char *err_msg;
|
||||||
@ -304,8 +312,8 @@ ChangeUser(const char *user)
|
|||||||
/*
|
/*
|
||||||
* Obtain password entry and change privilages
|
* Obtain password entry and change privilages
|
||||||
*/
|
*/
|
||||||
|
pas = getpwnam(user);
|
||||||
if ((pas = getpwnam(user)) == 0) {
|
if (pas == 0) {
|
||||||
crondlog("\011failed to get uid for %s", user);
|
crondlog("\011failed to get uid for %s", user);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -331,20 +339,21 @@ ChangeUser(const char *user)
|
|||||||
return (pas->pw_uid);
|
return (pas->pw_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void startlogger(void)
|
||||||
startlogger(void)
|
|
||||||
{
|
{
|
||||||
if (LogFile == 0)
|
if (LogFile == 0) {
|
||||||
openlog(bb_applet_name, LOG_CONS | LOG_PID, LOG_CRON);
|
openlog(bb_applet_name, LOG_CONS | LOG_PID, LOG_CRON);
|
||||||
|
}
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
else { /* test logfile */
|
else { /* test logfile */
|
||||||
int logfd;
|
int logfd;
|
||||||
|
|
||||||
if ((logfd = open(LogFile, O_WRONLY|O_CREAT|O_APPEND, 600)) >= 0)
|
if ((logfd = open(LogFile, O_WRONLY | O_CREAT | O_APPEND, 600)) >= 0) {
|
||||||
close(logfd);
|
close(logfd);
|
||||||
else
|
} else {
|
||||||
bb_perror_msg("Failed to open log file '%s' reason", LogFile);
|
bb_perror_msg("Failed to open log file '%s' reason", LogFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,23 +406,21 @@ static const char * const MonAry[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *
|
static char *ParseField(char *user, char *ary, int modvalue, int off,
|
||||||
ParseField(char *user, char *ary, int modvalue, int off,
|
|
||||||
const char *const *names, char *ptr)
|
const char *const *names, char *ptr)
|
||||||
{
|
{
|
||||||
char *base = ptr;
|
char *base = ptr;
|
||||||
int n1 = -1;
|
int n1 = -1;
|
||||||
int n2 = -1;
|
int n2 = -1;
|
||||||
|
|
||||||
if (base == NULL)
|
if (base == NULL) {
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n') {
|
while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n') {
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
|
||||||
/*
|
/* Handle numeric digit or symbol or '*' */
|
||||||
* Handle numeric digit or symbol or '*'
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (*ptr == '*') {
|
if (*ptr == '*') {
|
||||||
n1 = 0; /* everything will be filled */
|
n1 = 0; /* everything will be filled */
|
||||||
@ -421,10 +428,11 @@ ParseField(char *user, char *ary, int modvalue, int off,
|
|||||||
skip = 1;
|
skip = 1;
|
||||||
++ptr;
|
++ptr;
|
||||||
} else if (*ptr >= '0' && *ptr <= '9') {
|
} else if (*ptr >= '0' && *ptr <= '9') {
|
||||||
if (n1 < 0)
|
if (n1 < 0) {
|
||||||
n1 = strtol(ptr, &ptr, 10) + off;
|
n1 = strtol(ptr, &ptr, 10) + off;
|
||||||
else
|
} else {
|
||||||
n2 = strtol(ptr, &ptr, 10) + off;
|
n2 = strtol(ptr, &ptr, 10) + off;
|
||||||
|
}
|
||||||
skip = 1;
|
skip = 1;
|
||||||
} else if (names) {
|
} else if (names) {
|
||||||
int i;
|
int i;
|
||||||
@ -436,17 +444,16 @@ ParseField(char *user, char *ary, int modvalue, int off,
|
|||||||
}
|
}
|
||||||
if (names[i]) {
|
if (names[i]) {
|
||||||
ptr += strlen(names[i]);
|
ptr += strlen(names[i]);
|
||||||
if (n1 < 0)
|
if (n1 < 0) {
|
||||||
n1 = i;
|
n1 = i;
|
||||||
else
|
} else {
|
||||||
n2 = i;
|
n2 = i;
|
||||||
|
}
|
||||||
skip = 1;
|
skip = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* handle optional range '-' */
|
||||||
* handle optional range '-'
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (skip == 0) {
|
if (skip == 0) {
|
||||||
crondlog("\111failed user %s parsing %s\n", user, base);
|
crondlog("\111failed user %s parsing %s\n", user, base);
|
||||||
@ -462,12 +469,12 @@ ParseField(char *user, char *ary, int modvalue, int off,
|
|||||||
* in the character array appropriately.
|
* in the character array appropriately.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (n2 < 0)
|
if (n2 < 0) {
|
||||||
n2 = n1;
|
n2 = n1;
|
||||||
|
}
|
||||||
if (*ptr == '/')
|
if (*ptr == '/') {
|
||||||
skip = strtol(ptr + 1, &ptr, 10);
|
skip = strtol(ptr + 1, &ptr, 10);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* fill array, using a failsafe is the easiest way to prevent
|
* fill array, using a failsafe is the easiest way to prevent
|
||||||
* an endless loop
|
* an endless loop
|
||||||
@ -485,15 +492,17 @@ ParseField(char *user, char *ary, int modvalue, int off,
|
|||||||
ary[n1 % modvalue] = 1;
|
ary[n1 % modvalue] = 1;
|
||||||
s0 = skip;
|
s0 = skip;
|
||||||
}
|
}
|
||||||
} while (n1 != n2 && --failsafe);
|
}
|
||||||
|
while (n1 != n2 && --failsafe);
|
||||||
|
|
||||||
if (failsafe == 0) {
|
if (failsafe == 0) {
|
||||||
crondlog("\111failed user %s parsing %s\n", user, base);
|
crondlog("\111failed user %s parsing %s\n", user, base);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*ptr != ',')
|
if (*ptr != ',') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
++ptr;
|
++ptr;
|
||||||
n1 = -1;
|
n1 = -1;
|
||||||
n2 = -1;
|
n2 = -1;
|
||||||
@ -504,15 +513,16 @@ ParseField(char *user, char *ary, int modvalue, int off,
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n')
|
while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') {
|
||||||
++ptr;
|
++ptr;
|
||||||
|
}
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
if (DebugOpt) {
|
if (DebugOpt) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < modvalue; ++i)
|
for (i = 0; i < modvalue; ++i) {
|
||||||
crondlog("\005%d", ary[i]);
|
crondlog("\005%d", ary[i]);
|
||||||
|
}
|
||||||
crondlog("\005\n");
|
crondlog("\005\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -520,8 +530,7 @@ ParseField(char *user, char *ary, int modvalue, int off,
|
|||||||
return (ptr);
|
return (ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void FixDayDow(CronLine * line)
|
||||||
FixDayDow(CronLine *line)
|
|
||||||
{
|
{
|
||||||
short i;
|
short i;
|
||||||
short weekUsed = 0;
|
short weekUsed = 0;
|
||||||
@ -549,15 +558,15 @@ FixDayDow(CronLine *line)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void SynchronizeFile(const char *fileName)
|
||||||
SynchronizeFile(const char *fileName)
|
|
||||||
{
|
{
|
||||||
int maxEntries = MAXLINES;
|
int maxEntries = MAXLINES;
|
||||||
int maxLines;
|
int maxLines;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
if (strcmp(fileName, "root") == 0)
|
if (strcmp(fileName, "root") == 0) {
|
||||||
maxEntries = 65535;
|
maxEntries = 65535;
|
||||||
|
}
|
||||||
maxLines = maxEntries * 10;
|
maxLines = maxEntries * 10;
|
||||||
|
|
||||||
if (fileName) {
|
if (fileName) {
|
||||||
@ -565,7 +574,8 @@ SynchronizeFile(const char *fileName)
|
|||||||
|
|
||||||
DeleteFile(fileName);
|
DeleteFile(fileName);
|
||||||
|
|
||||||
if ((fi = fopen(fileName, "r")) != NULL) {
|
fi = fopen(fileName, "r");
|
||||||
|
if (fi != NULL) {
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
|
|
||||||
if (fstat(fileno(fi), &sbuf) == 0 && sbuf.st_uid == DaemonUid) {
|
if (fstat(fileno(fi), &sbuf) == 0 && sbuf.st_uid == DaemonUid) {
|
||||||
@ -579,38 +589,34 @@ SynchronizeFile(const char *fileName)
|
|||||||
CronLine line;
|
CronLine line;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
if (buf[0])
|
if (buf[0]) {
|
||||||
buf[strlen(buf) - 1] = 0;
|
buf[strlen(buf) - 1] = 0;
|
||||||
|
}
|
||||||
if (buf[0] == 0 || buf[0] == '#' || buf[0] == ' ' || buf[0] == '\t')
|
if (buf[0] == 0 || buf[0] == '#' || buf[0] == ' ' || buf[0] == '\t') {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if (--maxEntries == 0)
|
if (--maxEntries == 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
memset(&line, 0, sizeof(line));
|
memset(&line, 0, sizeof(line));
|
||||||
|
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
if (DebugOpt)
|
if (DebugOpt) {
|
||||||
crondlog("\111User %s Entry %s\n", fileName, buf);
|
crondlog("\111User %s Entry %s\n", fileName, buf);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/* parse date ranges */
|
||||||
* parse date ranges
|
|
||||||
*/
|
|
||||||
|
|
||||||
ptr = ParseField(file->cf_User, line.cl_Mins, 60, 0, NULL, buf);
|
ptr = ParseField(file->cf_User, line.cl_Mins, 60, 0, NULL, buf);
|
||||||
ptr = ParseField(file->cf_User, line.cl_Hrs, 24, 0, NULL, ptr);
|
ptr = ParseField(file->cf_User, line.cl_Hrs, 24, 0, NULL, ptr);
|
||||||
ptr = ParseField(file->cf_User, line.cl_Days, 32, 0, NULL, ptr);
|
ptr = ParseField(file->cf_User, line.cl_Days, 32, 0, NULL, ptr);
|
||||||
ptr = ParseField(file->cf_User, line.cl_Mons, 12, -1, MonAry, ptr);
|
ptr = ParseField(file->cf_User, line.cl_Mons, 12, -1, MonAry, ptr);
|
||||||
ptr = ParseField(file->cf_User, line.cl_Dow, 7, 0, DowAry, ptr);
|
ptr = ParseField(file->cf_User, line.cl_Dow, 7, 0, DowAry, ptr);
|
||||||
|
|
||||||
/*
|
/* check failure */
|
||||||
* check failure
|
if (ptr == NULL) {
|
||||||
*/
|
|
||||||
|
|
||||||
if (ptr == NULL)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fix days and dow - if one is not * and the other
|
* fix days and dow - if one is not * and the other
|
||||||
@ -622,10 +628,7 @@ SynchronizeFile(const char *fileName)
|
|||||||
*pline = calloc(1, sizeof(CronLine));
|
*pline = calloc(1, sizeof(CronLine));
|
||||||
**pline = line;
|
**pline = line;
|
||||||
|
|
||||||
/*
|
/* copy command */
|
||||||
* copy command
|
|
||||||
*/
|
|
||||||
|
|
||||||
(*pline)->cl_Shell = strdup(ptr);
|
(*pline)->cl_Shell = strdup(ptr);
|
||||||
|
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
@ -641,21 +644,22 @@ SynchronizeFile(const char *fileName)
|
|||||||
file->cf_Next = FileBase;
|
file->cf_Next = FileBase;
|
||||||
FileBase = file;
|
FileBase = file;
|
||||||
|
|
||||||
if (maxLines == 0 || maxEntries == 0)
|
if (maxLines == 0 || maxEntries == 0) {
|
||||||
crondlog("\111Maximum number of lines reached for user %s\n", fileName);
|
crondlog("\111Maximum number of lines reached for user %s\n", fileName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fclose(fi);
|
fclose(fi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void CheckUpdates(void)
|
||||||
CheckUpdates(void)
|
|
||||||
{
|
{
|
||||||
FILE *fi;
|
FILE *fi;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
if ((fi = fopen(CRONUPDATE, "r")) != NULL) {
|
fi = fopen(CRONUPDATE, "r");
|
||||||
|
if (fi != NULL) {
|
||||||
remove(CRONUPDATE);
|
remove(CRONUPDATE);
|
||||||
while (fgets(buf, sizeof(buf), fi) != NULL) {
|
while (fgets(buf, sizeof(buf), fi) != NULL) {
|
||||||
SynchronizeFile(strtok(buf, " \t\r\n"));
|
SynchronizeFile(strtok(buf, " \t\r\n"));
|
||||||
@ -664,20 +668,17 @@ CheckUpdates(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SynchronizeDir(void)
|
||||||
SynchronizeDir(void)
|
|
||||||
{
|
{
|
||||||
/*
|
/* Attempt to delete the database. */
|
||||||
* Attempt to delete the database.
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
CronFile *file;
|
CronFile *file;
|
||||||
|
|
||||||
for (file = FileBase; file && file->cf_Deleted; file = file->cf_Next)
|
for (file = FileBase; file && file->cf_Deleted; file = file->cf_Next);
|
||||||
;
|
if (file == NULL) {
|
||||||
if (file == NULL)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
DeleteFile(file->cf_User);
|
DeleteFile(file->cf_User);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,18 +696,20 @@ SynchronizeDir(void)
|
|||||||
crondlog("\311unable to find %s\n", CDir);
|
crondlog("\311unable to find %s\n", CDir);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir = opendir(".");
|
||||||
struct dirent *den;
|
struct dirent *den;
|
||||||
|
|
||||||
if ((dir = opendir("."))) {
|
if (dir) {
|
||||||
while ((den = readdir(dir))) {
|
while ((den = readdir(dir))) {
|
||||||
if (strchr(den->d_name, '.') != NULL)
|
if (strchr(den->d_name, '.') != NULL) {
|
||||||
continue;
|
continue;
|
||||||
if (getpwnam(den->d_name))
|
}
|
||||||
|
if (getpwnam(den->d_name)) {
|
||||||
SynchronizeFile(den->d_name);
|
SynchronizeFile(den->d_name);
|
||||||
else
|
} else {
|
||||||
crondlog("\007ignoring %s\n", den->d_name);
|
crondlog("\007ignoring %s\n", den->d_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
} else {
|
} else {
|
||||||
crondlog("\311Unable to open current dir!\n");
|
crondlog("\311Unable to open current dir!\n");
|
||||||
@ -722,8 +725,7 @@ SynchronizeDir(void)
|
|||||||
* completely delete a database due to running processes.
|
* completely delete a database due to running processes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void DeleteFile(const char *userName)
|
||||||
DeleteFile(const char *userName)
|
|
||||||
{
|
{
|
||||||
CronFile **pfile = &FileBase;
|
CronFile **pfile = &FileBase;
|
||||||
CronFile *file;
|
CronFile *file;
|
||||||
@ -767,15 +769,12 @@ DeleteFile(const char *userName)
|
|||||||
* hour (60 scans).
|
* hour (60 scans).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int TestJobs(time_t t1, time_t t2)
|
||||||
TestJobs(time_t t1, time_t t2)
|
|
||||||
{
|
{
|
||||||
short nJobs = 0;
|
short nJobs = 0;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
/*
|
/* Find jobs > t1 and <= t2 */
|
||||||
* Find jobs > t1 and <= t2
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (t = t1 - t1 % 60; t <= t2; t += 60) {
|
for (t = t1 - t1 % 60; t <= t2; t += 60) {
|
||||||
if (t > t1) {
|
if (t > t1) {
|
||||||
@ -795,20 +794,18 @@ TestJobs(time_t t1, time_t t2)
|
|||||||
if (DebugOpt)
|
if (DebugOpt)
|
||||||
crondlog("\005 LINE %s\n", line->cl_Shell);
|
crondlog("\005 LINE %s\n", line->cl_Shell);
|
||||||
#endif
|
#endif
|
||||||
if (line->cl_Mins[tp->tm_min] &&
|
if (line->cl_Mins[tp->tm_min] && line->cl_Hrs[tp->tm_hour] &&
|
||||||
line->cl_Hrs[tp->tm_hour] &&
|
(line->cl_Days[tp->tm_mday] || line->cl_Dow[tp->tm_wday])
|
||||||
(line->cl_Days[tp->tm_mday] || line->cl_Dow[tp->tm_wday]) &&
|
&& line->cl_Mons[tp->tm_mon]) {
|
||||||
line->cl_Mons[tp->tm_mon]
|
|
||||||
) {
|
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
if (DebugOpt)
|
if (DebugOpt) {
|
||||||
crondlog("\005 JobToDo: %d %s\n", line->cl_Pid, line->cl_Shell);
|
crondlog("\005 JobToDo: %d %s\n",
|
||||||
|
line->cl_Pid, line->cl_Shell);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (line->cl_Pid > 0) {
|
if (line->cl_Pid > 0) {
|
||||||
crondlog("\010 process already running: %s %s\n",
|
crondlog("\010 process already running: %s %s\n",
|
||||||
file->cf_User,
|
file->cf_User, line->cl_Shell);
|
||||||
line->cl_Shell
|
|
||||||
);
|
|
||||||
} else if (line->cl_Pid == 0) {
|
} else if (line->cl_Pid == 0) {
|
||||||
line->cl_Pid = -1;
|
line->cl_Pid = -1;
|
||||||
file->cf_Ready = 1;
|
file->cf_Ready = 1;
|
||||||
@ -822,8 +819,7 @@ TestJobs(time_t t1, time_t t2)
|
|||||||
return (nJobs);
|
return (nJobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void RunJobs(void)
|
||||||
RunJobs(void)
|
|
||||||
{
|
{
|
||||||
CronFile *file;
|
CronFile *file;
|
||||||
CronLine *line;
|
CronLine *line;
|
||||||
@ -838,19 +834,18 @@ RunJobs(void)
|
|||||||
RunJob(file->cf_User, line);
|
RunJob(file->cf_User, line);
|
||||||
|
|
||||||
crondlog("\010USER %s pid %3d cmd %s\n",
|
crondlog("\010USER %s pid %3d cmd %s\n",
|
||||||
file->cf_User,
|
file->cf_User, line->cl_Pid, line->cl_Shell);
|
||||||
line->cl_Pid,
|
if (line->cl_Pid < 0) {
|
||||||
line->cl_Shell
|
|
||||||
);
|
|
||||||
if (line->cl_Pid < 0)
|
|
||||||
file->cf_Ready = 1;
|
file->cf_Ready = 1;
|
||||||
else if (line->cl_Pid > 0)
|
}
|
||||||
|
else if (line->cl_Pid > 0) {
|
||||||
file->cf_Running = 1;
|
file->cf_Running = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CheckJobs() - check for job completion
|
* CheckJobs() - check for job completion
|
||||||
@ -859,8 +854,7 @@ RunJobs(void)
|
|||||||
* all done.
|
* all done.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int CheckJobs(void)
|
||||||
CheckJobs(void)
|
|
||||||
{
|
{
|
||||||
CronFile *file;
|
CronFile *file;
|
||||||
CronLine *line;
|
CronLine *line;
|
||||||
@ -877,8 +871,9 @@ CheckJobs(void)
|
|||||||
|
|
||||||
if (r < 0 || r == line->cl_Pid) {
|
if (r < 0 || r == line->cl_Pid) {
|
||||||
EndJob(file->cf_User, line);
|
EndJob(file->cf_User, line);
|
||||||
if (line->cl_Pid)
|
if (line->cl_Pid) {
|
||||||
file->cf_Running = 1;
|
file->cf_Running = 1;
|
||||||
|
}
|
||||||
} else if (r == 0) {
|
} else if (r == 0) {
|
||||||
file->cf_Running = 1;
|
file->cf_Running = 1;
|
||||||
}
|
}
|
||||||
@ -896,27 +891,22 @@ static void
|
|||||||
ForkJob(const char *user, CronLine * line, int mailFd,
|
ForkJob(const char *user, CronLine * line, int mailFd,
|
||||||
const char *prog, const char *cmd, const char *arg, const char *mailf)
|
const char *prog, const char *cmd, const char *arg, const char *mailf)
|
||||||
{
|
{
|
||||||
/*
|
/* Fork as the user in question and run program */
|
||||||
* Fork as the user in question and run program
|
|
||||||
*/
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
line->cl_Pid = pid;
|
line->cl_Pid = pid;
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/*
|
/* CHILD */
|
||||||
* CHILD
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/* Change running state to the user in question */
|
||||||
* Change running state to the user in question
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (ChangeUser(user) < 0)
|
if (ChangeUser(user) < 0) {
|
||||||
exit(0);
|
exit(0);
|
||||||
|
}
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
if (DebugOpt)
|
if (DebugOpt) {
|
||||||
crondlog("\005Child Running %s\n", prog);
|
crondlog("\005Child Running %s\n", prog);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mailFd >= 0) {
|
if (mailFd >= 0) {
|
||||||
@ -925,29 +915,25 @@ ForkJob(const char *user, CronLine *line, int mailFd,
|
|||||||
close(mailFd);
|
close(mailFd);
|
||||||
}
|
}
|
||||||
execl(prog, prog, cmd, arg, NULL);
|
execl(prog, prog, cmd, arg, NULL);
|
||||||
crondlog("\024unable to exec, user %s cmd %s %s %s\n", user,
|
crondlog("\024unable to exec, user %s cmd %s %s %s\n", user, prog, cmd, arg);
|
||||||
prog, cmd, arg);
|
if (mailf) {
|
||||||
if(mailf)
|
|
||||||
fdprintf(1, "Exec failed: %s -c %s\n", prog, arg);
|
fdprintf(1, "Exec failed: %s -c %s\n", prog, arg);
|
||||||
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (pid < 0) {
|
} else if (pid < 0) {
|
||||||
/*
|
/* FORK FAILED */
|
||||||
* FORK FAILED
|
|
||||||
*/
|
|
||||||
crondlog("\024couldn't fork, user %s\n", user);
|
crondlog("\024couldn't fork, user %s\n", user);
|
||||||
line->cl_Pid = 0;
|
line->cl_Pid = 0;
|
||||||
if(mailf)
|
if (mailf) {
|
||||||
remove(mailf);
|
remove(mailf);
|
||||||
|
}
|
||||||
} else if (mailf) {
|
} else if (mailf) {
|
||||||
/*
|
/* PARENT, FORK SUCCESS
|
||||||
* PARENT, FORK SUCCESS
|
|
||||||
*
|
|
||||||
* rename mail-file based on pid of process
|
* rename mail-file based on pid of process
|
||||||
*/
|
*/
|
||||||
char mailFile2[128];
|
char mailFile2[128];
|
||||||
|
|
||||||
snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d",
|
snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid);
|
||||||
user, pid);
|
|
||||||
rename(mailf, mailFile2);
|
rename(mailf, mailFile2);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -955,12 +941,12 @@ ForkJob(const char *user, CronLine *line, int mailFd,
|
|||||||
* a structure, closing it later, because we might run out of descriptors
|
* a structure, closing it later, because we might run out of descriptors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (mailFd >= 0)
|
if (mailFd >= 0) {
|
||||||
close(mailFd);
|
close(mailFd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void RunJob(const char *user, CronLine * line)
|
||||||
RunJob(const char *user, CronLine *line)
|
|
||||||
{
|
{
|
||||||
char mailFile[128];
|
char mailFile[128];
|
||||||
int mailFd;
|
int mailFd;
|
||||||
@ -968,12 +954,9 @@ RunJob(const char *user, CronLine *line)
|
|||||||
line->cl_Pid = 0;
|
line->cl_Pid = 0;
|
||||||
line->cl_MailFlag = 0;
|
line->cl_MailFlag = 0;
|
||||||
|
|
||||||
/*
|
/* open mail file - owner root so nobody can screw with it. */
|
||||||
* open mail file - owner root so nobody can screw with it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
snprintf(mailFile, sizeof(mailFile), TMPDIR "/cron.%s.%d",
|
snprintf(mailFile, sizeof(mailFile), TMPDIR "/cron.%s.%d", user, getpid());
|
||||||
user, getpid());
|
|
||||||
mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600);
|
mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600);
|
||||||
|
|
||||||
if (mailFd >= 0) {
|
if (mailFd >= 0) {
|
||||||
@ -982,8 +965,7 @@ RunJob(const char *user, CronLine *line)
|
|||||||
line->cl_Shell);
|
line->cl_Shell);
|
||||||
line->cl_MailPos = lseek(mailFd, 0, 1);
|
line->cl_MailPos = lseek(mailFd, 0, 1);
|
||||||
} else {
|
} else {
|
||||||
crondlog("\024unable to create mail file user %s file %s, output to /dev/null\n",
|
crondlog("\024unable to create mail file user %s file %s, output to /dev/null\n", user, mailFile);
|
||||||
user, mailFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ForkJob(user, line, mailFd, DEFAULT_SHELL, "-c", line->cl_Shell, mailFile);
|
ForkJob(user, line, mailFd, DEFAULT_SHELL, "-c", line->cl_Shell, mailFile);
|
||||||
@ -993,16 +975,13 @@ RunJob(const char *user, CronLine *line)
|
|||||||
* EndJob - called when job terminates and when mail terminates
|
* EndJob - called when job terminates and when mail terminates
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void EndJob(const char *user, CronLine * line)
|
||||||
EndJob(const char *user, CronLine *line)
|
|
||||||
{
|
{
|
||||||
int mailFd;
|
int mailFd;
|
||||||
char mailFile[128];
|
char mailFile[128];
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
|
|
||||||
/*
|
/* No job */
|
||||||
* No job
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (line->cl_Pid <= 0) {
|
if (line->cl_Pid <= 0) {
|
||||||
line->cl_Pid = 0;
|
line->cl_Pid = 0;
|
||||||
@ -1014,13 +993,12 @@ EndJob(const char *user, CronLine *line)
|
|||||||
* End of sendmail job
|
* End of sendmail job
|
||||||
*/
|
*/
|
||||||
|
|
||||||
snprintf(mailFile, sizeof(mailFile), TMPDIR "/cron.%s.%d",
|
snprintf(mailFile, sizeof(mailFile), TMPDIR "/cron.%s.%d", user, line->cl_Pid);
|
||||||
user, line->cl_Pid);
|
|
||||||
line->cl_Pid = 0;
|
line->cl_Pid = 0;
|
||||||
|
|
||||||
if (line->cl_MailFlag != 1)
|
if (line->cl_MailFlag != 1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
line->cl_MailFlag = 0;
|
line->cl_MailFlag = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1034,12 +1012,8 @@ EndJob(const char *user, CronLine *line)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(mailFd, &sbuf) < 0 ||
|
if (fstat(mailFd, &sbuf) < 0 || sbuf.st_uid != DaemonUid || sbuf.st_nlink != 0 ||
|
||||||
sbuf.st_uid != DaemonUid ||
|
sbuf.st_size == line->cl_MailPos || !S_ISREG(sbuf.st_mode)) {
|
||||||
sbuf.st_nlink != 0 ||
|
|
||||||
sbuf.st_size == line->cl_MailPos ||
|
|
||||||
!S_ISREG(sbuf.st_mode)
|
|
||||||
) {
|
|
||||||
close(mailFd);
|
close(mailFd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1048,29 +1022,23 @@ EndJob(const char *user, CronLine *line)
|
|||||||
#else
|
#else
|
||||||
/* crond whithout sendmail */
|
/* crond whithout sendmail */
|
||||||
|
|
||||||
static void
|
static void RunJob(const char *user, CronLine * line)
|
||||||
RunJob(const char *user, CronLine *line)
|
|
||||||
{
|
{
|
||||||
/*
|
/* Fork as the user in question and run program */
|
||||||
* Fork as the user in question and run program
|
|
||||||
*/
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/*
|
/* CHILD */
|
||||||
* CHILD
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/* Change running state to the user in question */
|
||||||
* Change running state to the user in question
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (ChangeUser(user) < 0)
|
if (ChangeUser(user) < 0) {
|
||||||
exit(0);
|
exit(0);
|
||||||
|
}
|
||||||
#ifdef FEATURE_DEBUG_OPT
|
#ifdef FEATURE_DEBUG_OPT
|
||||||
if (DebugOpt)
|
if (DebugOpt) {
|
||||||
crondlog("\005Child Running %s\n", DEFAULT_SHELL);
|
crondlog("\005Child Running %s\n", DEFAULT_SHELL);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", line->cl_Shell, NULL);
|
execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", line->cl_Shell, NULL);
|
||||||
@ -1078,9 +1046,7 @@ RunJob(const char *user, CronLine *line)
|
|||||||
DEFAULT_SHELL, line->cl_Shell);
|
DEFAULT_SHELL, line->cl_Shell);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (pid < 0) {
|
} else if (pid < 0) {
|
||||||
/*
|
/* FORK FAILED */
|
||||||
* FORK FAILED
|
|
||||||
*/
|
|
||||||
crondlog("\024couldn't fork, user %s\n", user);
|
crondlog("\024couldn't fork, user %s\n", user);
|
||||||
pid = 0;
|
pid = 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user