aboutsummaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
AgeCommit message (Collapse)Author
2017-08-08getopt32: remove applet_long_optionsDenys Vlasenko
FEATURE_GETOPT_LONG made dependent on LONG_OPTS. The folloving options are removed, now LONG_OPTS enables long options for affected applets: FEATURE_ENV_LONG_OPTIONS FEATURE_EXPAND_LONG_OPTIONS FEATURE_UNEXPAND_LONG_OPTIONS FEATURE_MKDIR_LONG_OPTIONS FEATURE_MV_LONG_OPTIONS FEATURE_RMDIR_LONG_OPTIONS FEATURE_ADDGROUP_LONG_OPTIONS FEATURE_ADDUSER_LONG_OPTIONS FEATURE_HWCLOCK_LONG_OPTIONS FEATURE_NSENTER_LONG_OPTS FEATURE_CHCON_LONG_OPTIONS FEATURE_RUNCON_LONG_OPTIONS They either had a small number of long options, or their long options are essential. Example: upstream addgroup and adduser have ONLY longopts, we should probably go further and get rid of non-standard short options. To this end, make addgroup and adduser "select LONG_OPTS". We had this breakage caused by us even in our own package! #if ENABLE_LONG_OPTS || !ENABLE_ADDGROUP /* We try to use --gid, not -g, because "standard" addgroup * has no short option -g, it has only long --gid. */ argv[1] = (char*)"--gid"; #else /* Breaks if system in fact does NOT use busybox addgroup */ argv[1] = (char*)"-g"; #endif xargs: its lone longopt no longer depends on DESKTOP, only on LONG_OPTS. hwclock TODO: get rid of incompatible -t, -l aliases to --systz, --localtime Shorten help texts by omitting long option when short opt alternative exists. Reduction of size comes from the fact that store of an immediate (an address of longopts) to a fixed address (global variable) is a longer insn than pushing that immediate or passing it in a register. This effect is CPU-agnostic. function old new delta getopt32 1350 22 -1328 vgetopt32 - 1318 +1318 getopt32long - 24 +24 tftpd_main 562 567 +5 scan_recursive 376 380 +4 collect_cpu 545 546 +1 date_main 1096 1095 -1 hostname_main 262 259 -3 uname_main 259 255 -4 setpriv_main 362 358 -4 rmdir_main 191 187 -4 mv_main 562 558 -4 ipcalc_main 548 544 -4 ifenslave_main 641 637 -4 gzip_main 192 188 -4 gunzip_main 77 73 -4 fsfreeze_main 81 77 -4 flock_main 318 314 -4 deluser_main 337 333 -4 cp_main 374 370 -4 chown_main 175 171 -4 applet_long_options 4 - -4 xargs_main 894 889 -5 wget_main 2540 2535 -5 udhcpc_main 2767 2762 -5 touch_main 436 431 -5 tar_main 1014 1009 -5 start_stop_daemon_main 1033 1028 -5 sed_main 682 677 -5 script_main 1082 1077 -5 run_parts_main 330 325 -5 rtcwake_main 459 454 -5 od_main 2169 2164 -5 nl_main 201 196 -5 modprobe_main 773 768 -5 mkdir_main 160 155 -5 ls_main 568 563 -5 install_main 773 768 -5 hwclock_main 411 406 -5 getopt_main 622 617 -5 fstrim_main 256 251 -5 env_main 198 193 -5 dumpleases_main 635 630 -5 dpkg_main 3991 3986 -5 diff_main 1355 1350 -5 cryptpw_main 233 228 -5 cpio_main 593 588 -5 conspy_main 1135 1130 -5 chpasswd_main 313 308 -5 adduser_main 887 882 -5 addgroup_main 416 411 -5 ftpgetput_main 351 345 -6 get_terminal_width_height 242 234 -8 expand_main 690 680 -10 static.expand_longopts 18 - -18 static.unexpand_longopts 27 - -27 mkdir_longopts 28 - -28 env_longopts 30 - -30 static.ifenslave_longopts 34 - -34 mv_longopts 46 - -46 static.rmdir_longopts 48 - -48 packed_usage 31739 31687 -52 ------------------------------------------------------------------------------ (add/remove: 2/8 grow/shrink: 3/49 up/down: 1352/-1840) Total: -488 bytes text data bss dec hex filename 915681 485 6880 923046 e15a6 busybox_old 915428 485 6876 922789 e14a5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-08libbb: simplify NOFORK/NOEXEC defines, move set_task_comm to libbbDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-08libbb: rearrange NOFORK/NOEXEC code, logic is not changedDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07noexec: consolidate codeDenys Vlasenko
function old new delta run_noexec_applet_and_exit - 61 +61 find_applet_by_name 128 124 -4 run_applet_no_and_exit 441 434 -7 tryexec 169 152 -17 pseudo_exec_argv 338 321 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/6 up/down: 61/-48) Total: 13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07noexec: do GETOPT_RESET() before entering APPLET_main()Denys Vlasenko
hush -c 'yes | head -1' was not happy. function old new delta tryexec 159 169 +10 pseudo_exec_argv 328 338 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07noexec: set comm field for noexecsDenys Vlasenko
function old new delta set_task_comm - 18 +18 tryexec 152 159 +7 pseudo_exec_argv 321 328 +7 main 106 97 -9 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/2 up/down: 34/-13) Total: 23 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-07free,stat: make NOEXECDenys Vlasenko
pkill/pgrep/pidof uncovered another quirk: what about noexec's _process names_? Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04libbb: use _exit, not exit, in bb_daemonize_or_rexec()Denys Vlasenko
By the time we reach exit in parent, child already exited or execed. We should not re-run libc cleanup code. While at it, introduce bb_daemon_helper() and add a few comments. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-03nofork: fix a bug uncovered by hush testsuite (forgotten fflush)Denys Vlasenko
function old new delta run_nofork_applet 280 287 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-03new NOFORKs: pwdx,kill[all5],ttysize,realpath,readlink NOEXECs: date,resizeDenys Vlasenko
function old new delta run_nofork_applet 258 280 +22 readlink_main 112 123 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 33/0) Total: 33 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-07main: fix the case where user has "halt" as login shell. Closes 9986Denys Vlasenko
halt::0:0::/:/sbin/halt function old new delta run_applet_and_exit 748 751 +3 run_applet_no_and_exit 467 459 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03fixes for bugs found by make_single_applets.shDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12libbb: GETOPT_RESET macroKaarle Ritvanen
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-26libbb: spawn_and_wait() fflushes before forking NOEXEC; child reinits logmodeDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-22config: disentangle PREFER_APPLETS from SH_STANDALONE and SH_NOFORKDenys Vlasenko
On user request. I thought enabling/disabling them all together is more consistent. Evidently, some people do want them to be separately selectable. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30applet_tables: save space by removing applet name offsetsRon Yorston
The array applet_nameofs consumes two bytes per applet. It encodes nofork/noexec flags suid flags the offset of the applet name in the applet_name string Change the applet_table build tool to store the flags in two separate arrays (applet_flags and applet_suid). Replace applet_nameofs[] with a smaller version that only stores a limited number of offsets. This requires changes to the macros APPLET_IS_NOFORK, APPLET_IS_NOEXEC and APPLET_SUID. According to Valgrind the original find_applet_by_name required 353 cycles per call, averaged over all names. Adjusting the number of known offsets allows space to be traded off against execution time: KNOWN_OFFSETS cycles bytes (wrt KNOWN_OFFSETS = 0) 0 9057 - 2 4604 32 4 2407 75 8 1342 98 16 908 130 32 884 194 This patch uses KNOWN_OFFSETS = 8. v2: Remove some dead code from the applet_table tool; Treat the applet in the middle of the table as a special case. v3: Use the middle applet to adjust the start of the linear search as well as the last applet found. v4: Use an augmented linear search in find_applet_by_name. Drop the special treatment of the middle name from get_applet_name: most of the advantage now derives from the last stored value. v5: Don't store index in applet_nameofs, it can be calculated. v6: Tweaks by Denys function old new delta find_applet_by_name 25 125 +100 applet_suid - 92 +92 run_applet_no_and_exit 452 460 +8 run_applet_and_exit 695 697 +2 applet_name_compare 31 - -31 applet_nameofs 734 14 -720 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 3/1 up/down: 202/-751) Total: -549 bytes text data bss dec hex filename 925464 906 17160 943530 e65aa busybox_old 924915 906 17160 942981 e6385 busybox_unstripped Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09remove global "jmp_buf die_jmp" from !FEATURE_PREFER_APPLETS buildsDenys Vlasenko
function old new delta xfunc_has_died - 21 +21 sleep_much - 12 +12 sleep10 - 9 +9 die_func - 4 +4 fflush_stdout_and_exit 35 36 +1 builtin_type 121 119 -2 die_sleep 4 - -4 xfunc_die 60 24 -36 hush_main 1128 1011 -117 die_jmp 156 - -156 ------------------------------------------------------------------------------ (add/remove: 4/2 grow/shrink: 1/3 up/down: 47/-315) Total: -268 bytes text data bss dec hex filename 939992 992 17652 958636 ea0ac busybox_old 939880 992 17496 958368 e9fa0 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-11-09bb_daemonize_or_rexec(): add flag to double-fork; use it in start-stop-daemonPeter Korsgaard
Add a DAEMON_DOUBLE_FORK flag to make bb_daemonize double-fork so it isn't a session leader, and hence doesn't get a controlling tty on Linux if a tty is ever opened, similar to how libdaemon's daemon_fork or the big start-stop-daemon does it - And use it in start-stop-daemon. For details, see http://www.win.tue.nl/~aeb/linux/lk/lk-10.html#ss10.3 Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-02-03libbb: spawn should remove child which failed to execDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-02-02move nofork_save_area from libbb.h to vfork_daemon_rexec.cDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-02-02libbb: make BB_EXECVP/LP try to exec real binary if there's no /proc/self/exeDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-08-16*: make GNU licensing statement forms more regularDenys Vlasenko
This change retains "or later" state! No licensing _changes_ here, only form is adjusted (article, space between "GPL" and "v2" and so on). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-07-04*: introduce and use xfork() and xvfork()Pascal Bellard
function old new delta launch_helper 170 169 -1 setup_heredoc 312 302 -10 handle_dir_common 367 354 -13 expand_vars_to_list 2456 2443 -13 open_transformer 89 74 -15 data_extract_to_command 439 423 -16 do_ipaddr 1406 1389 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-85) Total: -85 bytes Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-07-04libbb: introduce and use BB_EXECVP_or_die()Pascal Bellard
function old new delta BB_EXECVP_or_die - 47 +47 time_main 1042 1043 +1 chrt_main 371 364 -7 ionice_main 292 282 -10 setsid_main 69 56 -13 nohup_main 236 223 -13 cttyhack_main 266 253 -13 chroot_main 94 81 -13 chpst_main 746 733 -13 timeout_main 297 279 -18 taskset_main 541 522 -19 vfork_child 67 45 -22 parse 975 953 -22 lpd_main 770 748 -22 launch_helper 192 170 -22 tcpudpsvd_main 1810 1782 -28 nice_main 190 156 -34 env_main 242 206 -36 run_command 221 174 -47 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/17 up/down: 48/-352) Total: -304 bytes Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-06-25*: make exec failure message more consistentDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-18*: code shrink and better "died from signal" reporting from wait4pidDenys Vlasenko
function old new delta parse 964 967 +3 udhcp_run_script 670 665 -5 singlemount 911 906 -5 mount_it_now 360 355 -5 inotifyd_main 521 516 -5 xspawn 21 - -21 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/4 up/down: 3/-41) Total: -38 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-11-02*: introduce and use ffulsh_all()Denys Vlasenko
function old new delta buffer_fill_and_print 179 196 +17 fflush_all - 9 +9 spawn 87 92 +5 rtcwake_main 455 453 -2 ... alarm_intr 93 84 -9 readcmd 1072 1062 -10 bb_ask 345 333 -12 more_main 845 832 -13 flush_stdout_stderr 42 23 -19 xfflush_stdout 27 - -27 flush_stderr 30 - -30 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 2/50 up/down: 31/-397) Total: -366 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-10-11libbb: revert the change where spawn reports exec failureDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-10-08libbb: make spawn() print "can't execute '%s'" on execv errorDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-09-23*: more portability fixes by Dan FandrichDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-06-07stop using non-standard macro, use WEXITSTATUS insteadDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-03-20Compatibility fixes:Denis Vlasenko
grep: support -z find: support --mindepth together +45 bytes cpio: support -p (configurable, +230 bytes) libbb: tweaks for cpio
2008-11-06runsvdir: alternative methon of supporting runsvdir-as-init. +66 bytes.Denis Vlasenko
*: s/int/pid_t where appropriate
2008-10-20ash: fix a bug in standalone mode (corrupted getopt() state)Denis Vlasenko
2008-07-06mdev: do not follow symlinks in /sys (as was intended prior to rev 18811).Denis Vlasenko
If this breaks things, please document why! mdev,init: use shared code for fd sanitization function old new delta bb_daemonize_or_rexec 155 172 +17 mdev_main 500 505 +5 init_main 907 856 -51 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 22/-51) Total: -29 bytes
2008-07-01revert last two commits. vfork cannot be used in subroutine,Denis Vlasenko
it trashes stack on return
2008-07-01*: introduce and use xfork()Denis Vlasenko
function old new delta xfork - 20 +20 msh_main 1377 1380 +3 mod_process 455 446 -9 forkexit_or_rexec 30 17 -13 expand_variables 1434 1421 -13 open_transformer 91 76 -15 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/4 up/down: 23/-50) Total: -27 bytes
2008-07-01*: introduce and use xvfork()Denis Vlasenko
function old new delta time_main 1052 1285 +233 crontab_main 623 856 +233 ifupdown_main 2202 2403 +201 xvfork - 20 +20 passwd_main 1049 1053 +4 grave 1068 1066 -2 script_main 935 921 -14 vfork_or_die 20 - -20 vfork_compressor 206 175 -31 open_as_user 109 - -109 popen2 218 - -218 edit_file 910 690 -220 run_command 268 - -268 ------------------------------------------------------------------------------ (add/remove: 1/4 grow/shrink: 4/4 up/down: 691/-882) Total: -191 bytes
2008-06-27*: introduce and use FAST_FUNC: regparm on i386, otherwise no-onDenis Vlasenko
text data bss dec hex filename 808035 611 6868 815514 c719a busybox_old 804472 611 6868 811951 c63af busybox_unstripped
2008-05-19- use EXIT_{SUCCESS,FAILURE}. No object-code changesBernhard Reutner-Fischer
2008-04-13fix english in commentDenis Vlasenko
2008-04-13ash: speed up NOFORK code in ash by eliminating second find_applet().Denis Vlasenko
some code reduction along the way. function old new delta run_list 1971 1981 +10 run_nofork_applet_prime 181 182 +1 unsetcmd 97 96 -1 delete_cmd_entry 54 53 -1 describe_command 399 397 -2 cmdlookup 152 150 -2 evaltreenr 602 599 -3 evaltree 602 599 -3 clearcmdentry 101 98 -3 cdcmd 675 672 -3 hashcmd 305 301 -4 find_command 933 910 -23 evalcommand 1371 1229 -142 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/11 up/down: 11/-187) Total: -176 bytes
2008-02-17libbb: introduce and use xrename and rename_or_warn.Denis Vlasenko
2008-01-28*: move getopt reset code to better place(s)Denis Vlasenko
2008-01-27tentatively fix getopt state corruption for NOFORK appletsDenis Vlasenko
2008-01-02libbb: introduce and use safe_waitpid (loops in EINTR)Denis Vlasenko
*: use more approproate (shorter) versions of wait() function old new delta safe_waitpid - 48 +48 wait_any_nohang - 17 +17 send_tree 365 369 +4 processorstop 432 435 +3 text_yank 110 108 -2 make_human_readable_str 202 200 -2 crond_main 1368 1366 -2 handle_sigchld 49 43 -6 reapchild 166 159 -7 custom 260 250 -10 checkscript 191 177 -14 wait_nohang 17 - -17 wait_pid 43 - -43 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 2/7 up/down: 72/-103) Total: -31 bytes
2007-11-29Further optimize applet tables; prettify build outputDenis Vlasenko
text data bss dec hex filename 775923 929 9100 785952 bfe20 busybox_old 775565 929 9100 785594 bfcba busybox_unstripped
2007-11-28reorganize applet table. Eliminates pointers to names.Denis Vlasenko
Should be a big win for libbusybox. busybox wins too: text data bss dec hex filename 776524 929 9100 786553 c0079 busybox_old 775903 929 9100 785932 bfe0c busybox_unstripped
2007-10-10get rid of global "struct bb_applet *current_applet"Denis Vlasenko
2007-10-01'simple' error message functions by Loic Grenie <loic.grenie@gmail.com>.Denis Vlasenko
263 bytes saved.