From 3532e60ca890979030949793933442afaec272fb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 6 Jul 2017 02:04:32 +0200 Subject: makedevs: allow much longer filenames function old new delta makedevs_main 1056 1071 +15 Patch by Kang-Che Sung Signed-off-by: Denys Vlasenko --- miscutils/makedevs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'miscutils') diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 9e7ca340f..fec1045e4 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c @@ -208,17 +208,17 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) unsigned count = 0; unsigned increment = 0; unsigned start = 0; - char name[41]; char user[41]; char group[41]; - char *full_name = name; + char *full_name; + int name_len; uid_t uid; gid_t gid; linenum = parser->lineno; - if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", - name, &type, &mode, user, group, + if ((1 > sscanf(line, "%*s%n %c %o %40s %40s %u %u %u %u %u", + &name_len, &type, &mode, user, group, &major, &minor, &start, &increment, &count)) || ((unsigned)(major | minor | start | count | increment) > 255) ) { @@ -229,9 +229,11 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) gid = (*group) ? get_ug_id(group, xgroup2gid) : getgid(); uid = (*user) ? get_ug_id(user, xuname2uid) : getuid(); + line[name_len] = '\0'; + full_name = line; /* We are already in the right root dir, * so make absolute paths relative */ - if ('/' == *full_name) + if ('/' == full_name[0]) full_name++; if (type == 'd') { -- cgit v1.2.3-55-g6feb From 3c9688e58737665d204ab70e6b0e10c745c99c30 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 6 Jul 2017 02:17:24 +0200 Subject: makedevs: code shrink function old new delta makedevs_main 1071 1052 -19 Signed-off-by: Denys Vlasenko --- miscutils/makedevs.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'miscutils') diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index fec1045e4..f436b08f8 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c @@ -262,9 +262,7 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) if (chmod(full_name, mode) < 0) goto chmod_fail; } else { - dev_t rdev; unsigned i; - char *full_name_inc; if (type == 'p') { mode |= S_IFIFO; @@ -278,26 +276,29 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) continue; } - full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2); - if (count) + if (count != 0) count--; - for (i = start; i <= start + count; i++) { - sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i); - rdev = makedev(major, minor + (i - start) * increment); - if (mknod(full_name_inc, mode, rdev) != 0 + for (i = 0; i <= count; i++) { + dev_t rdev; + char *nameN = full_name; + if (count != 0) + nameN = xasprintf("%s%u", full_name, start + i); + rdev = makedev(major, minor + i * increment); + if (mknod(nameN, mode, rdev) != 0 && errno != EEXIST ) { - bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc); + bb_perror_msg("line %d: can't create node %s", linenum, nameN); ret = EXIT_FAILURE; - } else if (chown(full_name_inc, uid, gid) < 0) { - bb_perror_msg("line %d: can't chown %s", linenum, full_name_inc); + } else if (chown(nameN, uid, gid) < 0) { + bb_perror_msg("line %d: can't chown %s", linenum, nameN); ret = EXIT_FAILURE; - } else if (chmod(full_name_inc, mode) < 0) { - bb_perror_msg("line %d: can't chmod %s", linenum, full_name_inc); + } else if (chmod(nameN, mode) < 0) { + bb_perror_msg("line %d: can't chmod %s", linenum, nameN); ret = EXIT_FAILURE; } + if (count != 0) + free(nameN); } - free(full_name_inc); } } if (ENABLE_FEATURE_CLEAN_UP) -- cgit v1.2.3-55-g6feb From 1b84f4a22adb1a8c3fa633a5b08081694667505c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 8 Jul 2017 12:21:45 +0200 Subject: beep: disallow FEATURE_BEEP_FREQ = 0 in configuration Signed-off-by: Denys Vlasenko --- miscutils/beep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'miscutils') diff --git a/miscutils/beep.c b/miscutils/beep.c index 14802b543..216f69400 100644 --- a/miscutils/beep.c +++ b/miscutils/beep.c @@ -16,7 +16,7 @@ //config: //config:config FEATURE_BEEP_FREQ //config: int "default frequency" -//config: range 0 2147483647 +//config: range 20 50000 # allowing 0 here breaks the build //config: default 4000 //config: depends on BEEP //config: help -- cgit v1.2.3-55-g6feb From 31c765081dc41f158786545fbea9294be4685bd2 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Sat, 8 Jul 2017 18:35:25 +0200 Subject: watchdog: stop watchdog first on startup Some watchdog implementations may do things other than issue a reboot on a watchdog timeout. In this case, there's the possibility of restarting this program from the state of the watchdog device not being properly stopped (done by writing a 'V' and closing the device). Since it wasn't stopped, the driver may not be able to restart the watchdog when this program reopens it and starts pinging it. To fix this, the code will always first issue the stop when it starts up. function old new delta shutdown_on_signal - 32 +32 watchdog_main 268 298 +30 shutdown_watchdog - 25 +25 watchdog_shutdown 41 - -41 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 1/0 up/down: 87/-41) Total: 46 bytes Signed-off-by: Matt Spinler Signed-off-by: Denys Vlasenko --- miscutils/watchdog.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'miscutils') diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index 07ae64e52..95e2f1a53 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c @@ -42,17 +42,36 @@ #define OPT_STIMER (1 << 1) #define OPT_HTIMER (1 << 2) -static void watchdog_shutdown(int sig UNUSED_PARAM) +static void shutdown_watchdog(void) { static const char V = 'V'; + write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */ + close(3); +} +static void shutdown_on_signal(int sig UNUSED_PARAM) +{ remove_pidfile(CONFIG_PID_FILE_PATH "/watchdog.pid"); - write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */ - if (ENABLE_FEATURE_CLEAN_UP) - close(3); + shutdown_watchdog(); _exit(EXIT_SUCCESS); } +static void watchdog_open(const char* device) +{ + /* Use known fd # - avoid needing global 'int fd' */ + xmove_fd(xopen(device, O_WRONLY), 3); + + /* If the watchdog driver can do something other than cause a reboot + * on a timeout, then it's possible this program may be starting from + * a state when the watchdog hadn't been previously stopped with + * the magic write followed by a close. In this case the driver may + * not start properly, so always do the proper stop first just in case. + */ + shutdown_watchdog(); + + xmove_fd(xopen(device, O_WRONLY), 3); +} + int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int watchdog_main(int argc, char **argv) { @@ -86,10 +105,9 @@ int watchdog_main(int argc, char **argv) if (opts & OPT_STIMER) stimer_duration = xatou_sfx(st_arg, suffixes); - bb_signals(BB_FATAL_SIGS, watchdog_shutdown); + bb_signals(BB_FATAL_SIGS, shutdown_on_signal); - /* Use known fd # - avoid needing global 'int fd' */ - xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); + watchdog_open(argv[argc - 1]); /* WDIOC_SETTIMEOUT takes seconds, not milliseconds */ htimer_duration = htimer_duration / 1000; -- cgit v1.2.3-55-g6feb From 1572f520ccfe9e45d4cb9b18bb7b728eb2bbb571 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 8 Jul 2017 18:53:49 +0200 Subject: watchdog: do not use argc, other cleanups function old new delta watchdog_main 298 291 -7 Signed-off-by: Denys Vlasenko --- miscutils/watchdog.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'miscutils') diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index 95e2f1a53..d379a97f4 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c @@ -35,8 +35,21 @@ //usage: "\nUse 500ms to specify period in milliseconds" #include "libbb.h" -#include "linux/types.h" /* for __u32 */ -#include "linux/watchdog.h" +#include /* for __u32 */ +#include + +#ifndef WDIOC_SETOPTIONS +# define WDIOC_SETOPTIONS 0x5704 +#endif +#ifndef WDIOC_SETTIMEOUT +# define WDIOC_SETTIMEOUT 0x5706 +#endif +#ifndef WDIOC_GETTIMEOUT +# define WDIOC_GETTIMEOUT 0x5707 +#endif +#ifndef WDIOS_ENABLECARD +# define WDIOS_ENABLECARD 2 +#endif #define OPT_FOREGROUND (1 << 0) #define OPT_STIMER (1 << 1) @@ -73,8 +86,9 @@ static void watchdog_open(const char* device) } int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int watchdog_main(int argc, char **argv) +int watchdog_main(int argc UNUSED_PARAM, char **argv) { + static const int enable = WDIOS_ENABLECARD; static const struct suffix_mult suffixes[] = { { "ms", 1 }, { "", 1000 }, @@ -99,6 +113,8 @@ int watchdog_main(int argc, char **argv) if (!(opts & OPT_FOREGROUND)) bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); + /* maybe bb_logenv_override(); here for LOGGING=syslog to work? */ + if (opts & OPT_HTIMER) htimer_duration = xatou_sfx(ht_arg, suffixes); stimer_duration = htimer_duration / 2; @@ -107,22 +123,12 @@ int watchdog_main(int argc, char **argv) bb_signals(BB_FATAL_SIGS, shutdown_on_signal); - watchdog_open(argv[argc - 1]); + watchdog_open(argv[optind]); /* WDIOC_SETTIMEOUT takes seconds, not milliseconds */ htimer_duration = htimer_duration / 1000; -#ifndef WDIOC_SETTIMEOUT -# error WDIOC_SETTIMEOUT is not defined, cannot compile watchdog applet -#else -# if defined WDIOC_SETOPTIONS && defined WDIOS_ENABLECARD - { - static const int enable = WDIOS_ENABLECARD; - ioctl_or_warn(3, WDIOC_SETOPTIONS, (void*) &enable); - } -# endif + ioctl_or_warn(3, WDIOC_SETOPTIONS, (void*) &enable); ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration); -#endif - #if 0 ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration); printf("watchdog: SW timer is %dms, HW timer is %ds\n", -- cgit v1.2.3-55-g6feb From 75fbea3879b251ef4a66c6da23a6c0e3a706c016 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 8 Jul 2017 20:53:11 +0200 Subject: crond: support @daily etc function old new delta start_jobs - 348 +348 load_crontab 766 936 +170 static.SpecAry - 96 +96 crond_main 1424 1134 -290 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 1/1 up/down: 614/-290) Total: 324 bytes Based on patch by Jonathan Kolb Signed-off-by: Denys Vlasenko --- miscutils/crond.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 19 deletions(-) (limited to 'miscutils') diff --git a/miscutils/crond.c b/miscutils/crond.c index 88e7b47b3..8a399446c 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -35,6 +35,22 @@ //config: help //config: Command output will be sent to corresponding user via email. //config: +//config:config FEATURE_CROND_SPECIAL_TIMES +//config: bool "Support special times (@reboot, @daily, etc) in crontabs" +//config: default y +//config: depends on CROND +//config: help +//config: string meaning +//config: ------ ------- +//config: @reboot Run once, at startup +//config: @yearly Run once a year: "0 0 1 1 *" +//config: @annually Same as @yearly: "0 0 1 1 *" +//config: @monthly Run once a month: "0 0 1 * *" +//config: @weekly Run once a week: "0 0 * * 0" +//config: @daily Run once a day: "0 0 * * *" +//config: @midnight Same as @daily: "0 0 * * *" +//config: @hourly Run once an hour: "0 * * * *" +//config: //config:config FEATURE_CROND_DIR //config: string "crond spool directory" //config: default "/var/spool/cron" @@ -74,6 +90,7 @@ #define CRON_DIR CONFIG_FEATURE_CROND_DIR #define CRONTABS CONFIG_FEATURE_CROND_DIR "/crontabs" +#define CRON_REBOOT CONFIG_PID_FILE_PATH "/crond.reboot" #ifndef SENDMAIL # define SENDMAIL "sendmail" #endif @@ -101,6 +118,8 @@ typedef struct CronLine { struct CronLine *cl_next; char *cl_cmd; /* shell command */ pid_t cl_pid; /* >0:running, <0:needs to be started in this minute, 0:dormant */ +#define START_ME_REBOOT -2 +#define START_ME_NORMAL -1 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL int cl_empty_mail_size; /* size of mail header only, 0 if no mailfile */ char *cl_mailto; /* whom to mail results, may be NULL */ @@ -452,6 +471,59 @@ static void load_crontab(const char *fileName) shell = xstrdup(&tokens[0][6]); continue; } +#if ENABLE_FEATURE_CROND_SPECIAL_TIMES + if (tokens[0][0] == '@') { + /* + * "@daily /a/script/to/run PARAM1 PARAM2..." + */ + typedef struct SpecialEntry { + const char *name; + const char tokens[8]; + } SpecialEntry; + static const SpecialEntry SpecAry[] = { + /* hour day month weekday */ + { "yearly", "0\0" "1\0" "1\0" "*" }, + { "annually", "0\0" "1\0" "1\0" "*" }, + { "monthly", "0\0" "1\0" "*\0" "*" }, + { "weekly", "0\0" "*\0" "*\0" "0" }, + { "daily", "0\0" "*\0" "*\0" "*" }, + { "midnight", "0\0" "*\0" "*\0" "*" }, + { "hourly", "*\0" "*\0" "*\0" "*" }, + { "reboot", "" }, + }; + const SpecialEntry *e = SpecAry; + + if (n < 2) + continue; + for (;;) { + if (strcmp(e->name, tokens[0] + 1) == 0) { + /* + * tokens[1] is only the first word of command, + * find the entire command in unmodified string: + */ + tokens[5] = strstr( + skip_non_whitespace(skip_whitespace(parser->data)), + /* ^^^^ avoids mishandling e.g. "@daily aily PARAM" */ + tokens[1] + ); + if (e->tokens[0]) { + char *et = (char*)e->tokens; + /* minute is "0" for all specials */ + tokens[0] = (char*)"0"; + tokens[1] = et; + tokens[2] = et + 2; + tokens[3] = et + 4; + tokens[4] = et + 6; + } + goto got_it; + } + if (!e->tokens[0]) + break; + e++; + } + continue; /* bad line (unrecognized '@foo') */ + } +#endif //TODO: handle HOME= too? "man crontab" says: //name = value // @@ -468,18 +540,30 @@ static void load_crontab(const char *fileName) /* check if a minimum of tokens is specified */ if (n < 6) continue; + IF_FEATURE_CROND_SPECIAL_TIMES( + got_it: + ) *pline = line = xzalloc(sizeof(*line)); - /* parse date ranges */ - ParseField(file->cf_username, line->cl_Mins, 60, 0, NULL, tokens[0]); - ParseField(file->cf_username, line->cl_Hrs, 24, 0, NULL, tokens[1]); - ParseField(file->cf_username, line->cl_Days, 32, 0, NULL, tokens[2]); - ParseField(file->cf_username, line->cl_Mons, 12, -1, MonAry, tokens[3]); - ParseField(file->cf_username, line->cl_Dow, 7, 0, DowAry, tokens[4]); - /* - * fix days and dow - if one is not "*" and the other - * is "*", the other is set to 0, and vise-versa - */ - FixDayDow(line); +#if ENABLE_FEATURE_CROND_SPECIAL_TIMES + if (tokens[0][0] == '@') { /* "@reboot" line */ + file->cf_wants_starting = 1; + line->cl_pid = START_ME_REBOOT; /* wants to start */ + /* line->cl_Mins/Hrs/etc stay zero: never match any time */ + } else +#endif + { + /* parse date ranges */ + ParseField(file->cf_username, line->cl_Mins, 60, 0, NULL, tokens[0]); + ParseField(file->cf_username, line->cl_Hrs, 24, 0, NULL, tokens[1]); + ParseField(file->cf_username, line->cl_Days, 32, 0, NULL, tokens[2]); + ParseField(file->cf_username, line->cl_Mons, 12, -1, MonAry, tokens[3]); + ParseField(file->cf_username, line->cl_Dow, 7, 0, DowAry, tokens[4]); + /* + * fix days and dow - if one is not "*" and the other + * is "*", the other is set to 0, and vise-versa + */ + FixDayDow(line); + } #if ENABLE_FEATURE_CROND_CALL_SENDMAIL /* copy mailto (can be NULL) */ line->cl_mailto = xstrdup(mailTo); @@ -664,7 +748,7 @@ fork_job(const char *user, int mailFd, CronLine *line, bool run_sendmail) return pid; } -static void start_one_job(const char *user, CronLine *line) +static pid_t start_one_job(const char *user, CronLine *line) { char mailFile[128]; int mailFd = -1; @@ -698,6 +782,8 @@ static void start_one_job(const char *user, CronLine *line) free(mailFile2); } } + + return line->cl_pid; } /* @@ -748,7 +834,7 @@ static void process_finished_job(const char *user, CronLine *line) #else /* !ENABLE_FEATURE_CROND_CALL_SENDMAIL */ -static void start_one_job(const char *user, CronLine *line) +static pid_t start_one_job(const char *user, CronLine *line) { const char *shell; struct passwd *pas; @@ -782,6 +868,7 @@ static void start_one_job(const char *user, CronLine *line) pid = 0; } line->cl_pid = pid; + return pid; } #define process_finished_job(user, line) ((line)->cl_pid = 0) @@ -825,7 +912,7 @@ static void flag_starting_jobs(time_t t1, time_t t2) log8("user %s: process already running: %s", file->cf_username, line->cl_cmd); } else if (line->cl_pid == 0) { - line->cl_pid = -1; + line->cl_pid = START_ME_NORMAL; file->cf_wants_starting = 1; } } @@ -834,7 +921,20 @@ static void flag_starting_jobs(time_t t1, time_t t2) } } -static void start_jobs(void) +#if ENABLE_FEATURE_CROND_SPECIAL_TIMES +static int touch_reboot_file(void) +{ + int fd = open(CRON_REBOOT, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0000); + if (fd >= 0) { + close(fd); + return 1; + } + /* File (presumably) exists - this is not the first run after reboot */ + return 0; +} +#endif + +static void start_jobs(int wants_start) { CronFile *file; CronLine *line; @@ -846,11 +946,10 @@ static void start_jobs(void) file->cf_wants_starting = 0; for (line = file->cf_lines; line; line = line->cl_next) { pid_t pid; - if (line->cl_pid >= 0) + if (line->cl_pid != wants_start) continue; - start_one_job(file->cf_username, line); - pid = line->cl_pid; + pid = start_one_job(file->cf_username, line); log8("USER %s pid %3d cmd %s", file->cf_username, (int)pid, line->cl_cmd); if (pid < 0) { @@ -950,6 +1049,10 @@ int crond_main(int argc UNUSED_PARAM, char **argv) log8("crond (busybox "BB_VER") started, log level %d", G.log_level); rescan_crontab_dir(); write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid"); +#if ENABLE_FEATURE_CROND_SPECIAL_TIMES + if (touch_reboot_file()) + start_jobs(START_ME_REBOOT); /* start @reboot entries, if any */ +#endif /* Main loop */ t2 = time(NULL); @@ -1002,7 +1105,7 @@ int crond_main(int argc UNUSED_PARAM, char **argv) } else if (dt > 0) { /* Usual case: time advances forward, as expected */ flag_starting_jobs(t1, t2); - start_jobs(); + start_jobs(START_ME_NORMAL); sleep_time = 60; if (check_completions() > 0) { /* some jobs are still running */ -- cgit v1.2.3-55-g6feb From 0b3b65fa91214d112581cfdd28526604b1399ece Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 9 Jul 2017 00:00:39 +0200 Subject: crond: move misplaced comment Signed-off-by: Denys Vlasenko --- miscutils/crond.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'miscutils') diff --git a/miscutils/crond.c b/miscutils/crond.c index 8a399446c..a472c9b23 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -471,6 +471,19 @@ static void load_crontab(const char *fileName) shell = xstrdup(&tokens[0][6]); continue; } +//TODO: handle HOME= too? "man crontab" says: +//name = value +// +//where the spaces around the equal-sign (=) are optional, and any subsequent +//non-leading spaces in value will be part of the value assigned to name. +//The value string may be placed in quotes (single or double, but matching) +//to preserve leading or trailing blanks. +// +//Several environment variables are set up automatically by the cron(8) daemon. +//SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd +//line of the crontab's owner. HOME and SHELL may be overridden by settings +//in the crontab; LOGNAME may not. + #if ENABLE_FEATURE_CROND_SPECIAL_TIMES if (tokens[0][0] == '@') { /* @@ -524,19 +537,6 @@ static void load_crontab(const char *fileName) continue; /* bad line (unrecognized '@foo') */ } #endif -//TODO: handle HOME= too? "man crontab" says: -//name = value -// -//where the spaces around the equal-sign (=) are optional, and any subsequent -//non-leading spaces in value will be part of the value assigned to name. -//The value string may be placed in quotes (single or double, but matching) -//to preserve leading or trailing blanks. -// -//Several environment variables are set up automatically by the cron(8) daemon. -//SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd -//line of the crontab's owner. HOME and SHELL may be overridden by settings -//in the crontab; LOGNAME may not. - /* check if a minimum of tokens is specified */ if (n < 6) continue; -- cgit v1.2.3-55-g6feb From d18b2000967cddd0b84091d90a914aec58025310 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 9 Jul 2017 00:08:13 +0200 Subject: crond: code shrink function old new delta load_crontab 936 925 -11 Signed-off-by: Denys Vlasenko --- miscutils/crond.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'miscutils') diff --git a/miscutils/crond.c b/miscutils/crond.c index a472c9b23..c0c8bef11 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -512,13 +512,12 @@ static void load_crontab(const char *fileName) if (strcmp(e->name, tokens[0] + 1) == 0) { /* * tokens[1] is only the first word of command, + * can'r use it. * find the entire command in unmodified string: */ - tokens[5] = strstr( - skip_non_whitespace(skip_whitespace(parser->data)), - /* ^^^^ avoids mishandling e.g. "@daily aily PARAM" */ - tokens[1] - ); + tokens[5] = skip_whitespace( + skip_non_whitespace( + skip_whitespace(parser->data))); if (e->tokens[0]) { char *et = (char*)e->tokens; /* minute is "0" for all specials */ -- cgit v1.2.3-55-g6feb From 68e980545af6a8ffb2980f94a6edac4dd89940f3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 16 Jul 2017 20:36:48 +0200 Subject: ttysize: if stdin is not tty, try stdout, then stderr function old new delta ttysize_main 135 175 +40 packed_usage 31686 31672 -14 Signed-off-by: Denys Vlasenko --- miscutils/ttysize.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'miscutils') diff --git a/miscutils/ttysize.c b/miscutils/ttysize.c index 135ce8535..cba65b148 100644 --- a/miscutils/ttysize.c +++ b/miscutils/ttysize.c @@ -25,7 +25,7 @@ //usage:#define ttysize_trivial_usage //usage: "[w] [h]" //usage:#define ttysize_full_usage "\n\n" -//usage: "Print dimension(s) of stdin's terminal, on error return 80x25" +//usage: "Print dimensions of stdin tty, or 80x24" #include "libbb.h" @@ -37,7 +37,10 @@ int ttysize_main(int argc UNUSED_PARAM, char **argv) w = 80; h = 24; - if (!ioctl(0, TIOCGWINSZ, &wsz)) { + if (ioctl(0, TIOCGWINSZ, &wsz) == 0 + || ioctl(1, TIOCGWINSZ, &wsz) == 0 + || ioctl(2, TIOCGWINSZ, &wsz) == 0 + ) { w = wsz.ws_col; h = wsz.ws_row; } -- cgit v1.2.3-55-g6feb