Browse Source

libbb: code shrink: introduce and use [_]exit_SUCCESS()

function                                             old     new   delta
exit_SUCCESS                                           -       7      +7
_exit_SUCCESS                                          -       7      +7
run_pipe                                            1562    1567      +5
pseudo_exec_argv                                     399     400      +1
finish                                                86      87      +1
start_stop_daemon_main                              1109    1107      -2
shutdown_on_signal                                    38      36      -2
runsv_main                                          1662    1660      -2
redirect                                            1070    1068      -2
read_line                                             79      77      -2
pause_and_low_level_reboot                            54      52      -2
list_i2c_busses_and_exit                             483     481      -2
less_exit                                             12      10      -2
identify                                            4123    4121      -2
grep_file                                           1161    1159      -2
getty_main                                          1519    1517      -2
fsck_minix_main                                     2681    2679      -2
free_session                                         132     130      -2
fdisk_main                                          4739    4737      -2
clean_up_and_exit                                     53      51      -2
bsd_select                                          1566    1564      -2
bb_daemonize_or_rexec                                198     196      -2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/17 up/down: 21/-34)           Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko 2 years ago
parent
commit
db5546ca10

+ 2 - 2
debianutils/start_stop_daemon.c

@@ -519,7 +519,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
 			/* why _exit? the child may have changed the stack,
 			 * so "return 0" may do bad things
 			 */
-			_exit(EXIT_SUCCESS);
+			_exit_SUCCESS();
 		}
 		/* Child */
 		setsid(); /* detach from controlling tty */
@@ -531,7 +531,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
 		 */
 		pid = xvfork();
 		if (pid != 0)
-			_exit(EXIT_SUCCESS); /* Parent */
+			_exit_SUCCESS(); /* Parent */
 	}
 	if (opt & OPT_MAKEPID) {
 		/* User wants _us_ to make the pidfile */

+ 1 - 1
findutils/grep.c

@@ -470,7 +470,7 @@ static int grep_file(FILE *file)
 					 * "exit immediately with zero status
 					 * if any match is found,
 					 * even if errors were detected" */
-					exit(EXIT_SUCCESS);
+					exit_SUCCESS();
 				}
 				/* -l "print filenames with matches": stop after the first match */
 				if (option_mask32 & OPT_l) {

+ 2 - 0
include/libbb.h

@@ -1278,6 +1278,8 @@ void set_task_comm(const char *comm) FAST_FUNC;
 # define re_execed_comm() 0
 # define set_task_comm(name) ((void)0)
 #endif
+void exit_SUCCESS(void) NORETURN FAST_FUNC;
+void _exit_SUCCESS(void) NORETURN FAST_FUNC;
 
 /* Helpers for daemonization.
  *

+ 3 - 3
init/init.c

@@ -744,7 +744,7 @@ static void pause_and_low_level_reboot(unsigned magic)
 	pid = vfork();
 	if (pid == 0) { /* child */
 		reboot(magic);
-		_exit(EXIT_SUCCESS);
+		_exit_SUCCESS();
 	}
 	/* Used to have "while (1) sleep(1)" here.
 	 * However, in containers reboot() call is ignored, and with that loop
@@ -752,7 +752,7 @@ static void pause_and_low_level_reboot(unsigned magic)
 	 */
 	waitpid(pid, NULL, 0);
 	sleep1(); /* paranoia */
-	_exit(EXIT_SUCCESS);
+	_exit_SUCCESS();
 }
 
 static void run_shutdown_and_kill_processes(void)
@@ -942,7 +942,7 @@ static void reload_inittab(void)
 			for (a = G.init_action_list; a; a = a->next)
 				if (a->action_type == 0 && a->pid != 0)
 					kill(a->pid, SIGKILL);
-			_exit(EXIT_SUCCESS);
+			_exit_SUCCESS();
 		}
 	}
 #endif

+ 2 - 2
libbb/vfork_daemon_rexec.c

@@ -308,7 +308,7 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv)
 		/* fflush_all(); - add it in fork_or_rexec() if necessary */
 
 		if (fork_or_rexec(argv))
-			_exit(EXIT_SUCCESS); /* parent */
+			_exit_SUCCESS(); /* parent */
 		/* if daemonizing, detach from stdio & ctty */
 		setsid();
 		dup2(fd, 0);
@@ -320,7 +320,7 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv)
 //			 * Prevent this: stop being a session leader.
 //			 */
 //			if (fork_or_rexec(argv))
-//				_exit(EXIT_SUCCESS); /* parent */
+//				_exit_SUCCESS(); /* parent */
 //		}
 	}
 	while (fd > 2) {

+ 10 - 0
libbb/xfuncs.c

@@ -423,3 +423,13 @@ int FAST_FUNC wait4pid(pid_t pid)
 		return WTERMSIG(status) + 0x180;
 	return 0;
 }
