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

function                                             old     new   delta
exit_FAILURE                                           -       7      +7
_exit_FAILURE                                          -       7      +7
run                                                  198     199      +1
restore_state_and_exit                               114     115      +1
xbsd_write_bootstrap                                 399     397      -2
vfork_compressor                                     209     207      -2
sig_handler                                           12      10      -2
serial_ctl                                           154     152      -2
parse_args                                          1169    1167      -2
onintr                                                21      19      -2
make_new_session                                     493     491      -2
login_main                                           988     986      -2
gotsig                                                35      33      -2
do_iplink                                           1315    1313      -2
addgroup_main                                        397     395      -2
inetd_main                                          1911    1908      -3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/12 up/down: 16/-25)            Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
master
Denys Vlasenko 2023-06-15 11:55:56 +02:00
parent 61a4959251
commit 648f506949
21 changed files with 40 additions and 27 deletions

View File

@ -20,5 +20,5 @@ int main(int argc, char **argv)
void bb_show_usage(void)
{
fputs_stdout(APPLET_full_usage "\n");
exit(EXIT_FAILURE);
exit_FAILURE();
}

View File

@ -621,7 +621,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
execlp(gzip, gzip, "-f", (char *)0);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
/* parent */

View File

@ -45,7 +45,7 @@ static void
onintr(int sig UNUSED_PARAM)
{
tcsetattr(STDERR_FILENO, TCSANOW, old_termios_p);
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;

View File

@ -800,7 +800,7 @@ void bb_show_usage(void)
{
fprintf(stderr, "Usage: %s [-p] [-r] [-t] -[x] [-n max_arg] [-s max_chars]\n",
applet_name);
exit(EXIT_FAILURE);
exit_FAILURE();
}
int main(int argc, char **argv)

View File

@ -1281,6 +1281,8 @@ void set_task_comm(const char *comm) FAST_FUNC;
#endif
void exit_SUCCESS(void) NORETURN FAST_FUNC;
void _exit_SUCCESS(void) NORETURN FAST_FUNC;
void exit_FAILURE(void) NORETURN FAST_FUNC;
void _exit_FAILURE(void) NORETURN FAST_FUNC;
/* Helpers for daemonization.
*

View File

@ -500,7 +500,7 @@ static pid_t run(const struct init_action *a)
/* Open the new terminal device */
if (!open_stdio_to_tty(a->terminal))
_exit(EXIT_FAILURE);
_exit_FAILURE();
/* NB: on NOMMU we can't wait for input in child, so
* "askfirst" will work the same as "respawn". */

View File

@ -433,3 +433,13 @@ void FAST_FUNC _exit_SUCCESS(void)
{
_exit(EXIT_SUCCESS);
}
void FAST_FUNC exit_FAILURE(void)
{
exit(EXIT_FAILURE);
}
void FAST_FUNC _exit_FAILURE(void)
{
_exit(EXIT_FAILURE);
}

View File

@ -102,7 +102,7 @@ static void new_group(char *group, gid_t gid)
/* add entry to group */
p = xasprintf("x:%u:", (unsigned) gr.gr_gid);
if (update_passwd(bb_path_group_file, group, p, NULL) < 0)
exit(EXIT_FAILURE);
exit_FAILURE();
if (ENABLE_FEATURE_CLEAN_UP)
free(p);
#if ENABLE_FEATURE_SHADOWPASSWDS

View File

@ -173,7 +173,7 @@ static void die_if_nologin(void)
fflush_all();
/* Users say that they do need this prior to exit: */
tcdrain(STDOUT_FILENO);
exit(EXIT_FAILURE);
exit_FAILURE();
}
#else
# define die_if_nologin() ((void)0)
@ -265,19 +265,19 @@ static void get_username_or_die(char *buf, int size_buf)
do {
c = getchar();
if (c == EOF)
exit(EXIT_FAILURE);
exit_FAILURE();
if (c == '\n') {
if (!--cntdown)
exit(EXIT_FAILURE);
exit_FAILURE();
goto prompt;
}
} while (isspace(c)); /* maybe isblank? */
*buf++ = c;
if (!fgets(buf, size_buf-2, stdin))
exit(EXIT_FAILURE);
exit_FAILURE();
if (!strchr(buf, '\n'))
exit(EXIT_FAILURE);
exit_FAILURE();
while ((unsigned char)*buf > ' ')
buf++;
*buf = '\0';

View File

