do not duplicate CONFIG_PID_FILE_PATH and ".pid" strings
No binary (build failed)
—
(log yok)
| @@ -1298,9 +1298,13 @@ llist_t *llist_find_str(llist_t *first, const char *str) FAST_FUNC; | |
| /* True only if we created pidfile which is *file*, not /dev/null etc */ | |
| extern smallint wrote_pidfile; | |
| void write_pidfile(const char *path) FAST_FUNC; | |
| + | void write_pidfile_std_path_and_ext(const char *path) FAST_FUNC; |
| + | void remove_pidfile_std_path_and_ext(const char *path) FAST_FUNC; |
| #define remove_pidfile(path) do { if (wrote_pidfile) unlink(path); } while (0) | |
| #else | |
| enum { wrote_pidfile = 0 }; | |
| + | #define write_pidfile_std_path_and_ext(path) ((void)0) |
| + | #define remove_pidfile_std_path_and_ext(path) ((void)0) |
| #define write_pidfile(path) ((void)0) | |
| #define remove_pidfile(path) ((void)0) | |
| #endif | |
| @@ -38,3 +38,21 @@ void FAST_FUNC write_pidfile(const char *path) | |
| } | |
| close(pid_fd); | |
| } | |
| + | |
| + | void FAST_FUNC write_pidfile_std_path_and_ext(const char *name) |
| + | { |
| + | char buf[sizeof(CONFIG_PID_FILE_PATH) + 64]; |
| + | |
| + | snprintf(buf, sizeof(buf), CONFIG_PID_FILE_PATH"/%s.pid", name); |
| + | write_pidfile(buf); |
| + | } |
| + | |
| + | void FAST_FUNC remove_pidfile_std_path_and_ext(const char *name) |
| + | { |
| + | char buf[sizeof(CONFIG_PID_FILE_PATH) + 64]; |
| + | |
| + | if (!wrote_pidfile) |
| + | return; |
| + | snprintf(buf, sizeof(buf), CONFIG_PID_FILE_PATH"/%s.pid", name); |
| + | unlink(buf); |
| + | } |
| @@ -1056,7 +1056,7 @@ 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"); |
| + | write_pidfile_std_path_and_ext("crond"); |
| #if ENABLE_FEATURE_CROND_SPECIAL_TIMES | |
| if (touch_reboot_file()) | |
| start_jobs(START_ME_REBOOT); /* start @reboot entries, if any */ | |
| @@ -64,7 +64,7 @@ static void shutdown_watchdog(void) | |
| static void shutdown_on_signal(int sig UNUSED_PARAM) | |
| { | |
| - | remove_pidfile(CONFIG_PID_FILE_PATH "/watchdog.pid"); |
| + | remove_pidfile_std_path_and_ext("watchdog"); |
| shutdown_watchdog(); | |
| _exit(EXIT_SUCCESS); | |
| } | |
| @@ -136,7 +136,7 @@ int watchdog_main(int argc UNUSED_PARAM, char **argv) | |
| stimer_duration, htimer_duration * 1000); | |
| #endif | |
| - | write_pidfile(CONFIG_PID_FILE_PATH "/watchdog.pid"); |
| + | write_pidfile_std_path_and_ext("watchdog"); |
| while (1) { | |
| /* | |
| @@ -1207,7 +1207,7 @@ static void clean_up_and_exit(int sig UNUSED_PARAM) | |
| if (ENABLE_FEATURE_CLEAN_UP) | |
| close(sep->se_fd); | |
| } | |
| - | remove_pidfile(CONFIG_PID_FILE_PATH "/inetd.pid"); |
| + | remove_pidfile_std_path_and_ext("inetd"); |
| exit(EXIT_SUCCESS); | |
| } | |
| @@ -1256,7 +1256,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |
| setgroups(1, &gid); | |
| } | |
| - | write_pidfile(CONFIG_PID_FILE_PATH "/inetd.pid"); |
| + | write_pidfile_std_path_and_ext("inetd"); |
| /* never fails under Linux (except if you pass it bad arguments) */ | |
| getrlimit(RLIMIT_NOFILE, &rlim_ofile); | |
| @@ -2641,7 +2641,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |
| */ | |
| cnt = G.peer_cnt * (INITIAL_SAMPLES + 1); | |
| - | write_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); |
| + | write_pidfile_std_path_and_ext("ntpd"); |
| while (!bb_got_signal) { | |
| llist_t *item; | |
| @@ -2814,7 +2814,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |
| } | |
| } /* while (!bb_got_signal) */ | |
| - | remove_pidfile(CONFIG_PID_FILE_PATH "/ntpd.pid"); |
| + | remove_pidfile_std_path_and_ext("ntpd"); |
| kill_myself_with_sig(bb_got_signal); | |
| } | |
| @@ -231,7 +231,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |
| syslog(LOG_NOTICE, "klogd started: %s", bb_banner); | |
| - | write_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); |
| + | write_pidfile_std_path_and_ext("klogd"); |
| used = 0; | |
| while (!bb_got_signal) { | |
| @@ -295,7 +295,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |
| klogd_close(); | |
| syslog(LOG_NOTICE, "klogd: exiting"); | |
| - | remove_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); |
| + | remove_pidfile_std_path_and_ext("klogd"); |
| if (bb_got_signal) | |
| kill_myself_with_sig(bb_got_signal); | |
| return EXIT_FAILURE; | |
| @@ -1098,7 +1098,7 @@ static void do_syslogd(void) | |
| } /* while (!bb_got_signal) */ | |
| timestamp_and_log_internal("syslogd exiting"); | |
| - | remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); |
| + | remove_pidfile_std_path_and_ext("syslogd"); |
| ipcsyslog_cleanup(); | |
| if (option_mask32 & OPT_kmsg) | |
| kmsg_cleanup(); | |
| @@ -1164,7 +1164,7 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv) | |
| } | |
| //umask(0); - why?? | |
| - | write_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); |
| + | write_pidfile_std_path_and_ext("syslogd"); |
| do_syslogd(); | |
| /* return EXIT_SUCCESS; */ | |