+
+void FAST_FUNC exit_SUCCESS(void)
+{
+	exit(EXIT_SUCCESS);
+}
+
+void FAST_FUNC _exit_SUCCESS(void)
+{
+	_exit(EXIT_SUCCESS);
+}

+ 3 - 3
loginutils/getty.c

@@ -484,7 +484,7 @@ static char *get_logname(void)
 			if (read(STDIN_FILENO, &c, 1) < 1) {
 				finalize_tty_attrs();
 				if (errno == EINTR || errno == EIO)
-					exit(EXIT_SUCCESS);
+					exit_SUCCESS();
 				bb_simple_perror_msg_and_die(bb_msg_read_error);
 			}
 
@@ -511,7 +511,7 @@ static char *get_logname(void)
 			case CTL('C'):
 			case CTL('D'):
 				finalize_tty_attrs();
-				exit(EXIT_SUCCESS);
+				exit_SUCCESS();
 			case '\0':
 				/* BREAK. If we have speeds to try,
 				 * return NULL (will switch speeds and return here) */
@@ -538,7 +538,7 @@ static char *get_logname(void)
 static void alarm_handler(int sig UNUSED_PARAM)
 {
 	finalize_tty_attrs();
-	_exit(EXIT_SUCCESS);
+	_exit_SUCCESS();
 }
 
 static void sleep10(void)

+ 1 - 1
loginutils/login.c

@@ -312,7 +312,7 @@ static void alarm_handler(int sig UNUSED_PARAM)
 	/* unix API is brain damaged regarding O_NONBLOCK,
 	 * we should undo it, or else we can affect other processes */
 	ndelay_off(STDOUT_FILENO);
-	_exit(EXIT_SUCCESS);
+	_exit_SUCCESS();
 }
 
 int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;

+ 2 - 2
miscutils/devfsd.c

@@ -453,7 +453,7 @@ int devfsd_main(int argc, char **argv)
 				DEVFSD_PROTOCOL_REVISION_DAEMON, bb_msg_proto_rev, proto_rev);
 		if (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev)
 			bb_error_msg_and_die("%s mismatch!", bb_msg_proto_rev);
-		exit(EXIT_SUCCESS); /* -v */
+		exit_SUCCESS(); /* -v */
 	}
 	/*  Tell kernel we are special(i.e. we get to see hidden entries)  */
 	xioctl(fd, DEVFSDIOC_SET_EVENT_MASK, 0);
@@ -474,7 +474,7 @@ int devfsd_main(int argc, char **argv)
 	dir_operation(SERVICE, mount_point, 0, NULL);
 
 	if (ENABLE_DEVFSD_FG_NP && no_polling)
-		exit(EXIT_SUCCESS);
+		exit_SUCCESS();
 
 	if (ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG)
 		logmode = LOGMODE_BOTH;

+ 1 - 1
miscutils/hdparm.c

@@ -1271,7 +1271,7 @@ static void identify(uint16_t *val)
 		}
 	}
 
-	exit(EXIT_SUCCESS);
+	exit_SUCCESS();
 }
 #endif
 

+ 1 - 1
miscutils/i2c_tools.c

@@ -1212,7 +1212,7 @@ static void NORETURN list_i2c_busses_and_exit(void)
 		}
 	}
 
-	exit(EXIT_SUCCESS);
+	exit_SUCCESS();
 }
 
 static void NORETURN no_support(const char *cmd)

+ 2 - 2
miscutils/less.c

@@ -333,10 +333,10 @@ static void restore_tty(void)
 	clear_line();
 }
 
-static void less_exit(void)
+static NOINLINE void less_exit(void)
 {
 	restore_tty();
-	exit(EXIT_SUCCESS);
+	exit_SUCCESS();
 }
 
 #if (ENABLE_FEATURE_LESS_DASHCMD && ENABLE_FEATURE_LESS_LINENUMS) \

+ 1 - 1
miscutils/watchdog.c

@@ -76,7 +76,7 @@ static void shutdown_on_signal(int sig UNUSED_PARAM)
 {
 	remove_pidfile_std_path_and_ext("watchdog");
 	shutdown_watchdog();
-	_exit(EXIT_SUCCESS);
+	_exit_SUCCESS();
 }
 
 static void watchdog_open(const char* device)

+ 1 - 1
modutils/modprobe-small.c

@@ -415,7 +415,7 @@ static FAST_FUNC int fileAction(struct recursive_state *state,
 			/* Load was successful, there is nothing else to do.
 			 * This can happen ONLY for "top-level" module load,
 			 * not a dep, because deps don't do dirscan. */
-			exit(EXIT_SUCCESS);
+			exit_SUCCESS();
 		}
 	}
 

+ 1 - 1
networking/arping.c

@@ -159,7 +159,7 @@ static void finish(void)
 	if (option_mask32 & DAD)
 		exit(!!received);
 	if (option_mask32 & UNSOLICITED)