@ -354,10 +354,10 @@ static const char bb_msg_variable_not_found[] ALIGN1 = "variable: %s not found";
#define simple_info_logger(p, msg)
#define msg_logger(p, fmt, args...)
#define simple_msg_logger(p, msg)
#define msg_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE)
#define simple_msg_logger_and_die(p, msg) exit(EXIT_FAILURE)
#define msg_logger_and_die(p, fmt, args...) exit_FAILURE()
#define simple_msg_logger_and_die(p, msg) exit_FAILURE()
#define error_logger(p, fmt, args...)
#define error_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE)
#define error_logger_and_die(p, fmt, args...) exit_FAILURE()
#endif
static void safe_memcpy(char *dest, const char *src, int len)

View File

@ -535,7 +535,7 @@ static int serial_ctl(int fd, int ops, struct serial_struct *serinfo)
bb_simple_perror_msg(err);
if (ops & CTL_NODIE)
goto nodie;
exit(EXIT_FAILURE);
exit_FAILURE();
}
static void print_flag(const char **prefix, const char *flag)

View File

@ -1449,7 +1449,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
else
sep->se_builtin->bi_dgram_fn(ctrl, sep);
if (pid) /* we did fork */
_exit(EXIT_FAILURE);
_exit_FAILURE();
maybe_close(accepted_fd);
continue; /* -> check next fd in fd set */
}
@ -1530,7 +1530,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
/* eat packet in udp case */
if (sep->se_socktype != SOCK_STREAM)
recv(0, line, LINE_SIZE, MSG_DONTWAIT);
_exit(EXIT_FAILURE);
_exit_FAILURE();
} /* for (sep = servtab...) */
} /* for (;;) */
}

View File

@ -215,7 +215,7 @@ static void parse_address(char *dev, int hatype, int halen, char *lla, struct if
alen = hatype == 1/*ARPHRD_ETHER*/ ? 14/*ETH_HLEN*/ : 19/*INFINIBAND_HLEN*/;
alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), alen, lla);
if (alen < 0)
exit(EXIT_FAILURE);
exit_FAILURE();
if (alen != halen) {
bb_error_msg_and_die("wrong address (%s) length: expected %d bytes", lla, halen);
}

View File

@ -319,7 +319,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p)
struct ip_tunnel_parm old_p;
memset(&old_p, 0, sizeof(old_p));
if (do_get_ioctl(*argv, &old_p))
exit(EXIT_FAILURE);
exit_FAILURE();
*p = old_p;
}
}

View File

@ -247,7 +247,7 @@ struct globals {
static void noresp(int ign UNUSED_PARAM)
{
printf("No response from %s\n", G.hostname);
exit(EXIT_FAILURE);
exit_FAILURE();
}
static void ping4(len_and_sockaddr *lsa)

View File

@ -80,7 +80,7 @@ static void restore_state_and_exit(int exitcode)
/* Restore line status */
if (tcsetattr_serial_or_warn(&G.saved_state))
exit(EXIT_FAILURE);
exit_FAILURE();
if (ENABLE_FEATURE_CLEAN_UP)
close(serial_fd);

View File

@ -571,7 +571,7 @@ make_new_session(
BB_EXECVP(G.loginpath, (char **)login_argv);
/* _exit is safer with vfork, and we shouldn't send message
* to remote clients anyway */
_exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", G.loginpath);*/
_exit_FAILURE(); /*bb_perror_msg_and_die("execv %s", G.loginpath);*/
}
#if ENABLE_FEATURE_TELNETD_STANDALONE

View File

@ -109,7 +109,7 @@ static void reset_term(void)
static void sig_handler(int signo UNUSED_PARAM)
{
reset_term();
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
#endif

View File

@ -687,7 +687,7 @@ int setfiles_main(int argc UNUSED_PARAM, char **argv)
bb_simple_perror_msg_and_die(argv[0]);
}
if (nerr)
exit(EXIT_FAILURE);
exit_FAILURE();
argv++;
}

View File

@ -746,11 +746,12 @@ xbsd_write_bootstrap(void)
return;
e = d + sizeof(struct xbsd_disklabel);
for (p = d; p < e; p++)
for (p = d; p < e; p++) {
if (*p) {
printf("Bootstrap overlaps with disk label!\n");
exit(EXIT_FAILURE);
exit_FAILURE();
}
}
memmove(d, &dl, sizeof(struct xbsd_disklabel));

View File

@ -65,7 +65,7 @@ static void gotsig(int sig UNUSED_PARAM)
* therefore it is safe in signal handler */
bb_putchar_stderr('\n');
tcsetattr_tty_TCSANOW(&G.initial_settings);
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
#define CONVERTED_TAB_SIZE 8