mirror of
https://github.com/sheumann/hush.git
synced 2025-01-30 11:37:02 +00:00
crond: small code shrink and readability enhancements
This commit is contained in:
parent
8e8200a772
commit
314820e595
@ -98,7 +98,6 @@ static void crondlog(const char *ctl, ...)
|
|||||||
int type = level == 20 ?
|
int type = level == 20 ?
|
||||||
LOG_ERR : ((ctl[0] & 0100) ? LOG_WARNING : LOG_NOTICE);
|
LOG_ERR : ((ctl[0] & 0100) ? LOG_WARNING : LOG_NOTICE);
|
||||||
|
|
||||||
|
|
||||||
va_start(va, ctl);
|
va_start(va, ctl);
|
||||||
fmt = ctl + 1;
|
fmt = ctl + 1;
|
||||||
if (level >= LogLevel) {
|
if (level >= LogLevel) {
|
||||||
@ -108,7 +107,7 @@ static void crondlog(const char *ctl, ...)
|
|||||||
vfprintf(stderr, fmt, va);
|
vfprintf(stderr, fmt, va);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (LogFile == 0) {
|
if (LogFile == NULL) {
|
||||||
vsyslog(type, fmt, va);
|
vsyslog(type, fmt, va);
|
||||||
} else {
|
} else {
|
||||||
#if !ENABLE_DEBUG_CROND_OPTION
|
#if !ENABLE_DEBUG_CROND_OPTION
|
||||||
@ -271,7 +270,7 @@ static int ChangeUser(const char *user)
|
|||||||
|
|
||||||
static void startlogger(void)
|
static void startlogger(void)
|
||||||
{
|
{
|
||||||
if (LogFile == 0) {
|
if (LogFile == NULL) {
|
||||||
openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON);
|
openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON);
|
||||||
}
|
}
|
||||||
#if ENABLE_DEBUG_CROND_OPTION
|
#if ENABLE_DEBUG_CROND_OPTION
|
||||||
@ -778,7 +777,8 @@ static int CheckJobs(void)
|
|||||||
#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
|
#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
|
||||||
static void
|
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 *mail_filename)
|
||||||
{
|
{
|
||||||
/* 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();
|
||||||
@ -786,7 +786,6 @@ ForkJob(const char *user, CronLine * line, int mailFd,
|
|||||||
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) {
|
||||||
@ -799,31 +798,32 @@ ForkJob(const char *user, CronLine * line, int mailFd,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mailFd >= 0) {
|
if (mailFd >= 0) {
|
||||||
dup2(mailFd, mailf != NULL);
|
xmove_fd(mailFd, mail_filename ? 1 : 0);
|
||||||
dup2((mailf ? mailFd : 1), 2);
|
dup2(1, 2);
|
||||||
close(mailFd);
|
|
||||||
}
|
}
|
||||||
execl(prog, prog, cmd, arg, NULL);
|
execl(prog, prog, cmd, arg, NULL);
|
||||||
crondlog("\024cannot exec, user %s cmd %s %s %s\n", user, prog, cmd, arg);
|
crondlog("\024cannot exec, user %s cmd %s %s %s\n", user, prog, cmd, arg);
|
||||||
if (mailf) {
|
if (mail_filename) {
|
||||||
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) {
|
}
|
||||||
|
|
||||||
|
if (pid < 0) {
|
||||||
/* FORK FAILED */
|
/* FORK FAILED */
|
||||||
crondlog("\024cannot fork, user %s\n", user);
|
crondlog("\024cannot fork\n");
|
||||||
line->cl_Pid = 0;
|
line->cl_Pid = 0;
|
||||||
if (mailf) {
|
if (mail_filename) {
|
||||||
remove(mailf);
|
remove(mail_filename);
|
||||||
}
|
}
|
||||||
} else if (mailf) {
|
} else if (mail_filename) {
|
||||||
/* 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", user, pid);
|
snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid);
|
||||||
rename(mailf, mailFile2);
|
rename(mail_filename, mailFile2);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Close the mail file descriptor.. we can't just leave it open in
|
* Close the mail file descriptor.. we can't just leave it open in
|
||||||
|
Loading…
x
Reference in New Issue
Block a user