From db5546ca101846f18294a43b39883bc4ff53613a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 5 Jan 2022 22:16:06 +0100 Subject: 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 --- debianutils/start_stop_daemon.c | 4 ++-- findutils/grep.c | 2 +- include/libbb.h | 2 ++ init/init.c | 6 +++--- libbb/vfork_daemon_rexec.c | 4 ++-- libbb/xfuncs.c | 10 ++++++++++ loginutils/getty.c | 6 +++--- loginutils/login.c | 2 +- miscutils/devfsd.c | 4 ++-- miscutils/hdparm.c | 2 +- miscutils/i2c_tools.c | 2 +- miscutils/less.c | 4 ++-- miscutils/watchdog.c | 2 +- modutils/modprobe-small.c | 2 +- networking/arping.c | 2 +- networking/inetd.c | 2 +- networking/nc.c | 2 +- networking/telnetd.c | 2 +- runit/runsv.c | 2 +- shell/ash.c | 2 +- shell/hush.c | 4 ++-- util-linux/fdisk.c | 4 ++-- util-linux/fdisk_osf.c | 4 ++-- util-linux/fsck_minix.c | 2 +- 24 files changed, 45 insertions(+), 33 deletions(-) diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 68df44a..3e5dd9f 100644 --- a/debianutils/start_stop_daemon.c +++ b/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 */ diff --git a/findutils/grep.c b/findutils/grep.c index 8600d72..0b72812 100644 --- a/findutils/grep.c +++ b/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) { diff --git a/include/libbb.h b/include/libbb.h index 8308d62..c93058f 100644 --- a/include/libbb.h +++ b/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. * diff --git a/init/init.c b/init/init.c index efab5dc..785a3b4 100644 --- a/init/init.c +++ b/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 diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 31e9705..7914193 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/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) { diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index c40dcb7..465e536 100644 --- a/libbb/xfuncs.c +++ b/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); +} diff --git a/loginutils/getty.c b/loginutils/getty.c index 6c6d409..cd6378d 100644 --- a/loginutils/getty.c +++ b/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) diff --git a/loginutils/login.c b/loginutils/login.c index ce87e31..569053c 100644 --- a/loginutils/login.c +++ b/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; diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index e5bb8a2..839d00f 100644 --- a/miscutils/devfsd.c +++ b/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; diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 01b4e8e..d8d8f61 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -1271,7 +1271,7 @@ static void identify(uint16_t *val) } } - exit(EXIT_SUCCESS); + exit_SUCCESS(); } #endif diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index b25d497..e3741ee 100644 --- a/miscutils/i2c_tools.c +++ b/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) diff --git a/miscutils/less.c b/miscutils/less.c index 6825e55..82c4b21 100644 --- a/miscutils/less.c +++ b/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) \ diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index d8e9c78..9f5a4b8 100644 --- a/miscutils/watchdog.c +++ b/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) diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index db44a2e..b616516 100644 --- a/modutils/modprobe-small.c +++ b/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(); } } diff --git a/networking/arping.c b/networking/arping.c index d44d7d6..86f0221 100644 --- a/networking/arping.c +++ b/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); } diff --git a/networking/inetd.c b/networking/inetd.c index e5352a5..e71be51 100644 --- a/networking/inetd.c +++ b/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; diff --git a/networking/nc.c b/networking/nc.c index d351bf7..ab13163 100644 --- a/networking/nc.c +++ b/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) { diff --git a/networking/telnetd.c b/networking/telnetd.c index 581da19..0805e46 100644 --- a/networking/telnetd.c +++ b/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; diff --git a/runit/runsv.c b/runit/runsv.c index a4b8af4..6ad6bf4 100644 --- a/runit/runsv.c +++ b/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]); */ diff --git a/shell/ash.c b/shell/ash.c index 8276438..4a8ec0c 100644 --- a/shell/ash.c +++ b/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]); diff --git a/shell/hush.c b/shell/hush.c index 6a27b16..982fc35 100644 --- a/shell/hush.c +++ b/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 diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 1c2a7d6..9c393b8 100644 --- a/util-linux/fdisk.c +++ b/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': diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 765740f..6c66c13 100644 --- a/util-linux/fdisk_osf.c +++ b/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': diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index 40b86d0..dd2265c 100644 --- a/util-linux/fsck_minix.c +++ b/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(); } } } -- cgit v1.1