*: stop using atexit in non-debug build: saves ~260 in bss with musl
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 16 Aug 2017 15:45:32 +0000 (17:45 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 16 Aug 2017 15:45:32 +0000 (17:45 +0200)
"builtin" below is atexit's 32-element global array of functions to call.

function                                             old     new   delta
top_main                                             879     889     +10
launch_helper                                        185     193      +8
powertop_main                                       1555    1559      +4
sed_main                                             651     650      -1
slot                                                   4       -      -4
call                                                   4       -      -4
atexit                                                23       -     -23
kill_helper                                           31       -     -31
__funcs_on_exit                                      120       -    -120
__cxa_atexit                                         168       -    -168
builtin                                              260       -    -260
------------------------------------------------------------------------------
(add/remove: 0/8 grow/shrink: 3/1 up/down: 22/-611)          Total: -589 bytes
   text    data     bss     dec     hex filename
 912364     563    6132  919059   e0613 busybox_old
 912035     563    5844  918442   e03aa busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/sed.c
mailutils/mail.c
procps/powertop.c
procps/top.c

index f68f44724f3cd4ee04f25e3b5dd54c5d5810c65d..3fc40ceef86f44a8dc5c9cb595c794bb970689ca 100644 (file)
@@ -1521,7 +1521,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
        //argc -= optind;
        argv += optind;
        if (opt & OPT_in_place) { // -i
-               atexit(cleanup_outname);
+               die_func = cleanup_outname;
        }
        if (opt & (2|4))
                G.regex_type |= REG_EXTENDED; // -r or -E
index a7e43c0d12f2f8f3cfbfd823e4f888b33f8b3dcf..eceb890715a0d48de5afd0115506eebb15c6c321 100644 (file)
@@ -6,23 +6,15 @@
  *
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
+#include <sys/prctl.h>
 #include "libbb.h"
 #include "mail.h"
 
-static void kill_helper(void)
-{
-       if (G.helper_pid > 0) {
-               kill(G.helper_pid, SIGTERM);
-               G.helper_pid = 0;
-       }
-}
-
 // generic signal handler
 static void signal_handler(int signo)
 {
 #define err signo
        if (SIGALRM == signo) {
-               kill_helper();
                bb_error_msg_and_die("timed out");
        }
 
@@ -66,16 +58,15 @@ void FAST_FUNC launch_helper(const char **argv)
        // child stdout [1] -> parent stdin [0]
 
        if (!G.helper_pid) {
-               // child: try to execute connection helper
+               // child
+               // if parent dies, get SIGTERM
+               prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
+               // try to execute connection helper
                // NB: SIGCHLD & SIGALRM revert to SIG_DFL on exec
                BB_EXECVP_or_die((char**)argv);
        }
 
-       // parent
-       // check whether child is alive
-       //redundant:signal_handler(SIGCHLD);
-       // child seems OK -> parent goes on
-       atexit(kill_helper);
+       // parent goes on
 }
 
 char* FAST_FUNC send_mail_command(const char *fmt, const char *param)
index ebd659bdba29a73fa0a91634153bcc1e9f6157d6..5d522bf918c23197d6c9dc07da844db402491f57 100644 (file)
@@ -8,11 +8,6 @@
  *
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
-
-//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
-
-//kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
-
 //config:config POWERTOP
 //config:      bool "powertop (9.1 kb)"
 //config:      default y
 //config:      Without this, powertop will only refresh display every 10 seconds.
 //config:      No keyboard commands will work, only ^C to terminate.
 
+//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
+
 // XXX This should be configurable
 #define ENABLE_FEATURE_POWERTOP_PROCIRQ 1
 
@@ -718,7 +717,7 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
        set_termios_to_raw(STDIN_FILENO, &G.init_settings, TERMIOS_CLEAR_ISIG);
        bb_signals(BB_FATAL_SIGS, sig_handler);
        /* So we don't forget to reset term settings */
-       atexit(reset_term);
+       die_func = reset_term;
 #endif
 
        /* Collect initial data */
@@ -855,6 +854,9 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
        } /* for (;;) */
 
        bb_putchar('\n');
+#if ENABLE_FEATURE_POWERTOP_INTERACTIVE
+       reset_term();
+#endif
 
        return EXIT_SUCCESS;
 }
index b9958afa097754d6ce762b801bc68189d14bc05d..f97ded5d6e47080c1958a1fc7cb1bf15f404a1af 100644 (file)
@@ -1146,6 +1146,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
        else {
                /* Turn on unbuffered input; turn off echoing, ^C ^Z etc */
                set_termios_to_raw(STDIN_FILENO, &initial_settings, TERMIOS_CLEAR_ISIG);
+               die_func = reset_term;
        }
 
        bb_signals(BB_FATAL_SIGS, sig_catcher);