diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-15 11:55:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-15 11:55:56 +0200 |
commit | 648f506949ded749e28186d0092b6e42085c897b (patch) | |
tree | 049c72bc8149f41fc617d00f7d32f1d6384f8e2f | |
parent | 61a4959251667751e424e600c6cb75de39d6b1c3 (diff) | |
download | busybox-w32-648f506949ded749e28186d0092b6e42085c897b.tar.gz busybox-w32-648f506949ded749e28186d0092b6e42085c897b.tar.bz2 busybox-w32-648f506949ded749e28186d0092b6e42085c897b.zip |
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>
-rw-r--r-- | applets/individual.c | 2 | ||||
-rw-r--r-- | archival/tar.c | 2 | ||||
-rw-r--r-- | console-tools/resize.c | 2 | ||||
-rw-r--r-- | findutils/xargs.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | init/init.c | 2 | ||||
-rw-r--r-- | libbb/xfuncs.c | 10 | ||||
-rw-r--r-- | loginutils/addgroup.c | 2 | ||||
-rw-r--r-- | loginutils/login.c | 10 | ||||
-rw-r--r-- | miscutils/devfsd.c | 6 | ||||
-rw-r--r-- | miscutils/setserial.c | 2 | ||||
-rw-r--r-- | networking/inetd.c | 4 | ||||
-rw-r--r-- | networking/libiproute/iplink.c | 2 | ||||
-rw-r--r-- | networking/libiproute/iptunnel.c | 2 | ||||
-rw-r--r-- | networking/ping.c | 2 | ||||
-rw-r--r-- | networking/slattach.c | 2 | ||||
-rw-r--r-- | networking/telnetd.c | 2 | ||||
-rw-r--r-- | procps/powertop.c | 2 | ||||
-rw-r--r-- | selinux/setfiles.c | 2 | ||||
-rw-r--r-- | util-linux/fdisk_osf.c | 5 | ||||
-rw-r--r-- | util-linux/more.c | 2 |
21 files changed, 40 insertions, 27 deletions
diff --git a/applets/individual.c b/applets/individual.c index e94f26c93..2f743d906 100644 --- a/applets/individual.c +++ b/applets/individual.c | |||
@@ -20,5 +20,5 @@ int main(int argc, char **argv) | |||
20 | void bb_show_usage(void) | 20 | void bb_show_usage(void) |
21 | { | 21 | { |
22 | fputs_stdout(APPLET_full_usage "\n"); | 22 | fputs_stdout(APPLET_full_usage "\n"); |
23 | exit(EXIT_FAILURE); | 23 | exit_FAILURE(); |
24 | } | 24 | } |
diff --git a/archival/tar.c b/archival/tar.c index 9de37592e..d6ca6c1e0 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -621,7 +621,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) | |||
621 | execlp(gzip, gzip, "-f", (char *)0); | 621 | execlp(gzip, gzip, "-f", (char *)0); |
622 | 622 | ||
623 | vfork_exec_errno = errno; | 623 | vfork_exec_errno = errno; |
624 | _exit(EXIT_FAILURE); | 624 | _exit_FAILURE(); |
625 | } | 625 | } |
626 | 626 | ||
627 | /* parent */ | 627 | /* parent */ |
diff --git a/console-tools/resize.c b/console-tools/resize.c index 056e33750..95e0c7bf9 100644 --- a/console-tools/resize.c +++ b/console-tools/resize.c | |||
@@ -45,7 +45,7 @@ static void | |||
45 | onintr(int sig UNUSED_PARAM) | 45 | onintr(int sig UNUSED_PARAM) |
46 | { | 46 | { |
47 | tcsetattr(STDERR_FILENO, TCSANOW, old_termios_p); | 47 | tcsetattr(STDERR_FILENO, TCSANOW, old_termios_p); |
48 | _exit(EXIT_FAILURE); | 48 | _exit_FAILURE(); |
49 | } | 49 | } |
50 | 50 | ||
51 | int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 51 | int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
diff --git a/findutils/xargs.c b/findutils/xargs.c index 067ef41c5..c6000e066 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -800,7 +800,7 @@ void bb_show_usage(void) | |||
800 | { | 800 | { |
801 | fprintf(stderr, "Usage: %s [-p] [-r] [-t] -[x] [-n max_arg] [-s max_chars]\n", | 801 | fprintf(stderr, "Usage: %s [-p] [-r] [-t] -[x] [-n max_arg] [-s max_chars]\n", |
802 | applet_name); | 802 | applet_name); |
803 | exit(EXIT_FAILURE); | 803 | exit_FAILURE(); |
804 | } | 804 | } |
805 | 805 | ||
806 | int main(int argc, char **argv) | 806 | int main(int argc, char **argv) |
diff --git a/include/libbb.h b/include/libbb.h index 6191debb1..18336da23 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1281,6 +1281,8 @@ void set_task_comm(const char *comm) FAST_FUNC; | |||
1281 | #endif | 1281 | #endif |
1282 | void exit_SUCCESS(void) NORETURN FAST_FUNC; | 1282 | void exit_SUCCESS(void) NORETURN FAST_FUNC; |
1283 | void _exit_SUCCESS(void) NORETURN FAST_FUNC; | 1283 | void _exit_SUCCESS(void) NORETURN FAST_FUNC; |
1284 | void exit_FAILURE(void) NORETURN FAST_FUNC; | ||
1285 | void _exit_FAILURE(void) NORETURN FAST_FUNC; | ||
1284 | 1286 | ||
1285 | /* Helpers for daemonization. | 1287 | /* Helpers for daemonization. |
1286 | * | 1288 | * |
diff --git a/init/init.c b/init/init.c index 1e1ce833d..2ee1e4cde 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -500,7 +500,7 @@ static pid_t run(const struct init_action *a) | |||
500 | 500 | ||
501 | /* Open the new terminal device */ | 501 | /* Open the new terminal device */ |
502 | if (!open_stdio_to_tty(a->terminal)) | 502 | if (!open_stdio_to_tty(a->terminal)) |
503 | _exit(EXIT_FAILURE); | 503 | _exit_FAILURE(); |
504 | 504 | ||
505 | /* NB: on NOMMU we can't wait for input in child, so | 505 | /* NB: on NOMMU we can't wait for input in child, so |
506 | * "askfirst" will work the same as "respawn". */ | 506 | * "askfirst" will work the same as "respawn". */ |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 465e5366c..b03af8542 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -433,3 +433,13 @@ void FAST_FUNC _exit_SUCCESS(void) | |||
433 | { | 433 | { |
434 | _exit(EXIT_SUCCESS); | 434 | _exit(EXIT_SUCCESS); |
435 | } | 435 | } |
436 | |||
437 | void FAST_FUNC exit_FAILURE(void) | ||
438 | { | ||
439 | exit(EXIT_FAILURE); | ||
440 | } | ||
441 | |||
442 | void FAST_FUNC _exit_FAILURE(void) | ||
443 | { | ||
444 | _exit(EXIT_FAILURE); | ||
445 | } | ||
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index 2a83c8a15..71d3a8db9 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c | |||
@@ -102,7 +102,7 @@ static void new_group(char *group, gid_t gid) | |||
102 | /* add entry to group */ | 102 | /* add entry to group */ |
103 | p = xasprintf("x:%u:", (unsigned) gr.gr_gid); | 103 | p = xasprintf("x:%u:", (unsigned) gr.gr_gid); |
104 | if (update_passwd(bb_path_group_file, group, p, NULL) < 0) | 104 | if (update_passwd(bb_path_group_file, group, p, NULL) < 0) |
105 | exit(EXIT_FAILURE); | 105 | exit_FAILURE(); |
106 | if (ENABLE_FEATURE_CLEAN_UP) | 106 | if (ENABLE_FEATURE_CLEAN_UP) |
107 | free(p); | 107 | free(p); |
108 | #if ENABLE_FEATURE_SHADOWPASSWDS | 108 | #if ENABLE_FEATURE_SHADOWPASSWDS |
diff --git a/loginutils/login.c b/loginutils/login.c index 332238181..b02be2176 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -173,7 +173,7 @@ static void die_if_nologin(void) | |||
173 | fflush_all(); | 173 | fflush_all(); |
174 | /* Users say that they do need this prior to exit: */ | 174 | /* Users say that they do need this prior to exit: */ |
175 | tcdrain(STDOUT_FILENO); | 175 | tcdrain(STDOUT_FILENO); |
176 | exit(EXIT_FAILURE); | 176 | exit_FAILURE(); |
177 | } | 177 | } |
178 | #else | 178 | #else |
179 | # define die_if_nologin() ((void)0) | 179 | # define die_if_nologin() ((void)0) |
@@ -265,19 +265,19 @@ static void get_username_or_die(char *buf, int size_buf) | |||
265 | do { | 265 | do { |
266 | c = getchar(); | 266 | c = getchar(); |
267 | if (c == EOF) | 267 | if (c == EOF) |
268 | exit(EXIT_FAILURE); | 268 | exit_FAILURE(); |
269 | if (c == '\n') { | 269 | if (c == '\n') { |
270 | if (!--cntdown) | 270 | if (!--cntdown) |
271 | exit(EXIT_FAILURE); | 271 | exit_FAILURE(); |
272 | goto prompt; | 272 | goto prompt; |
273 | } | 273 | } |
274 | } while (isspace(c)); /* maybe isblank? */ | 274 | } while (isspace(c)); /* maybe isblank? */ |
275 | 275 | ||
276 | *buf++ = c; | 276 | *buf++ = c; |
277 | if (!fgets(buf, size_buf-2, stdin)) | 277 | if (!fgets(buf, size_buf-2, stdin)) |
278 | exit(EXIT_FAILURE); | 278 | exit_FAILURE(); |
279 | if (!strchr(buf, '\n')) | 279 | if (!strchr(buf, '\n')) |
280 | exit(EXIT_FAILURE); | 280 | exit_FAILURE(); |
281 | while ((unsigned char)*buf > ' ') | 281 | while ((unsigned char)*buf > ' ') |
282 | buf++; | 282 | buf++; |
283 | *buf = '\0'; | 283 | *buf = '\0'; |
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 297693f8c..36b491595 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c | |||
@@ -354,10 +354,10 @@ static const char bb_msg_variable_not_found[] ALIGN1 = "variable: %s not found"; | |||
354 | #define simple_info_logger(p, msg) | 354 | #define simple_info_logger(p, msg) |
355 | #define msg_logger(p, fmt, args...) | 355 | #define msg_logger(p, fmt, args...) |
356 | #define simple_msg_logger(p, msg) | 356 | #define simple_msg_logger(p, msg) |
357 | #define msg_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE) | 357 | #define msg_logger_and_die(p, fmt, args...) exit_FAILURE() |
358 | #define simple_msg_logger_and_die(p, msg) exit(EXIT_FAILURE) | 358 | #define simple_msg_logger_and_die(p, msg) exit_FAILURE() |
359 | #define error_logger(p, fmt, args...) | 359 | #define error_logger(p, fmt, args...) |
360 | #define error_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE) | 360 | #define error_logger_and_die(p, fmt, args...) exit_FAILURE() |
361 | #endif | 361 | #endif |
362 | 362 | ||
363 | static void safe_memcpy(char *dest, const char *src, int len) | 363 | static void safe_memcpy(char *dest, const char *src, int len) |
diff --git a/miscutils/setserial.c b/miscutils/setserial.c index 2006861e2..175c788fc 100644 --- a/miscutils/setserial.c +++ b/miscutils/setserial.c | |||
@@ -535,7 +535,7 @@ static int serial_ctl(int fd, int ops, struct serial_struct *serinfo) | |||
535 | bb_simple_perror_msg(err); | 535 | bb_simple_perror_msg(err); |
536 | if (ops & CTL_NODIE) | 536 | if (ops & CTL_NODIE) |
537 | goto nodie; | 537 | goto nodie; |
538 | exit(EXIT_FAILURE); | 538 | exit_FAILURE(); |
539 | } | 539 | } |
540 | 540 | ||
541 | static void print_flag(const char **prefix, const char *flag) | 541 | static void print_flag(const char **prefix, const char *flag) |
diff --git a/networking/inetd.c b/networking/inetd.c index fb2fbe323..e63edcd9d 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1449,7 +1449,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1449 | else | 1449 | else |
1450 | sep->se_builtin->bi_dgram_fn(ctrl, sep); | 1450 | sep->se_builtin->bi_dgram_fn(ctrl, sep); |
1451 | if (pid) /* we did fork */ | 1451 | if (pid) /* we did fork */ |
1452 | _exit(EXIT_FAILURE); | 1452 | _exit_FAILURE(); |
1453 | maybe_close(accepted_fd); | 1453 | maybe_close(accepted_fd); |
1454 | continue; /* -> check next fd in fd set */ | 1454 | continue; /* -> check next fd in fd set */ |
1455 | } | 1455 | } |
@@ -1530,7 +1530,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1530 | /* eat packet in udp case */ | 1530 | /* eat packet in udp case */ |
1531 | if (sep->se_socktype != SOCK_STREAM) | 1531 | if (sep->se_socktype != SOCK_STREAM) |
1532 | recv(0, line, LINE_SIZE, MSG_DONTWAIT); | 1532 | recv(0, line, LINE_SIZE, MSG_DONTWAIT); |
1533 | _exit(EXIT_FAILURE); | 1533 | _exit_FAILURE(); |
1534 | } /* for (sep = servtab...) */ | 1534 | } /* for (sep = servtab...) */ |
1535 | } /* for (;;) */ | 1535 | } /* for (;;) */ |
1536 | } | 1536 | } |
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index 68d199044..9eb0b4f5f 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c | |||
@@ -215,7 +215,7 @@ static void parse_address(char *dev, int hatype, int halen, char *lla, struct if | |||
215 | alen = hatype == 1/*ARPHRD_ETHER*/ ? 14/*ETH_HLEN*/ : 19/*INFINIBAND_HLEN*/; | 215 | alen = hatype == 1/*ARPHRD_ETHER*/ ? 14/*ETH_HLEN*/ : 19/*INFINIBAND_HLEN*/; |
216 | alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), alen, lla); | 216 | alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), alen, lla); |
217 | if (alen < 0) | 217 | if (alen < 0) |
218 | exit(EXIT_FAILURE); | 218 | exit_FAILURE(); |
219 | if (alen != halen) { | 219 | if (alen != halen) { |
220 | bb_error_msg_and_die("wrong address (%s) length: expected %d bytes", lla, halen); | 220 | bb_error_msg_and_die("wrong address (%s) length: expected %d bytes", lla, halen); |
221 | } | 221 | } |
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index c9fa632f3..1ec81c635 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c | |||
@@ -319,7 +319,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) | |||
319 | struct ip_tunnel_parm old_p; | 319 | struct ip_tunnel_parm old_p; |
320 | memset(&old_p, 0, sizeof(old_p)); | 320 | memset(&old_p, 0, sizeof(old_p)); |
321 | if (do_get_ioctl(*argv, &old_p)) | 321 | if (do_get_ioctl(*argv, &old_p)) |
322 | exit(EXIT_FAILURE); | 322 | exit_FAILURE(); |
323 | *p = old_p; | 323 | *p = old_p; |
324 | } | 324 | } |
325 | } | 325 | } |
diff --git a/networking/ping.c b/networking/ping.c index 9805695a1..b7e6955a9 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -247,7 +247,7 @@ struct globals { | |||
247 | static void noresp(int ign UNUSED_PARAM) | 247 | static void noresp(int ign UNUSED_PARAM) |
248 | { | 248 | { |
249 | printf("No response from %s\n", G.hostname); | 249 | printf("No response from %s\n", G.hostname); |
250 | exit(EXIT_FAILURE); | 250 | exit_FAILURE(); |
251 | } | 251 | } |
252 | 252 | ||
253 | static void ping4(len_and_sockaddr *lsa) | 253 | static void ping4(len_and_sockaddr *lsa) |
diff --git a/networking/slattach.c b/networking/slattach.c index 6d2a252fc..16b4c9158 100644 --- a/networking/slattach.c +++ b/networking/slattach.c | |||
@@ -80,7 +80,7 @@ static void restore_state_and_exit(int exitcode) | |||
80 | 80 | ||
81 | /* Restore line status */ | 81 | /* Restore line status */ |
82 | if (tcsetattr_serial_or_warn(&G.saved_state)) | 82 | if (tcsetattr_serial_or_warn(&G.saved_state)) |
83 | exit(EXIT_FAILURE); | 83 | exit_FAILURE(); |
84 | 84 | ||
85 | if (ENABLE_FEATURE_CLEAN_UP) | 85 | if (ENABLE_FEATURE_CLEAN_UP) |
86 | close(serial_fd); | 86 | close(serial_fd); |
diff --git a/networking/telnetd.c b/networking/telnetd.c index 0805e464f..fb90e7f11 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -571,7 +571,7 @@ make_new_session( | |||
571 | BB_EXECVP(G.loginpath, (char **)login_argv); | 571 | BB_EXECVP(G.loginpath, (char **)login_argv); |
572 | /* _exit is safer with vfork, and we shouldn't send message | 572 | /* _exit is safer with vfork, and we shouldn't send message |
573 | * to remote clients anyway */ | 573 | * to remote clients anyway */ |
574 | _exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", G.loginpath);*/ | 574 | _exit_FAILURE(); /*bb_perror_msg_and_die("execv %s", G.loginpath);*/ |
575 | } | 575 | } |
576 | 576 | ||
577 | #if ENABLE_FEATURE_TELNETD_STANDALONE | 577 | #if ENABLE_FEATURE_TELNETD_STANDALONE |
diff --git a/procps/powertop.c b/procps/powertop.c index 18ddaa3ec..8d5d9295d 100644 --- a/procps/powertop.c +++ b/procps/powertop.c | |||
@@ -109,7 +109,7 @@ static void reset_term(void) | |||
109 | static void sig_handler(int signo UNUSED_PARAM) | 109 | static void sig_handler(int signo UNUSED_PARAM) |
110 | { | 110 | { |
111 | reset_term(); | 111 | reset_term(); |
112 | _exit(EXIT_FAILURE); | 112 | _exit_FAILURE(); |
113 | } | 113 | } |
114 | #endif | 114 | #endif |
115 | 115 | ||
diff --git a/selinux/setfiles.c b/selinux/setfiles.c index a617b95d8..70e68a666 100644 --- a/selinux/setfiles.c +++ b/selinux/setfiles.c | |||
@@ -687,7 +687,7 @@ int setfiles_main(int argc UNUSED_PARAM, char **argv) | |||
687 | bb_simple_perror_msg_and_die(argv[0]); | 687 | bb_simple_perror_msg_and_die(argv[0]); |
688 | } | 688 | } |
689 | if (nerr) | 689 | if (nerr) |
690 | exit(EXIT_FAILURE); | 690 | exit_FAILURE(); |
691 | argv++; | 691 | argv++; |
692 | } | 692 | } |
693 | 693 | ||
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 6c66c130d..049f0b169 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c | |||
@@ -746,11 +746,12 @@ xbsd_write_bootstrap(void) | |||
746 | return; | 746 | return; |
747 | 747 | ||
748 | e = d + sizeof(struct xbsd_disklabel); | 748 | e = d + sizeof(struct xbsd_disklabel); |
749 | for (p = d; p < e; p++) | 749 | for (p = d; p < e; p++) { |
750 | if (*p) { | 750 | if (*p) { |
751 | printf("Bootstrap overlaps with disk label!\n"); | 751 | printf("Bootstrap overlaps with disk label!\n"); |
752 | exit(EXIT_FAILURE); | 752 | exit_FAILURE(); |
753 | } | 753 | } |
754 | } | ||
754 | 755 | ||
755 | memmove(d, &dl, sizeof(struct xbsd_disklabel)); | 756 | memmove(d, &dl, sizeof(struct xbsd_disklabel)); |
756 | 757 | ||
diff --git a/util-linux/more.c b/util-linux/more.c index a830dcbc1..352a3b6cf 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -65,7 +65,7 @@ static void gotsig(int sig UNUSED_PARAM) | |||
65 | * therefore it is safe in signal handler */ | 65 | * therefore it is safe in signal handler */ |
66 | bb_putchar_stderr('\n'); | 66 | bb_putchar_stderr('\n'); |
67 | tcsetattr_tty_TCSANOW(&G.initial_settings); | 67 | tcsetattr_tty_TCSANOW(&G.initial_settings); |
68 | _exit(EXIT_FAILURE); | 68 | _exit_FAILURE(); |
69 | } | 69 | } |
70 | 70 | ||
71 | #define CONVERTED_TAB_SIZE 8 | 71 | #define CONVERTED_TAB_SIZE 8 |