Browse Source

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>
Denys Vlasenko 5 years ago
parent
commit
5059653882
8 changed files with 33 additions and 11 deletions
  1. 4 0
      include/libbb.h
  2. 18 0
      libbb/pidfile.c
  3. 1 1
      miscutils/crond.c
  4. 2 2
      miscutils/watchdog.c
  5. 2 2
      networking/inetd.c
  6. 2 2
      networking/ntpd.c
  7. 2 2
      sysklogd/klogd.c
  8. 2 2
      sysklogd/syslogd.c

+ 4 - 0
include/libbb.h

@@ -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

+ 18 - 0
libbb/pidfile.c

@@ -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);
+}

+ 1 - 1
miscutils/crond.c

@@ -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 */

+ 2 - 2
miscutils/watchdog.c

@@ -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) {
 		/*

+ 2 - 2
networking/inetd.c

@@ -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);

+ 2 - 2
networking/ntpd.c

@@ -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);
 }
 

+ 2 - 2
sysklogd/klogd.c

@@ -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;

+ 2 - 2
sysklogd/syslogd.c

@@ -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; */