diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-01-24 01:33:12 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-01-24 01:33:12 +0000 |
commit | 314820e5953372359888b47a59dde54b2bf896b6 (patch) | |
tree | 8d3d357719a0d6d206b36a73eeb7d1c19a7438b0 /miscutils/crond.c | |
parent | 8e8200a772c2cc8a07327f1b6161b671e97b5017 (diff) | |
download | busybox-w32-314820e5953372359888b47a59dde54b2bf896b6.tar.gz busybox-w32-314820e5953372359888b47a59dde54b2bf896b6.tar.bz2 busybox-w32-314820e5953372359888b47a59dde54b2bf896b6.zip |
crond: small code shrink and readability enhancements
Diffstat (limited to 'miscutils/crond.c')
-rw-r--r-- | miscutils/crond.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/miscutils/crond.c b/miscutils/crond.c index 6056cb065..fd20e6a57 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -98,7 +98,6 @@ static void crondlog(const char *ctl, ...) | |||
98 | int type = level == 20 ? | 98 | int type = level == 20 ? |
99 | LOG_ERR : ((ctl[0] & 0100) ? LOG_WARNING : LOG_NOTICE); | 99 | LOG_ERR : ((ctl[0] & 0100) ? LOG_WARNING : LOG_NOTICE); |
100 | 100 | ||
101 | |||
102 | va_start(va, ctl); | 101 | va_start(va, ctl); |
103 | fmt = ctl + 1; | 102 | fmt = ctl + 1; |
104 | if (level >= LogLevel) { | 103 | if (level >= LogLevel) { |
@@ -108,7 +107,7 @@ static void crondlog(const char *ctl, ...) | |||
108 | vfprintf(stderr, fmt, va); | 107 | vfprintf(stderr, fmt, va); |
109 | } else | 108 | } else |
110 | #endif | 109 | #endif |
111 | if (LogFile == 0) { | 110 | if (LogFile == NULL) { |
112 | vsyslog(type, fmt, va); | 111 | vsyslog(type, fmt, va); |
113 | } else { | 112 | } else { |
114 | #if !ENABLE_DEBUG_CROND_OPTION | 113 | #if !ENABLE_DEBUG_CROND_OPTION |
@@ -271,7 +270,7 @@ static int ChangeUser(const char *user) | |||
271 | 270 | ||
272 | static void startlogger(void) | 271 | static void startlogger(void) |
273 | { | 272 | { |
274 | if (LogFile == 0) { | 273 | if (LogFile == NULL) { |
275 | openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON); | 274 | openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON); |
276 | } | 275 | } |
277 | #if ENABLE_DEBUG_CROND_OPTION | 276 | #if ENABLE_DEBUG_CROND_OPTION |
@@ -778,7 +777,8 @@ static int CheckJobs(void) | |||
778 | #if ENABLE_FEATURE_CROND_CALL_SENDMAIL | 777 | #if ENABLE_FEATURE_CROND_CALL_SENDMAIL |
779 | static void | 778 | static void |
780 | ForkJob(const char *user, CronLine * line, int mailFd, | 779 | ForkJob(const char *user, CronLine * line, int mailFd, |
781 | const char *prog, const char *cmd, const char *arg, const char *mailf) | 780 | const char *prog, const char *cmd, const char *arg, |
781 | const char *mail_filename) | ||
782 | { | 782 | { |
783 | /* Fork as the user in question and run program */ | 783 | /* Fork as the user in question and run program */ |
784 | pid_t pid = fork(); | 784 | pid_t pid = fork(); |
@@ -786,7 +786,6 @@ ForkJob(const char *user, CronLine * line, int mailFd, | |||
786 | line->cl_Pid = pid; | 786 | line->cl_Pid = pid; |
787 | if (pid == 0) { | 787 | if (pid == 0) { |
788 | /* CHILD */ | 788 | /* CHILD */ |
789 | |||
790 | /* Change running state to the user in question */ | 789 | /* Change running state to the user in question */ |
791 | 790 | ||
792 | if (ChangeUser(user) < 0) { | 791 | if (ChangeUser(user) < 0) { |
@@ -799,31 +798,32 @@ ForkJob(const char *user, CronLine * line, int mailFd, | |||
799 | #endif | 798 | #endif |
800 | 799 | ||
801 | if (mailFd >= 0) { | 800 | if (mailFd >= 0) { |
802 | dup2(mailFd, mailf != NULL); | 801 | xmove_fd(mailFd, mail_filename ? 1 : 0); |
803 | dup2((mailf ? mailFd : 1), 2); | 802 | dup2(1, 2); |
804 | close(mailFd); | ||
805 | } | 803 | } |
806 | execl(prog, prog, cmd, arg, NULL); | 804 | execl(prog, prog, cmd, arg, NULL); |
807 | crondlog("\024cannot exec, user %s cmd %s %s %s\n", user, prog, cmd, arg); | 805 | crondlog("\024cannot exec, user %s cmd %s %s %s\n", user, prog, cmd, arg); |
808 | if (mailf) { | 806 | if (mail_filename) { |
809 | fdprintf(1, "Exec failed: %s -c %s\n", prog, arg); | 807 | fdprintf(1, "Exec failed: %s -c %s\n", prog, arg); |
810 | } | 808 | } |
811 | exit(0); | 809 | exit(0); |
812 | } else if (pid < 0) { | 810 | } |
811 | |||
812 | if (pid < 0) { | ||
813 | /* FORK FAILED */ | 813 | /* FORK FAILED */ |
814 | crondlog("\024cannot fork, user %s\n", user); | 814 | crondlog("\024cannot fork\n"); |
815 | line->cl_Pid = 0; | 815 | line->cl_Pid = 0; |
816 | if (mailf) { | 816 | if (mail_filename) { |
817 | remove(mailf); | 817 | remove(mail_filename); |
818 | } | 818 | } |
819 | } else if (mailf) { | 819 | } else if (mail_filename) { |
820 | /* PARENT, FORK SUCCESS | 820 | /* PARENT, FORK SUCCESS |
821 | * rename mail-file based on pid of process | 821 | * rename mail-file based on pid of process |
822 | */ | 822 | */ |
823 | char mailFile2[128]; | 823 | char mailFile2[128]; |
824 | 824 | ||
825 | snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid); | 825 | snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid); |
826 | rename(mailf, mailFile2); | 826 | rename(mail_filename, mailFile2); |
827 | } | 827 | } |
828 | /* | 828 | /* |
829 | * Close the mail file descriptor.. we can't just leave it open in | 829 | * Close the mail file descriptor.. we can't just leave it open in |