diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-03-17 19:47:52 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-03-17 19:48:39 +0100 |
commit | 5059653882dbd86e3bbf48389f9f81b0fac8cd0a (patch) | |
tree | c485a272add5b3a684f9ac97aad69a7c07aadb85 | |
parent | 2bbd1e1e8ababc480ff5d373847ab98ba0cc23dd (diff) | |
download | busybox-w32-5059653882dbd86e3bbf48389f9f81b0fac8cd0a.tar.gz busybox-w32-5059653882dbd86e3bbf48389f9f81b0fac8cd0a.tar.bz2 busybox-w32-5059653882dbd86e3bbf48389f9f81b0fac8cd0a.zip |
do not duplicate CONFIG_PID_FILE_PATH and ".pid" strings
text data bss dec hex filename
981737 485 7296 989518 f194e busybox_old
981704 485 7296 989485 f192d busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/pidfile.c | 18 | ||||
-rw-r--r-- | miscutils/crond.c | 2 | ||||
-rw-r--r-- | miscutils/watchdog.c | 4 | ||||
-rw-r--r-- | networking/inetd.c | 4 | ||||
-rw-r--r-- | networking/ntpd.c | 4 | ||||
-rw-r--r-- | sysklogd/klogd.c | 4 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 4 |
8 files changed, 33 insertions, 11 deletions
diff --git a/include/libbb.h b/include/libbb.h index 7a1e13875..e0d5521e4 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1298,9 +1298,13 @@ llist_t *llist_find_str(llist_t *first, const char *str) FAST_FUNC; | |||
1298 | /* True only if we created pidfile which is *file*, not /dev/null etc */ | 1298 | /* True only if we created pidfile which is *file*, not /dev/null etc */ |
1299 | extern smallint wrote_pidfile; | 1299 | extern smallint wrote_pidfile; |
1300 | void write_pidfile(const char *path) FAST_FUNC; | 1300 | void write_pidfile(const char *path) FAST_FUNC; |
1301 | void write_pidfile_std_path_and_ext(const char *path) FAST_FUNC; | ||
1302 | void remove_pidfile_std_path_and_ext(const char *path) FAST_FUNC; | ||
1301 | #define remove_pidfile(path) do { if (wrote_pidfile) unlink(path); } while (0) | 1303 | #define remove_pidfile(path) do { if (wrote_pidfile) unlink(path); } while (0) |
1302 | #else | 1304 | #else |
1303 | enum { wrote_pidfile = 0 }; | 1305 | enum { wrote_pidfile = 0 }; |
1306 | #define write_pidfile_std_path_and_ext(path) ((void)0) | ||
1307 | #define remove_pidfile_std_path_and_ext(path) ((void)0) | ||
1304 | #define write_pidfile(path) ((void)0) | 1308 | #define write_pidfile(path) ((void)0) |
1305 | #define remove_pidfile(path) ((void)0) | 1309 | #define remove_pidfile(path) ((void)0) |
1306 | #endif | 1310 | #endif |
diff --git a/libbb/pidfile.c b/libbb/pidfile.c index a48dfc38b..a6a282562 100644 --- a/libbb/pidfile.c +++ b/libbb/pidfile.c | |||
@@ -38,3 +38,21 @@ void FAST_FUNC write_pidfile(const char *path) | |||
38 | } | 38 | } |
39 | close(pid_fd); | 39 | close(pid_fd); |
40 | } | 40 | } |
41 | |||
42 | void FAST_FUNC write_pidfile_std_path_and_ext(const char *name) | ||
43 | { | ||
44 | char buf[sizeof(CONFIG_PID_FILE_PATH) + 64]; | ||
45 | |||
46 | snprintf(buf, sizeof(buf), CONFIG_PID_FILE_PATH"/%s.pid", name); | ||
47 | write_pidfile(buf); | ||
48 | } | ||
49 | |||
50 | void FAST_FUNC remove_pidfile_std_path_and_ext(const char *name) | ||
51 | { | ||
52 | char buf[sizeof(CONFIG_PID_FILE_PATH) + 64]; | ||
53 | |||
54 | if (!wrote_pidfile) | ||
55 | return; | ||
56 | snprintf(buf, sizeof(buf), CONFIG_PID_FILE_PATH"/%s.pid", name); | ||
57 | unlink(buf); | ||
58 | } | ||
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/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 | /* |
diff --git a/networking/inetd.c b/networking/inetd.c index 8f871ee12..da6551174 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1207,7 +1207,7 @@ static void clean_up_and_exit(int sig UNUSED_PARAM) | |||
1207 | if (ENABLE_FEATURE_CLEAN_UP) | 1207 | if (ENABLE_FEATURE_CLEAN_UP) |
1208 | close(sep->se_fd); | 1208 | close(sep->se_fd); |
1209 | } | 1209 | } |
1210 | remove_pidfile(CONFIG_PID_FILE_PATH "/inetd.pid"); | 1210 | remove_pidfile_std_path_and_ext("inetd"); |
1211 | exit(EXIT_SUCCESS); | 1211 | exit(EXIT_SUCCESS); |
1212 | } | 1212 | } |
1213 | 1213 | ||
@@ -1256,7 +1256,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1256 | setgroups(1, &gid); | 1256 | setgroups(1, &gid); |
1257 | } | 1257 | } |
1258 | 1258 | ||
1259 | write_pidfile(CONFIG_PID_FILE_PATH "/inetd.pid"); | 1259 | write_pidfile_std_path_and_ext("inetd"); |
1260 | 1260 | ||
1261 | /* never fails under Linux (except if you pass it bad arguments) */ | 1261 | /* never fails under Linux (except if you pass it bad arguments) */ |
1262 | getrlimit(RLIMIT_NOFILE, &rlim_ofile); | 1262 | getrlimit(RLIMIT_NOFILE, &rlim_ofile); |
diff --git a/networking/ntpd.c b/networking/ntpd.c index 0f474bc09..b2e77929e 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -2641,7 +2641,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
2641 | */ | 2641 | */ |
2642 | cnt = G.peer_cnt * (INITIAL_SAMPLES + 1); | 2642 | cnt = G.peer_cnt * (INITIAL_SAMPLES + 1); |
2643 | 2643 | ||
2644 | write_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); | 2644 | write_pidfile_std_path_and_ext("ntpd"); |
2645 | 2645 | ||
2646 | while (!bb_got_signal) { | 2646 | while (!bb_got_signal) { |
2647 | llist_t *item; | 2647 | llist_t *item; |
@@ -2814,7 +2814,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
2814 | } | 2814 | } |
2815 | } /* while (!bb_got_signal) */ | 2815 | } /* while (!bb_got_signal) */ |
2816 | 2816 | ||
2817 | remove_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); | 2817 | remove_pidfile_std_path_and_ext("ntpd"); |
2818 | kill_myself_with_sig(bb_got_signal); | 2818 | kill_myself_with_sig(bb_got_signal); |
2819 | } | 2819 | } |
2820 | 2820 | ||
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 76eccf1da..17b6ca235 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -231,7 +231,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
231 | 231 | ||
232 | syslog(LOG_NOTICE, "klogd started: %s", bb_banner); | 232 | syslog(LOG_NOTICE, "klogd started: %s", bb_banner); |
233 | 233 | ||
234 | write_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); | 234 | write_pidfile_std_path_and_ext("klogd"); |
235 | 235 | ||
236 | used = 0; | 236 | used = 0; |
237 | while (!bb_got_signal) { | 237 | while (!bb_got_signal) { |
@@ -295,7 +295,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
295 | 295 | ||
296 | klogd_close(); | 296 | klogd_close(); |
297 | syslog(LOG_NOTICE, "klogd: exiting"); | 297 | syslog(LOG_NOTICE, "klogd: exiting"); |
298 | remove_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); | 298 | remove_pidfile_std_path_and_ext("klogd"); |
299 | if (bb_got_signal) | 299 | if (bb_got_signal) |
300 | kill_myself_with_sig(bb_got_signal); | 300 | kill_myself_with_sig(bb_got_signal); |
301 | return EXIT_FAILURE; | 301 | return EXIT_FAILURE; |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index f12359476..d0dd1bd20 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -1098,7 +1098,7 @@ static void do_syslogd(void) | |||
1098 | } /* while (!bb_got_signal) */ | 1098 | } /* while (!bb_got_signal) */ |
1099 | 1099 | ||
1100 | timestamp_and_log_internal("syslogd exiting"); | 1100 | timestamp_and_log_internal("syslogd exiting"); |
1101 | remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); | 1101 | remove_pidfile_std_path_and_ext("syslogd"); |
1102 | ipcsyslog_cleanup(); | 1102 | ipcsyslog_cleanup(); |
1103 | if (option_mask32 & OPT_kmsg) | 1103 | if (option_mask32 & OPT_kmsg) |
1104 | kmsg_cleanup(); | 1104 | kmsg_cleanup(); |
@@ -1164,7 +1164,7 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv) | |||
1164 | } | 1164 | } |
1165 | 1165 | ||
1166 | //umask(0); - why?? | 1166 | //umask(0); - why?? |
1167 | write_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); | 1167 | write_pidfile_std_path_and_ext("syslogd"); |
1168 | 1168 | ||
1169 | do_syslogd(); | 1169 | do_syslogd(); |
1170 | /* return EXIT_SUCCESS; */ | 1170 | /* return EXIT_SUCCESS; */ |