diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-13 17:42:49 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-13 17:42:49 +0100 |
| commit | 78fcec4dc700dde189b0149ddfb53d321c4c75be (patch) | |
| tree | 58a7f2d86e609da04a0d0af0940853a18591277e | |
| parent | aa42d13e320250d3573c6be975876a612c00e91f (diff) | |
| download | busybox-w32-78fcec4dc700dde189b0149ddfb53d321c4c75be.tar.gz busybox-w32-78fcec4dc700dde189b0149ddfb53d321c4c75be.tar.bz2 busybox-w32-78fcec4dc700dde189b0149ddfb53d321c4c75be.zip | |
crond: do not log info messages at LOG_ERR. Closes bug 681. +62 bytes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | libbb/info_msg.c | 2 | ||||
| -rw-r--r-- | miscutils/crond.c | 41 |
2 files changed, 27 insertions, 16 deletions
diff --git a/libbb/info_msg.c b/libbb/info_msg.c index 5f375d43b..bc9d23b95 100644 --- a/libbb/info_msg.c +++ b/libbb/info_msg.c | |||
| @@ -38,6 +38,7 @@ void FAST_FUNC bb_info_msg(const char *s, ...) | |||
| 38 | 38 | ||
| 39 | va_start(p, s); | 39 | va_start(p, s); |
| 40 | used = vasprintf(&msg, s, p); | 40 | used = vasprintf(&msg, s, p); |
| 41 | va_end(p); | ||
| 41 | if (used < 0) | 42 | if (used < 0) |
| 42 | return; | 43 | return; |
| 43 | 44 | ||
| @@ -51,6 +52,5 @@ void FAST_FUNC bb_info_msg(const char *s, ...) | |||
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | free(msg); | 54 | free(msg); |
| 54 | va_end(p); | ||
| 55 | #endif | 55 | #endif |
| 56 | } | 56 | } |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 8e4f0bfd6..ad217f007 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
| @@ -122,15 +122,16 @@ static void EndJob(const char *user, CronLine *line); | |||
| 122 | static void DeleteFile(const char *userName); | 122 | static void DeleteFile(const char *userName); |
| 123 | 123 | ||
| 124 | 124 | ||
| 125 | /* 0 is the most verbose, default 8 */ | ||
| 125 | #define LVL5 "\x05" | 126 | #define LVL5 "\x05" |
| 126 | #define LVL7 "\x07" | 127 | #define LVL7 "\x07" |
| 127 | #define LVL8 "\x08" | 128 | #define LVL8 "\x08" |
| 128 | #define LVL9 "\x09" | ||
| 129 | #define WARN9 "\x49" | 129 | #define WARN9 "\x49" |
| 130 | #define DIE9 "\xc9" | 130 | #define DIE9 "\xc9" |
| 131 | /* level >= 20 is "error" */ | 131 | /* level >= 20 is "error" */ |
| 132 | #define ERR20 "\x14" | 132 | #define ERR20 "\x14" |
| 133 | 133 | ||
| 134 | static void crondlog(const char *ctl, ...) __attribute__ ((format (printf, 1, 2))); | ||
| 134 | static void crondlog(const char *ctl, ...) | 135 | static void crondlog(const char *ctl, ...) |
| 135 | { | 136 | { |
| 136 | va_list va; | 137 | va_list va; |
| @@ -146,8 +147,16 @@ static void crondlog(const char *ctl, ...) | |||
| 146 | if (logfd >= 0) | 147 | if (logfd >= 0) |
| 147 | xmove_fd(logfd, STDERR_FILENO); | 148 | xmove_fd(logfd, STDERR_FILENO); |
| 148 | } | 149 | } |
| 149 | // TODO: ERR -> error, WARN -> warning, LVL -> info | 150 | /* When we log to syslog, level > 8 is logged at LOG_ERR |
| 150 | bb_verror_msg(ctl + 1, va, /* strerr: */ NULL); | 151 | * syslog level, level <= 8 is logged at LOG_INFO. */ |
| 152 | if (level > 8) { | ||
| 153 | bb_verror_msg(ctl + 1, va, /* strerr: */ NULL); | ||
| 154 | } else { | ||
| 155 | char *msg = NULL; | ||
| 156 | vasprintf(&msg, ctl + 1, va); | ||
| 157 | bb_info_msg("%s: %s", applet_name, msg); | ||
| 158 | free(msg); | ||
| 159 | } | ||
| 151 | } | 160 | } |
| 152 | va_end(va); | 161 | va_end(va); |
| 153 | if (ctl[0] & 0x80) | 162 | if (ctl[0] & 0x80) |
| @@ -157,25 +166,25 @@ static void crondlog(const char *ctl, ...) | |||
| 157 | int crond_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 166 | int crond_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 158 | int crond_main(int argc UNUSED_PARAM, char **argv) | 167 | int crond_main(int argc UNUSED_PARAM, char **argv) |
| 159 | { | 168 | { |
| 160 | unsigned opt; | 169 | unsigned opts; |
| 161 | 170 | ||
| 162 | INIT_G(); | 171 | INIT_G(); |
| 163 | 172 | ||
| 164 | /* "-b after -f is ignored", and so on for every pair a-b */ | 173 | /* "-b after -f is ignored", and so on for every pair a-b */ |
| 165 | opt_complementary = "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l") | 174 | opt_complementary = "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l") |
| 166 | ":l+:d+"; /* -l and -d have numeric param */ | 175 | ":l+:d+"; /* -l and -d have numeric param */ |
| 167 | opt = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"), | 176 | opts = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"), |
| 168 | &LogLevel, &LogFile, &CDir | 177 | &LogLevel, &LogFile, &CDir |
| 169 | IF_FEATURE_CROND_D(,&LogLevel)); | 178 | IF_FEATURE_CROND_D(,&LogLevel)); |
| 170 | /* both -d N and -l N set the same variable: LogLevel */ | 179 | /* both -d N and -l N set the same variable: LogLevel */ |
| 171 | 180 | ||
| 172 | if (!(opt & OPT_f)) { | 181 | if (!(opts & OPT_f)) { |
| 173 | /* close stdin, stdout, stderr. | 182 | /* close stdin, stdout, stderr. |
| 174 | * close unused descriptors - don't need them. */ | 183 | * close unused descriptors - don't need them. */ |
| 175 | bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); | 184 | bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); |
| 176 | } | 185 | } |
| 177 | 186 | ||
| 178 | if (!DebugOpt && LogFile == NULL) { | 187 | if (!(opts & OPT_d) && LogFile == NULL) { |
| 179 | /* logging to syslog */ | 188 | /* logging to syslog */ |
| 180 | openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON); | 189 | openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON); |
| 181 | logmode = LOGMODE_SYSLOG; | 190 | logmode = LOGMODE_SYSLOG; |
| @@ -184,20 +193,21 @@ int crond_main(int argc UNUSED_PARAM, char **argv) | |||
| 184 | xchdir(CDir); | 193 | xchdir(CDir); |
| 185 | //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */ | 194 | //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */ |
| 186 | xsetenv("SHELL", DEFAULT_SHELL); /* once, for all future children */ | 195 | xsetenv("SHELL", DEFAULT_SHELL); /* once, for all future children */ |
| 187 | crondlog(LVL9 "crond (busybox "BB_VER") started, log level %d", LogLevel); | 196 | crondlog(LVL8 "crond (busybox "BB_VER") started, log level %d", LogLevel); |
| 188 | SynchronizeDir(); | 197 | SynchronizeDir(); |
| 189 | 198 | ||
| 190 | /* main loop - synchronize to 1 second after the minute, minimum sleep | 199 | /* main loop - synchronize to 1 second after the minute, minimum sleep |
| 191 | * of 1 second. */ | 200 | * of 1 second. */ |
| 192 | { | 201 | { |
| 193 | time_t t1 = time(NULL); | 202 | time_t t1 = time(NULL); |
| 194 | time_t t2; | ||
| 195 | long dt; | ||
| 196 | int rescan = 60; | 203 | int rescan = 60; |
| 197 | int sleep_time = 60; | 204 | int sleep_time = 60; |
| 198 | 205 | ||
| 199 | write_pidfile("/var/run/crond.pid"); | 206 | write_pidfile("/var/run/crond.pid"); |
| 200 | for (;;) { | 207 | for (;;) { |
| 208 | time_t t2; | ||
| 209 | long dt; | ||
| 210 | |||
| 201 | sleep((sleep_time + 1) - (time(NULL) % sleep_time)); | 211 | sleep((sleep_time + 1) - (time(NULL) % sleep_time)); |
| 202 | 212 | ||
| 203 | t2 = time(NULL); | 213 | t2 = time(NULL); |
| @@ -227,7 +237,7 @@ int crond_main(int argc UNUSED_PARAM, char **argv) | |||
| 227 | if (DebugOpt) | 237 | if (DebugOpt) |
| 228 | crondlog(LVL5 "wakeup dt=%ld", dt); | 238 | crondlog(LVL5 "wakeup dt=%ld", dt); |
| 229 | if (dt < -60 * 60 || dt > 60 * 60) { | 239 | if (dt < -60 * 60 || dt > 60 * 60) { |
| 230 | crondlog(WARN9 "time disparity of %d minutes detected", dt / 60); | 240 | crondlog(WARN9 "time disparity of %ld minutes detected", dt / 60); |
| 231 | } else if (dt > 0) { | 241 | } else if (dt > 0) { |
| 232 | TestJobs(t1, t2); | 242 | TestJobs(t1, t2); |
| 233 | RunJobs(); | 243 | RunJobs(); |
| @@ -239,8 +249,9 @@ int crond_main(int argc UNUSED_PARAM, char **argv) | |||
| 239 | } | 249 | } |
| 240 | } | 250 | } |
| 241 | t1 = t2; | 251 | t1 = t2; |
| 242 | } | 252 | } /* for (;;) */ |
| 243 | } | 253 | } |
| 254 | |||
| 244 | return 0; /* not reached */ | 255 | return 0; /* not reached */ |
| 245 | } | 256 | } |
| 246 | 257 | ||
| @@ -281,7 +292,7 @@ static void ChangeUser(struct passwd *pas) | |||
| 281 | /* careful: we're after vfork! */ | 292 | /* careful: we're after vfork! */ |
| 282 | change_identity(pas); /* - initgroups, setgid, setuid */ | 293 | change_identity(pas); /* - initgroups, setgid, setuid */ |
| 283 | if (chdir(pas->pw_dir) < 0) { | 294 | if (chdir(pas->pw_dir) < 0) { |
| 284 | crondlog(LVL9 "can't chdir(%s)", pas->pw_dir); | 295 | crondlog(WARN9 "can't chdir(%s)", pas->pw_dir); |
| 285 | if (chdir(TMPDIR) < 0) { | 296 | if (chdir(TMPDIR) < 0) { |
| 286 | crondlog(DIE9 "can't chdir(%s)", TMPDIR); /* exits */ | 297 | crondlog(DIE9 "can't chdir(%s)", TMPDIR); /* exits */ |
| 287 | } | 298 | } |
| @@ -760,7 +771,7 @@ ForkJob(const char *user, CronLine *line, int mailFd, | |||
| 760 | /* prepare things before vfork */ | 771 | /* prepare things before vfork */ |
| 761 | pas = getpwnam(user); | 772 | pas = getpwnam(user); |
| 762 | if (!pas) { | 773 | if (!pas) { |
| 763 | crondlog(LVL9 "can't get uid for %s", user); | 774 | crondlog(WARN9 "can't get uid for %s", user); |
| 764 | goto err; | 775 | goto err; |
| 765 | } | 776 | } |
| 766 | SetEnv(pas); | 777 | SetEnv(pas); |
| @@ -900,7 +911,7 @@ static void RunJob(const char *user, CronLine *line) | |||
| 900 | /* prepare things before vfork */ | 911 | /* prepare things before vfork */ |
| 901 | pas = getpwnam(user); | 912 | pas = getpwnam(user); |
| 902 | if (!pas) { | 913 | if (!pas) { |
| 903 | crondlog(LVL9 "can't get uid for %s", user); | 914 | crondlog(WARN9 "can't get uid for %s", user); |
| 904 | goto err; | 915 | goto err; |
| 905 | } | 916 | } |
| 906 | SetEnv(pas); | 917 | SetEnv(pas); |