-		exit(EXIT_SUCCESS);
+		exit_SUCCESS();
 	exit(!received);
 }
 

+ 1 - 1
networking/inetd.c

@@ -1208,7 +1208,7 @@ static void clean_up_and_exit(int sig UNUSED_PARAM)
 			close(sep->se_fd);
 	}
 	remove_pidfile_std_path_and_ext("inetd");
-	exit(EXIT_SUCCESS);
+	exit_SUCCESS();
 }
 
 int inetd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;

+ 1 - 1
networking/nc.c

@@ -268,7 +268,7 @@ int nc_main(int argc, char **argv)
 				nread = safe_read(pfds[fdidx].fd, iobuf, COMMON_BUFSIZE);
 				if (fdidx != 0) {
 					if (nread < 1)
-						exit(EXIT_SUCCESS);
+						exit_SUCCESS();
 					ofd = STDOUT_FILENO;
 				} else {
 					if (nread < 1) {

+ 1 - 1
networking/telnetd.c

@@ -582,7 +582,7 @@ free_session(struct tsession *ts)
 	struct tsession *t;
 
 	if (option_mask32 & OPT_INETD)
-		exit(EXIT_SUCCESS);
+		exit_SUCCESS();
 
 	/* Unlink this telnet session from the session list */
 	t = G.sessions;

+ 1 - 1
runit/runsv.c

@@ -700,7 +700,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
 
 		if (svd[0].sd_want == W_EXIT && svd[0].state == S_DOWN) {
 			if (svd[1].pid == 0)
-				_exit(EXIT_SUCCESS);
+				_exit_SUCCESS();
 			if (svd[1].sd_want != W_EXIT) {
 				svd[1].sd_want = W_EXIT;
 				/* stopservice(&svd[1]); */

+ 1 - 1
shell/ash.c

@@ -5505,7 +5505,7 @@ openhere(union node *redir)
 		ignoresig(SIGTSTP); //signal(SIGTSTP, SIG_IGN);
 		signal(SIGPIPE, SIG_DFL);
 		xwrite(pip[1], p, len);
-		_exit(EXIT_SUCCESS);
+		_exit_SUCCESS();
 	}
  out:
 	close(pip[1]);

+ 2 - 2
shell/hush.c

@@ -8587,7 +8587,7 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
 		 * expand_assignments(): think about ... | var=`sleep 1` | ...
 		 */
 		free_strings(new_env);
-		_exit(EXIT_SUCCESS);
+		_exit_SUCCESS();
 	}
 
 	sv_shadowed = G.shadowed_vars_pp;
@@ -8768,7 +8768,7 @@ static void pseudo_exec(nommu_save_t *nommu_save,
 
 	/* Case when we are here: ... | >file */
 	debug_printf_exec("pseudo_exec'ed null command\n");
-	_exit(EXIT_SUCCESS);
+	_exit_SUCCESS();
 }
 
 #if ENABLE_HUSH_JOB

+ 2 - 2
util-linux/fdisk.c

@@ -665,7 +665,7 @@ read_line(const char *prompt)
 
 	sz = read_line_input(NULL, prompt, line_buffer, sizeof(line_buffer));
 	if (sz <= 0)
-		exit(EXIT_SUCCESS); /* Ctrl-D or Ctrl-C */
+		exit_SUCCESS(); /* Ctrl-D or Ctrl-C */
 
 	if (line_buffer[sz-1] == '\n')
 		line_buffer[--sz] = '\0';
@@ -2855,7 +2855,7 @@ xselect(void)
 			if (ENABLE_FEATURE_CLEAN_UP)
 				close_dev_fd();
 			bb_putchar('\n');
-			exit(EXIT_SUCCESS);
+			exit_SUCCESS();
 		case 'r':
 			return;
 		case 's':

+ 2 - 2
util-linux/fdisk_osf.c

@@ -383,7 +383,7 @@ bsd_select(void)
 
 	if (xbsd_readlabel(NULL) == 0)
 		if (xbsd_create_disklabel() == 0)
-			exit(EXIT_SUCCESS);
+			exit_SUCCESS();
 
 #endif
 
@@ -411,7 +411,7 @@ bsd_select(void)
 		case 'q':
 			if (ENABLE_FEATURE_CLEAN_UP)
 				close_dev_fd();
-			exit(EXIT_SUCCESS);
+			exit_SUCCESS();
 		case 'r':
 			return;
 		case 's':

+ 1 - 1
util-linux/fsck_minix.c

@@ -423,7 +423,7 @@ static void check_mount(void)
 			cont = ask("Do you really want to continue", 0);
 		if (!cont) {
 			puts("Check aborted");
-			exit(EXIT_SUCCESS);
+			exit_SUCCESS();
 		}
 	}
 }