diff options
author | Ron Yorston <rmy@pobox.com> | 2019-03-31 08:55:48 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-03-31 09:51:00 +0100 |
commit | 61e0e3160a8be3ed8488b09200a5dca1bd1b21b4 (patch) | |
tree | d55341d875d1dd0d77445960723a47418efd14e5 /miscutils | |
parent | be2949717934c19890879cf2a8fc74c5da55d1c7 (diff) | |
parent | 35082fc2c17369223669e099f422acc0982ee4ff (diff) | |
download | busybox-w32-61e0e3160a8be3ed8488b09200a5dca1bd1b21b4.tar.gz busybox-w32-61e0e3160a8be3ed8488b09200a5dca1bd1b21b4.tar.bz2 busybox-w32-61e0e3160a8be3ed8488b09200a5dca1bd1b21b4.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/crond.c | 2 | ||||
-rw-r--r-- | miscutils/man.c | 54 | ||||
-rw-r--r-- | miscutils/ts.c | 84 | ||||
-rw-r--r-- | miscutils/watchdog.c | 4 |
4 files changed, 111 insertions, 33 deletions
diff --git a/miscutils/crond.c b/miscutils/crond.c index 2e36c406b..25e5503c7 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -1056,7 +1056,7 @@ int crond_main(int argc UNUSED_PARAM, char **argv) | |||
1056 | 1056 | ||
1057 | log8("crond (busybox "BB_VER") started, log level %d", G.log_level); | 1057 | log8("crond (busybox "BB_VER") started, log level %d", G.log_level); |
1058 | rescan_crontab_dir(); | 1058 | rescan_crontab_dir(); |
1059 | write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid"); | 1059 | write_pidfile_std_path_and_ext("crond"); |
1060 | #if ENABLE_FEATURE_CROND_SPECIAL_TIMES | 1060 | #if ENABLE_FEATURE_CROND_SPECIAL_TIMES |
1061 | if (touch_reboot_file()) | 1061 | if (touch_reboot_file()) |
1062 | start_jobs(START_ME_REBOOT); /* start @reboot entries, if any */ | 1062 | start_jobs(START_ME_REBOOT); /* start @reboot entries, if any */ |
diff --git a/miscutils/man.c b/miscutils/man.c index 0bc11e623..6724b4b5d 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
@@ -13,9 +13,9 @@ | |||
13 | //kbuild:lib-$(CONFIG_MAN) += man.o | 13 | //kbuild:lib-$(CONFIG_MAN) += man.o |
14 | 14 | ||
15 | //usage:#define man_trivial_usage | 15 | //usage:#define man_trivial_usage |
16 | //usage: "[-aw] [MANPAGE]..." | 16 | //usage: "[-aw] MANPAGE..." |
17 | //usage:#define man_full_usage "\n\n" | 17 | //usage:#define man_full_usage "\n\n" |
18 | //usage: "Format and display manual page\n" | 18 | //usage: "Display manual page\n" |
19 | //usage: "\n -a Display all pages" | 19 | //usage: "\n -a Display all pages" |
20 | //usage: "\n -w Show page locations" | 20 | //usage: "\n -w Show page locations" |
21 | //usage: "\n" | 21 | //usage: "\n" |
@@ -209,9 +209,6 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path) | |||
209 | path_element = man_path_list; | 209 | path_element = man_path_list; |
210 | if (path_element) while (*path_element) { | 210 | if (path_element) while (*path_element) { |
211 | if (strcmp(*path_element, path) == 0) { | 211 | if (strcmp(*path_element, path) == 0) { |
212 | /* Have path but haven't counted it, must be default */ | ||
213 | if (*count_mp == 0) | ||
214 | break; | ||
215 | goto skip; | 212 | goto skip; |
216 | } | 213 | } |
217 | path_element++; | 214 | path_element++; |
@@ -247,14 +244,14 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
247 | { | 244 | { |
248 | parser_t *parser; | 245 | parser_t *parser; |
249 | char *sec_list; | 246 | char *sec_list; |
250 | char *cur_path, *cur_sect; | ||
251 | char **man_path_list; | 247 | char **man_path_list; |
252 | int count_mp; | 248 | int count_mp; |
253 | int cur_mp; | ||
254 | int opt, not_found; | 249 | int opt, not_found; |
255 | char *token[2]; | 250 | char *token[2]; |
256 | #if ENABLE_PLATFORM_MINGW32 | 251 | #if ENABLE_PLATFORM_MINGW32 |
257 | char **ptr; | 252 | char **ptr; |
253 | char *exepath, *relpath; | ||
254 | const char *mpl[] = { "/usr/man", "/usr/share/man", NULL, NULL }; | ||
258 | #endif | 255 | #endif |
259 | 256 | ||
260 | INIT_G(); | 257 | INIT_G(); |
@@ -276,16 +273,6 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
276 | man_path_list = add_MANPATH(NULL, &count_mp, | 273 | man_path_list = add_MANPATH(NULL, &count_mp, |
277 | getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */ | 274 | getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */ |
278 | ); | 275 | ); |
279 | if (!man_path_list) { | ||
280 | /* default, may be overridden by /etc/man.conf */ | ||
281 | man_path_list = xzalloc(2 * sizeof(man_path_list[0])); | ||
282 | man_path_list[0] = (char*)"/usr/man"; | ||
283 | /* count_mp stays 0. | ||
284 | * Thus, man.conf will overwrite man_path_list[0] | ||
285 | * if a path is defined there. | ||
286 | */ | ||
287 | } | ||
288 | |||
289 | /* Parse man.conf[ig] or man_db.conf */ | 276 | /* Parse man.conf[ig] or man_db.conf */ |
290 | /* man version 1.6f uses man.config */ | 277 | /* man version 1.6f uses man.config */ |
291 | /* man-db implementation of man uses man_db.conf */ | 278 | /* man-db implementation of man uses man_db.conf */ |
@@ -299,7 +286,7 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
299 | if (!token[1]) | 286 | if (!token[1]) |
300 | continue; | 287 | continue; |
301 | if (strcmp("DEFINE", token[0]) == 0) { | 288 | if (strcmp("DEFINE", token[0]) == 0) { |
302 | G.col = if_redefined(G.tbl , "col", token[1]); | 289 | G.col = if_redefined(G.col , "col", token[1]); |
303 | G.tbl = if_redefined(G.tbl , "tbl", token[1]); | 290 | G.tbl = if_redefined(G.tbl , "tbl", token[1]); |
304 | G.nroff = if_redefined(G.nroff, "nroff", token[1]); | 291 | G.nroff = if_redefined(G.nroff, "nroff", token[1]); |
305 | G.pager = if_redefined(G.pager, "pager", token[1]); | 292 | G.pager = if_redefined(G.pager, "pager", token[1]); |
@@ -317,17 +304,22 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
317 | config_close(parser); | 304 | config_close(parser); |
318 | 305 | ||
319 | #if ENABLE_PLATFORM_MINGW32 | 306 | #if ENABLE_PLATFORM_MINGW32 |
320 | { | 307 | /* allow man pages to be stored relative to the executable */ |
321 | char *exepath = xstrdup(bb_busybox_exec_path); | 308 | exepath = xstrdup(bb_busybox_exec_path); |
322 | char *relpath = concat_path_file(dirname(exepath), "man"); | 309 | relpath = concat_path_file(dirname(exepath), "man"); |
323 | if (count_mp == 0) { | 310 | |
324 | /* default must match path set above */ | 311 | if (!man_path_list) { |
325 | man_path_list = add_MANPATH(man_path_list, &count_mp, | 312 | mpl[2] = relpath; |
326 | (char *)"/usr/man"); | 313 | man_path_list = (char**)mpl; |
327 | } | 314 | } |
315 | else { | ||
328 | man_path_list = add_MANPATH(man_path_list, &count_mp, relpath); | 316 | man_path_list = add_MANPATH(man_path_list, &count_mp, relpath); |
329 | free(relpath); | 317 | } |
330 | free(exepath); | 318 | #else |
319 | if (!man_path_list) { | ||
320 | static const char *const mpl[] = { "/usr/man", "/usr/share/man", NULL }; | ||
321 | man_path_list = (char**)mpl; | ||
322 | /*count_mp = 2; - not used below anyway */ | ||
331 | } | 323 | } |
332 | #endif | 324 | #endif |
333 | 325 | ||
@@ -347,16 +339,18 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
347 | 339 | ||
348 | not_found = 0; | 340 | not_found = 0; |
349 | do { /* for each argv[] */ | 341 | do { /* for each argv[] */ |
342 | const char *cur_path; | ||
343 | int cur_mp; | ||
350 | int found = 0; | 344 | int found = 0; |
351 | cur_mp = 0; | ||
352 | 345 | ||
353 | if (strchr(*argv, '/')) { | 346 | if (strchr(*argv, '/')) { |
354 | found = show_manpage(*argv, /*man:*/ 1, 0); | 347 | found = show_manpage(*argv, /*man:*/ 1, 0); |
355 | goto check_found; | 348 | goto check_found; |
356 | } | 349 | } |
350 | cur_mp = 0; | ||
357 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { | 351 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { |
358 | /* for each MANPATH */ | 352 | /* for each MANPATH */ |
359 | cur_sect = sec_list; | 353 | const char *cur_sect = sec_list; |
360 | do { /* for each section */ | 354 | do { /* for each section */ |
361 | char *next_sect = strchrnul(cur_sect, ':'); | 355 | char *next_sect = strchrnul(cur_sect, ':'); |
362 | int sect_len = next_sect - cur_sect; | 356 | int sect_len = next_sect - cur_sect; |
diff --git a/miscutils/ts.c b/miscutils/ts.c new file mode 100644 index 000000000..f2d367654 --- /dev/null +++ b/miscutils/ts.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Copyright (C) 2019 Denys Vlasenko <vda.linux@googlemail.com> | ||
4 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
5 | */ | ||
6 | //config:config TS | ||
7 | //config: bool "ts (450 bytes)" | ||
8 | //config: default y | ||
9 | |||
10 | //applet:IF_TS(APPLET(ts, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
11 | |||
12 | //kbuild:lib-$(CONFIG_TS) += ts.o | ||
13 | |||
14 | //usage:#define ts_trivial_usage | ||
15 | //usage: "[-is] [STRFTIME]" | ||
16 | //usage:#define ts_full_usage "" | ||
17 | |||
18 | #include "libbb.h" | ||
19 | #include "common_bufsiz.h" | ||
20 | |||
21 | int ts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
22 | int ts_main(int argc UNUSED_PARAM, char **argv) | ||
23 | { | ||
24 | struct timeval base; | ||
25 | unsigned opt; | ||
26 | char *frac; | ||
27 | char *fmt_dt2str; | ||
28 | char *line; | ||
29 | |||
30 | opt = getopt32(argv, "^" "is" "\0" "?1" /*max one arg*/); | ||
31 | if (opt) { | ||
32 | putenv((char*)"TZ=UTC0"); | ||
33 | tzset(); | ||
34 | } | ||
35 | /*argc -= optind;*/ | ||
36 | argv += optind; | ||
37 | fmt_dt2str = argv[0] ? argv[0] | ||
38 | : (char*)(opt ? "%b %d %H:%M:%S"+6 : "%b %d %H:%M:%S"); | ||
39 | frac = is_suffixed_with(fmt_dt2str, "%.S"); | ||
40 | if (!frac) | ||
41 | frac = is_suffixed_with(fmt_dt2str, "%.s"); | ||
42 | if (frac) { | ||
43 | frac++; | ||
44 | frac[0] = frac[1]; | ||
45 | frac[1] = '\0'; | ||
46 | } | ||
47 | |||
48 | #define date_buf bb_common_bufsiz1 | ||
49 | setup_common_bufsiz(); | ||
50 | gettimeofday(&base, NULL); | ||
51 | |||
52 | while ((line = xmalloc_fgets(stdin)) != NULL) { | ||
53 | struct timeval ts; | ||
54 | struct tm tm_time; | ||
55 | |||
56 | gettimeofday(&ts, NULL); | ||
57 | if (opt) { | ||
58 | /* -i and/or -s */ | ||
59 | struct timeval ts1 = ts1; | ||
60 | if (opt & 1) /* -i */ | ||
61 | ts1 = ts; | ||
62 | //printf("%d %d\n", ts.tv_sec, base.tv_sec); | ||
63 | ts.tv_sec -= base.tv_sec; | ||
64 | //printf("%d %d\n", ts.tv_sec, base.tv_sec); | ||
65 | ts.tv_usec -= base.tv_usec; | ||
66 | if ((int32_t)(ts.tv_usec) < 0) { | ||
67 | ts.tv_sec--; | ||
68 | ts.tv_usec += 1000*1000; | ||
69 | } | ||
70 | if (opt & 1) /* -i */ | ||
71 | base = ts1; | ||
72 | } | ||
73 | localtime_r(&ts.tv_sec, &tm_time); | ||
74 | strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time); | ||
75 | if (!frac) { | ||
76 | printf("%s %s", date_buf, line); | ||
77 | } else { | ||
78 | printf("%s.%06u %s", date_buf, (unsigned)ts.tv_usec, line); | ||
79 | } | ||
80 | free(line); | ||
81 | } | ||
82 | |||
83 | return EXIT_SUCCESS; | ||
84 | } | ||
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index 1e9ecc5e8..86600b72f 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c | |||
@@ -64,7 +64,7 @@ static void shutdown_watchdog(void) | |||
64 | 64 | ||
65 | static void shutdown_on_signal(int sig UNUSED_PARAM) | 65 | static void shutdown_on_signal(int sig UNUSED_PARAM) |
66 | { | 66 | { |
67 | remove_pidfile(CONFIG_PID_FILE_PATH "/watchdog.pid"); | 67 | remove_pidfile_std_path_and_ext("watchdog"); |
68 | shutdown_watchdog(); | 68 | shutdown_watchdog(); |
69 | _exit(EXIT_SUCCESS); | 69 | _exit(EXIT_SUCCESS); |
70 | } | 70 | } |
@@ -136,7 +136,7 @@ int watchdog_main(int argc UNUSED_PARAM, char **argv) | |||
136 | stimer_duration, htimer_duration * 1000); | 136 | stimer_duration, htimer_duration * 1000); |
137 | #endif | 137 | #endif |
138 | 138 | ||
139 | write_pidfile(CONFIG_PID_FILE_PATH "/watchdog.pid"); | 139 | write_pidfile_std_path_and_ext("watchdog"); |
140 | 140 | ||
141 | while (1) { | 141 | while (1) { |
142 | /* | 142 | /* |