From 95f7953f2c46c7b9c799250aa8dc6eb10cc5c726 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 2 Aug 2017 14:26:33 +0200 Subject: do not use `a' quoting style in comments Signed-off-by: Denys Vlasenko --- runit/chpst.c | 2 +- runit/runit_lib.h | 2 +- runit/runsv.c | 2 +- runit/runsvdir.c | 2 +- runit/sv.c | 2 +- runit/svlogd.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'runit') diff --git a/runit/chpst.c b/runit/chpst.c index 3a2f9e616..ccc96539d 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met: 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, diff --git a/runit/runit_lib.h b/runit/runit_lib.h index c36ea4ca5..c54561616 100644 --- a/runit/runit_lib.h +++ b/runit/runit_lib.h @@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met: 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, diff --git a/runit/runsv.c b/runit/runsv.c index ad7d82cb8..a67280b4b 100644 --- a/runit/runsv.c +++ b/runit/runsv.c @@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met: 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, diff --git a/runit/runsvdir.c b/runit/runsvdir.c index b4f5c303b..abba2e8e4 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c @@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met: 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, diff --git a/runit/sv.c b/runit/sv.c index 2d5b466bf..3dd02550a 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met: 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, diff --git a/runit/svlogd.c b/runit/svlogd.c index 8dbf67106..831873d86 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met: 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- cgit v1.2.3-55-g6feb From 5c527dc57e74c1b60c910dc1a3f3ec9683fca43d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Aug 2017 19:55:01 +0200 Subject: make 17 state-changing execing applets (ex: "nice PROG ARGS") noexec The applets with " [opts] PROG ARGS" API very quickly exec another program, noexec is okay for them: chpst/envdir/envuidgid/softlimit/setuidgid chroot chrt ionice nice nohup setarch/linux32/linux64 taskset cttyhack "reset" and "sulogin" applets don't have this form, but also exec another program at once, thus made noexec too. Signed-off-by: Denys Vlasenko --- NOFORK_NOEXEC.lst | 46 +++++++++++++++++++++++----------------------- console-tools/reset.c | 2 +- coreutils/chroot.c | 3 ++- coreutils/nice.c | 2 +- coreutils/nohup.c | 2 +- loginutils/sulogin.c | 4 ++-- runit/chpst.c | 12 ++++++------ shell/cttyhack.c | 2 +- util-linux/chrt.c | 2 +- util-linux/ionice.c | 2 +- util-linux/setarch.c | 8 ++++---- util-linux/taskset.c | 2 +- 12 files changed, 44 insertions(+), 43 deletions(-) (limited to 'runit') diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst index ccd8f0c96..5ec9ae3fe 100644 --- a/NOFORK_NOEXEC.lst +++ b/NOFORK_NOEXEC.lst @@ -20,7 +20,7 @@ suid: runs under different uid - must fork+exec Why shouldn't be NOFORK/NOEXEC: rare: not started often enough to bother optimizing (example: poweroff) daemon: runs indefinitely; these are also always fit "rare" category -longterm: often runs for a long time (many seconds), execing would make +longterm: often runs for a long time (many seconds), execing makes memory footprint smaller complex: no immediately obvious reason why NOFORK wouldn't work, but does some non-obvoius operations (example: fuser, lsof, losetup); @@ -66,9 +66,9 @@ chgrp - noexec. runner chmod - noexec. runner chown - noexec. runner chpasswd - runner (list of "user:password"s from stdin) -chpst - noexec candidate, spawner -chroot - noexec candidate, spawner -chrt - noexec candidate, spawner +chpst - noexec. spawner +chroot - noexec. spawner +chrt - noexec. spawner chvt - leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds. Also, "rare" category. noexec candidate. cksum - noexec. runner clear - NOFORK @@ -80,7 +80,7 @@ cpio - runner crond - daemon crontab 0 leaks: open+xasprintf cryptpw - changes state: with --password-fd=N, moves N to stdin. Also, "rare" category. noexec candidate. -cttyhack - noexec candidate, spawner +cttyhack - noexec. spawner cut - noexec. runner date - noexec. nofork candidate(needs to stop messing up env, free xasprintf result, not use xfuncs after xasprintf) dc - runner (eats stdin if no params) @@ -107,8 +107,8 @@ ed - interactive, longterm egrep - longterm runner ("CMD | egrep ..." may run indefinitely, better to exec to conserve memory) eject - leaks: open+ioctl_or_perror_and_die, changes state (moves fds) env - noexec. spawner, changes state (env) -envdir - noexec candidate, spawner -envuidgid - noexec candidate, spawner +envdir - noexec. spawner +envuidgid - noexec. spawner expand - runner expr - leaks: nested allocs factor - runner (eats stdin if no params) @@ -128,7 +128,7 @@ flash_eraseall flash_lock flash_unlock flashcp -flock - spawner, changes state (file locks) +flock - spawner, changes state (file locks), let's play safe and not be noexec fold - noexec. runner free - nofork candidate(struct globals, needs to close /proc/meminfo fd) freeramdisk - leaks: open+ioctl_or_perror_and_die @@ -170,7 +170,7 @@ init - daemon inotifyd - daemon insmod - noexec install - runner -ionice - spawner +ionice - noexec. spawner iostat - runner ip - noexec candidate ipaddr - noexec candidate @@ -190,8 +190,8 @@ klogd - daemon last - runner (I've got 1300 lines of output when tried it) less - interactive, longterm link - NOFORK -linux32 - spawner -linux64 - spawner +linux32 - noexec. spawner +linux64 - noexec. spawner linuxrc - daemon ln - noexec loadfont - leaks: config_open+bb_error_msg_and_die("map format") @@ -247,11 +247,11 @@ netstat - runner with -c nice - noexec candidate, spawner nl - runner nmeter - longterm -nohup - noexec candidate (maybe free concat_path_file result?), spawner +nohup - noexec. spawner nproc - NOFORK ntpd - daemon od - runner -openvt - spawner +openvt - longterm: spawns a child and waits for it partprobe - noexec candidate (simple), leaks: open+ioctl_or_perror_and_die(BLKRRPART) passwd - suid paste - noexec. runner @@ -304,15 +304,15 @@ scriptreplay sed - runner sendmail - runner seq - noexec. runner -setarch - spawner +setarch - noexec. spawner setconsole setfont setkeycodes setlogcons -setpriv - spawner +setpriv - spawner, changes state, let's play safe and not be noexec setserial -setsid - spawner -setuidgid +setsid - spawner, uses fork_or_rexec() [not audted to work in noexec], let's play safe and not be noexec +setuidgid - noexec. spawner sha1sum - noexec. runner sha256sum - noexec. runner sha3sum - noexec. runner @@ -323,7 +323,7 @@ shuf - noexec. runner slattach sleep - runner, longterm smemcap - runner -softlimit - noexec candidate, spawner +softlimit - noexec. spawner sort - noexec. runner split - runner ssl_client - longterm @@ -332,21 +332,21 @@ stat - nofork candidate(needs fewer allocs) strings - runner stty - noexec/nofork candidate. has no allocs or opens except xmove_fd(xopen("-F DEVICE"),STDIN). tcsetattr(STDIN) is not a problem: it would work the same across processes sharing this fd su - suid, spawner -sulogin - spawner +sulogin - noexec. spawner sum - runner sv - noexec candidate, needs ^C (uses usleep(420000)) svc - noexec candidate, needs ^C (uses usleep(420000)) svlogd - daemon swapoff - rare swapon - rare -switch_root - spawner, rare, changes state +switch_root - spawner, rare, changes state (oh yes), execing may be important to free binary's inode sync - NOFORK sysctl - noexec candidate, leaks: xstrdup+xmalloc_read syslogd - daemon tac - noexec. runner tail - runner tar - runner -taskset - spawner +taskset - noexec. spawner tcpsvd - daemon tee - runner telnet - interactive, longterm @@ -354,8 +354,8 @@ telnetd - daemon test - NOFORK tftp - runner tftpd - daemon -time - spawner, changes state (signals) -timeout - spawner, changes state (signals) +time - spawner, longterm, changes state (signals) +timeout - spawner, longterm, changes state (signals) top - interactive, longterm touch - NOFORK tr - runner diff --git a/console-tools/reset.c b/console-tools/reset.c index 04e5b0ca1..f2b900ddb 100644 --- a/console-tools/reset.c +++ b/console-tools/reset.c @@ -16,7 +16,7 @@ //config: This program is used to reset the terminal screen, if it //config: gets messed up. -//applet:IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_RESET(APPLET_NOEXEC(reset, reset, BB_DIR_USR_BIN, BB_SUID_DROP, reset)) //kbuild:lib-$(CONFIG_RESET) += reset.o diff --git a/coreutils/chroot.c b/coreutils/chroot.c index 5645d72df..78751df84 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c @@ -13,7 +13,7 @@ //config: chroot is used to change the root directory and run a command. //config: The default command is '/bin/sh'. -//applet:IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP)) +//applet:IF_CHROOT(APPLET_NOEXEC(chroot, chroot, BB_DIR_USR_SBIN, BB_SUID_DROP, chroot)) //kbuild:lib-$(CONFIG_CHROOT) += chroot.o @@ -40,6 +40,7 @@ int chroot_main(int argc UNUSED_PARAM, char **argv) ++argv; if (!*argv) bb_show_usage(); + xchroot(*argv); ++argv; diff --git a/coreutils/nice.c b/coreutils/nice.c index 0bf055299..d6818cf00 100644 --- a/coreutils/nice.c +++ b/coreutils/nice.c @@ -12,7 +12,7 @@ //config: help //config: nice runs a program with modified scheduling priority. -//applet:IF_NICE(APPLET(nice, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_NICE(APPLET_NOEXEC(nice, nice, BB_DIR_BIN, BB_SUID_DROP, nice)) //kbuild:lib-$(CONFIG_NICE) += nice.o diff --git a/coreutils/nohup.c b/coreutils/nohup.c index df271c738..8a70ec4df 100644 --- a/coreutils/nohup.c +++ b/coreutils/nohup.c @@ -15,7 +15,7 @@ //config: help //config: run a command immune to hangups, with output to a non-tty. -//applet:IF_NOHUP(APPLET(nohup, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_NOHUP(APPLET_NOEXEC(nohup, nohup, BB_DIR_USR_BIN, BB_SUID_DROP, nohup)) //kbuild:lib-$(CONFIG_NOHUP) += nohup.o diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index d5a463cac..27ea5dff0 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -12,7 +12,7 @@ //config: sulogin is invoked when the system goes into single user //config: mode (this is done through an entry in inittab). -//applet:IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP)) +//applet:IF_SULOGIN(APPLET_NOEXEC(sulogin, sulogin, BB_DIR_SBIN, BB_SUID_DROP, sulogin)) //kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o @@ -34,7 +34,7 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) /* Note: sulogin is not a suid app. It is meant to be run by init * for single user / emergency mode. init starts it as root. - * Normal users (potentially malisious ones) can only run it under + * Normal users (potentially malicious ones) can only run it under * their UID, therefore no paranoia here is warranted: * $LD_LIBRARY_PATH in env, TTY = /dev/sda * are no more dangerous here than in e.g. cp applet. diff --git a/runit/chpst.c b/runit/chpst.c index ccc96539d..c061a91ea 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -59,12 +59,12 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //config: help //config: Sets soft resource limits as specified by options -//applet:IF_CHPST(APPLET(chpst, BB_DIR_USR_BIN, BB_SUID_DROP)) -// APPLET_ODDNAME:name main location suid_type help -//applet:IF_ENVDIR( APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) -//applet:IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid)) -//applet:IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid)) -//applet:IF_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit)) +//applet:IF_CHPST( APPLET_NOEXEC(chpst, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, chpst)) +// APPLET_NOEXEC:name main location suid_type help +//applet:IF_ENVDIR( APPLET_NOEXEC(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) +//applet:IF_ENVUIDGID(APPLET_NOEXEC(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid)) +//applet:IF_SETUIDGID(APPLET_NOEXEC(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid)) +//applet:IF_SOFTLIMIT(APPLET_NOEXEC(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit)) //kbuild:lib-$(CONFIG_CHPST) += chpst.o //kbuild:lib-$(CONFIG_ENVDIR) += chpst.o diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 9004b4763..849fe9e48 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -6,7 +6,7 @@ */ #include "libbb.h" -//applet:IF_CTTYHACK(APPLET(cttyhack, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_CTTYHACK(APPLET_NOEXEC(cttyhack, cttyhack, BB_DIR_BIN, BB_SUID_DROP, cttyhack)) //kbuild:lib-$(CONFIG_CTTYHACK) += cttyhack.o diff --git a/util-linux/chrt.c b/util-linux/chrt.c index 4bc8b6cfa..52523df02 100644 --- a/util-linux/chrt.c +++ b/util-linux/chrt.c @@ -12,7 +12,7 @@ //config: manipulate real-time attributes of a process. //config: This requires sched_{g,s}etparam support in your libc. -//applet:IF_CHRT(APPLET(chrt, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_CHRT(APPLET_NOEXEC(chrt, chrt, BB_DIR_USR_BIN, BB_SUID_DROP, chrt)) //kbuild:lib-$(CONFIG_CHRT) += chrt.o diff --git a/util-linux/ionice.c b/util-linux/ionice.c index c7b7f0373..5b9664d25 100644 --- a/util-linux/ionice.c +++ b/util-linux/ionice.c @@ -14,7 +14,7 @@ //config: Set/set program io scheduling class and priority //config: Requires kernel >= 2.6.13 -//applet:IF_IONICE(APPLET(ionice, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_IONICE(APPLET_NOEXEC(ionice, ionice, BB_DIR_BIN, BB_SUID_DROP, ionice)) //kbuild:lib-$(CONFIG_IONICE) += ionice.o diff --git a/util-linux/setarch.c b/util-linux/setarch.c index d4b568832..520865318 100644 --- a/util-linux/setarch.c +++ b/util-linux/setarch.c @@ -30,10 +30,10 @@ //config: help //config: Alias to "setarch linux64". -//applet:IF_SETARCH(APPLET(setarch, BB_DIR_BIN, BB_SUID_DROP)) -// APPLET_ODDNAME:name main location suid_type help -//applet:IF_LINUX32(APPLET_ODDNAME(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32)) -//applet:IF_LINUX64(APPLET_ODDNAME(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64)) +//applet:IF_SETARCH(APPLET_NOEXEC(setarch, setarch, BB_DIR_BIN, BB_SUID_DROP, setarch)) +// APPLET_NOEXEC:name main location suid_type help +//applet:IF_LINUX32(APPLET_NOEXEC(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32)) +//applet:IF_LINUX64(APPLET_NOEXEC(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64)) //kbuild:lib-$(CONFIG_SETARCH) += setarch.o //kbuild:lib-$(CONFIG_LINUX32) += setarch.o diff --git a/util-linux/taskset.c b/util-linux/taskset.c index 9957b1a71..89dea176e 100644 --- a/util-linux/taskset.c +++ b/util-linux/taskset.c @@ -22,7 +22,7 @@ //config: affinity parameter 0xHHHHHHHHHHHHHHHHHHHH can be arbitrarily long //config: in this case. Otherwise, it is limited to sizeof(long). -//applet:IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_TASKSET(APPLET_NOEXEC(taskset, taskset, BB_DIR_USR_BIN, BB_SUID_DROP, taskset)) //kbuild:lib-$(CONFIG_TASKSET) += taskset.o //usage:#define taskset_trivial_usage -- cgit v1.2.3-55-g6feb From 754e9f96defd7be48dfdc9ffe820c3fb7f35ff9e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 5 Aug 2017 01:38:55 +0200 Subject: svc: fix a case where with more than option, getopt() state is not reset Signed-off-by: Denys Vlasenko --- runit/sv.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'runit') diff --git a/runit/sv.c b/runit/sv.c index 3dd02550a..3267c7e4c 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -718,15 +718,16 @@ int svc_main(int argc UNUSED_PARAM, char **argv) argv[1] = command; command[1] = '\0'; - /* getopt32() was already called: - * reset the libc getopt() function, which keeps internal state. - */ - GETOPT_RESET(); - do { if (opts & 1) { int r; + command[0] = *optstring; + + /* getopt() was already called by getopt32(): + * reset the libc getopt() function's internal state. + */ + GETOPT_RESET(); r = sv(argv); if (r) return 1; -- cgit v1.2.3-55-g6feb From a453ca576fba45849784322681a4515bdab9ceab Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 5 Aug 2017 01:42:08 +0200 Subject: sv, svc: make them NOEXEC Signed-off-by: Denys Vlasenko --- NOFORK_NOEXEC.lst | 4 ++-- runit/sv.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'runit') diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst index b2f410177..f6cc548d2 100644 --- a/NOFORK_NOEXEC.lst +++ b/NOFORK_NOEXEC.lst @@ -334,8 +334,8 @@ stty - noexec. nofork candidate: has no allocs or opens except xmove_fd(xopen("- su - suid, spawner sulogin - noexec. spawner sum - runner -sv - noexec candidate, needs ^C (uses usleep(420000)) -svc - noexec candidate, needs ^C (uses usleep(420000)) +sv - noexec. needs ^C (uses usleep(420000)) +svc - noexec. needs ^C (uses usleep(420000)) svlogd - daemon swapoff - rare swapon - rare diff --git a/runit/sv.c b/runit/sv.c index 3267c7e4c..0817ab472 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -175,8 +175,8 @@ Exit Codes //config: svc controls the state of services monitored by the runsv supervisor. //config: It is comaptible with daemontools command with the same name. -//applet:IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP)) -//applet:IF_SVC(APPLET(svc, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_SV( APPLET_NOEXEC(sv, sv, BB_DIR_USR_BIN, BB_SUID_DROP, sv )) +//applet:IF_SVC(APPLET_NOEXEC(svc, svc, BB_DIR_USR_BIN, BB_SUID_DROP, svc)) //kbuild:lib-$(CONFIG_SV) += sv.o //kbuild:lib-$(CONFIG_SVC) += sv.o -- cgit v1.2.3-55-g6feb From b9be78070569e69960ba2b3c4098c3dc3316b9bd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Aug 2017 21:23:03 +0200 Subject: sv,svc: fix NOEXEC fallout function old new delta svc_main 145 162 +17 sv 1280 1297 +17 status 139 133 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-6) Total: 28 bytes Signed-off-by: Denys Vlasenko --- console-tools/dumpkmap.c | 19 +++---------------- console-tools/resize.c | 2 ++ coreutils/cksum.c | 1 + coreutils/date.c | 1 + coreutils/stty.c | 1 + runit/sv.c | 10 ++++++++-- util-linux/umount.c | 2 ++ 7 files changed, 18 insertions(+), 18 deletions(-) (limited to 'runit') diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c index 5ffb0cddb..b803e579a 100644 --- a/console-tools/dumpkmap.c +++ b/console-tools/dumpkmap.c @@ -16,6 +16,7 @@ //config: stdout, in binary format. You can then use loadkmap to load it. //applet:IF_DUMPKMAP(APPLET_NOEXEC(dumpkmap, dumpkmap, BB_DIR_BIN, BB_SUID_DROP, dumpkmap)) +/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ //kbuild:lib-$(CONFIG_DUMPKMAP) += dumpkmap.o @@ -47,8 +48,6 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv) { struct kbentry ke; int i, j, fd; -#define flags bb_common_bufsiz1 - setup_common_bufsiz(); /* When user accidentally runs "dumpkmap FILE" * instead of "dumpkmap >FILE", we'd dump binary stuff to tty. @@ -60,19 +59,8 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv) fd = get_console_fd_or_die(); -#if 0 - write(STDOUT_FILENO, "bkeymap", 7); - /* Here we want to set everything to 0 except for indexes: - * [0-2] [4-6] [8-10] [12] - */ - /*memset(flags, 0x00, MAX_NR_KEYMAPS); - already is */ - memset(flags, 0x01, 13); - flags[3] = flags[7] = flags[11] = 0; - /* dump flags */ - write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS); -#define flags7 flags -#else - /* Same effect */ +#define flags bb_common_bufsiz1 + setup_common_bufsiz(); /* 0 1 2 3 4 5 6 7 8 9 a b c=12 */ memcpy(flags, "bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1", /* Can use sizeof, or sizeof-1. sizeof is even, using that */ @@ -80,7 +68,6 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv) ); write(STDOUT_FILENO, flags, 7 + MAX_NR_KEYMAPS); #define flags7 (flags + 7) -#endif for (i = 0; i < 13; i++) { if (flags7[i]) { diff --git a/console-tools/resize.c b/console-tools/resize.c index 97866673a..8aa487c41 100644 --- a/console-tools/resize.c +++ b/console-tools/resize.c @@ -24,6 +24,7 @@ //config: COLUMNS=80;LINES=44;export COLUMNS LINES; //applet:IF_RESIZE(APPLET_NOEXEC(resize, resize, BB_DIR_USR_BIN, BB_SUID_DROP, resize)) +/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ //kbuild:lib-$(CONFIG_RESIZE) += resize.o @@ -63,6 +64,7 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) */ tcgetattr(STDERR_FILENO, old_termios_p); /* fiddle echo */ +//TODO: die if the above fails? memcpy(&new, old_termios_p, sizeof(new)); new.c_cflag |= (CLOCAL | CREAD); new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); diff --git a/coreutils/cksum.c b/coreutils/cksum.c index c0cf65d2a..059a33310 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c @@ -13,6 +13,7 @@ //config: cksum is used to calculate the CRC32 checksum of a file. //applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) +/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ //kbuild:lib-$(CONFIG_CKSUM) += cksum.o diff --git a/coreutils/date.c b/coreutils/date.c index 89b281646..5a4ad5fe5 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -59,6 +59,7 @@ //config: MMDDhhmm[[YY]YY][.ss] format. //applet:IF_DATE(APPLET_NOEXEC(date, date, BB_DIR_BIN, BB_SUID_DROP, date)) +/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ //kbuild:lib-$(CONFIG_DATE) += date.o diff --git a/coreutils/stty.c b/coreutils/stty.c index 2292fa5ee..57e2cc30d 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -785,6 +785,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ G.device_name = bb_msg_standard_input; \ G.max_col = 80; \ G.current_col = 0; /* we are noexec, must clear */ \ diff --git a/runit/sv.c b/runit/sv.c index 0817ab472..630f1f37e 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -193,7 +193,7 @@ struct globals { /* "Bernstein" time format: unix + 0x400000000000000aULL */ uint64_t tstart, tnow; svstatus_t svstatus; - unsigned islog; + smallint islog; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define acts (G.acts ) @@ -203,7 +203,13 @@ struct globals { #define tnow (G.tnow ) #define svstatus (G.svstatus ) #define islog (G.islog ) -#define INIT_G() do { setup_common_bufsiz(); } while (0) +#define INIT_G() do { \ + setup_common_bufsiz(); \ + /* need to zero out, we are NOEXEC */ \ + rc = EXIT_SUCCESS; \ + islog = 0; \ + /* other fields need not be zero */ \ +} while (0) #define str_equal(s,t) (strcmp((s), (t)) == 0) diff --git a/util-linux/umount.c b/util-linux/umount.c index 33667b13c..a6405dfcc 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c @@ -35,6 +35,8 @@ * In this case, you might be actually happy if your standalone bbox shell * does not fork+exec, but only forks and calls umount_main() which it already has! * Let's go with NOEXEC. + * + * bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ //kbuild:lib-$(CONFIG_UMOUNT) += umount.o -- cgit v1.2.3-55-g6feb From 7389662dbf54463222d66e555368e0151098ab38 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Aug 2017 21:29:51 +0200 Subject: svc: remove superfluout INIT_G() function old new delta sv 1297 1296 -1 svc_main 162 145 -17 Signed-off-by: Denys Vlasenko --- runit/sv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'runit') diff --git a/runit/sv.c b/runit/sv.c index 630f1f37e..477c1ac6e 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -205,10 +205,8 @@ struct globals { #define islog (G.islog ) #define INIT_G() do { \ setup_common_bufsiz(); \ - /* need to zero out, we are NOEXEC */ \ - rc = EXIT_SUCCESS; \ - islog = 0; \ - /* other fields need not be zero */ \ + /* need to zero out, svc calls sv() repeatedly */ \ + memset(&G, 0, sizeof(G)); \ } while (0) @@ -707,8 +705,6 @@ int svc_main(int argc UNUSED_PARAM, char **argv) const char *optstring; unsigned opts; - INIT_G(); - optstring = "udopchaitkx"; opts = getopt32(argv, optstring); argv += optind; -- cgit v1.2.3-55-g6feb From 22542eca18e5807b72ddc78999f5101e33f17a53 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Aug 2017 21:55:02 +0200 Subject: getopt32: remove opt_complementary function old new delta vgetopt32 1318 1392 +74 runsvdir_main 703 713 +10 bb_make_directory 423 425 +2 collect_cpu 546 545 -1 opt_chars 3 - -3 opt_complementary 4 - -4 tftpd_main 567 562 -5 ntp_init 476 471 -5 zcip_main 1266 1256 -10 xxd_main 428 418 -10 whois_main 140 130 -10 who_main 463 453 -10 which_main 212 202 -10 wget_main 2535 2525 -10 watchdog_main 291 281 -10 watch_main 222 212 -10 vlock_main 399 389 -10 uuencode_main 332 322 -10 uudecode_main 316 306 -10 unlink_main 45 35 -10 udhcpd_main 1482 1472 -10 udhcpc_main 2762 2752 -10 tune2fs_main 290 280 -10 tunctl_main 366 356 -10 truncate_main 218 208 -10 tr_main 518 508 -10 time_main 1134 1124 -10 tftp_main 286 276 -10 telnetd_main 1873 1863 -10 tcpudpsvd_main 1785 1775 -10 taskset_main 521 511 -10 tar_main 1009 999 -10 tail_main 1644 1634 -10 syslogd_main 1967 1957 -10 switch_root_main 368 358 -10 svlogd_main 1454 1444 -10 sv 1296 1286 -10 stat_main 104 94 -10 start_stop_daemon_main 1028 1018 -10 split_main 542 532 -10 sort_main 796 786 -10 slattach_main 624 614 -10 shuf_main 504 494 -10 setsid_main 96 86 -10 setserial_main 1132 1122 -10 setfont_main 388 378 -10 setconsole_main 78 68 -10 sendmail_main 1209 1199 -10 sed_main 677 667 -10 script_main 1077 1067 -10 run_parts_main 325 315 -10 rtcwake_main 454 444 -10 rm_main 175 165 -10 reformime_main 119 109 -10 readlink_main 123 113 -10 rdate_main 246 236 -10 pwdx_main 189 179 -10 pstree_main 317 307 -10 pscan_main 663 653 -10 popmaildir_main 818 808 -10 pmap_main 80 70 -10 nc_main 1042 1032 -10 mv_main 558 548 -10 mountpoint_main 477 467 -10 mount_main 1264 1254 -10 modprobe_main 768 758 -10 modinfo_main 333 323 -10 mktemp_main 200 190 -10 mkswap_main 324 314 -10 mkfs_vfat_main 1489 1479 -10 microcom_main 715 705 -10 md5_sha1_sum_main 521 511 -10 man_main 867 857 -10 makedevs_main 1052 1042 -10 ls_main 563 553 -10 losetup_main 432 422 -10 loadfont_main 89 79 -10 ln_main 524 514 -10 link_main 75 65 -10 ipcalc_main 544 534 -10 iostat_main 2397 2387 -10 install_main 768 758 -10 id_main 480 470 -10 i2cset_main 1239 1229 -10 i2cget_main 380 370 -10 i2cdump_main 1482 1472 -10 i2cdetect_main 682 672 -10 hwclock_main 406 396 -10 httpd_main 741 731 -10 grep_main 837 827 -10 getty_main 1559 1549 -10 fuser_main 297 287 -10 ftpgetput_main 345 335 -10 ftpd_main 2232 2222 -10 fstrim_main 251 241 -10 fsfreeze_main 77 67 -10 fsck_minix_main 2921 2911 -10 flock_main 314 304 -10 flashcp_main 740 730 -10 flash_eraseall_main 833 823 -10 fdformat_main 532 522 -10 expand_main 680 670 -10 eject_main 335 325 -10 dumpleases_main 630 620 -10 du_main 314 304 -10 dos2unix_main 441 431 -10 diff_main 1350 1340 -10 df_main 1064 1054 -10 date_main 1095 1085 -10 cut_main 961 951 -10 cryptpw_main 228 218 -10 crontab_main 575 565 -10 crond_main 1149 1139 -10 cp_main 370 360 -10 common_traceroute_main 3834 3824 -10 common_ping_main 1767 1757 -10 comm_main 239 229 -10 cmp_main 655 645 -10 chrt_main 379 369 -10 chpst_main 704 694 -10 chpasswd_main 308 298 -10 chown_main 171 161 -10 chmod_main 158 148 -10 cat_main 428 418 -10 bzip2_main 120 110 -10 blkdiscard_main 264 254 -10 base64_main 221 211 -10 arping_main 1665 1655 -10 ar_main 556 546 -10 adjtimex_main 406 396 -10 adduser_main 882 872 -10 addgroup_main 411 401 -10 acpid_main 1198 1188 -10 optstring 11 - -11 opt_string 18 - -18 OPT_STR 25 - -25 ubi_tools_main 1288 1258 -30 ls_options 31 - -31 ------------------------------------------------------------------------------ (add/remove: 0/6 grow/shrink: 3/129 up/down: 86/-1383) Total: -1297 bytes text data bss dec hex filename 915428 485 6876 922789 e14a5 busybox_old 914629 485 6872 921986 e1182 busybox_unstripped Signed-off-by: Denys Vlasenko --- archival/ar.c | 11 +++--- archival/bzip2.c | 8 +++-- archival/dpkg_deb.c | 5 +-- archival/lzop.c | 2 +- archival/tar.c | 25 +++++++------- console-tools/loadfont.c | 6 ++-- console-tools/setconsole.c | 3 +- coreutils/cat.c | 8 +++-- coreutils/chmod.c | 3 +- coreutils/chown.c | 7 ++-- coreutils/comm.c | 3 +- coreutils/cp.c | 18 +++++----- coreutils/cut.c | 9 +++-- coreutils/date.c | 14 +++++--- coreutils/df.c | 15 +++++---- coreutils/dos2unix.c | 3 +- coreutils/du.c | 14 +++++--- coreutils/expand.c | 7 ++-- coreutils/id.c | 9 +++-- coreutils/install.c | 13 +++++--- coreutils/link.c | 3 +- coreutils/ln.c | 3 +- coreutils/ls.c | 60 +++++++++++++++++---------------- coreutils/md5_sha1_sum.c | 7 ++-- coreutils/mktemp.c | 3 +- coreutils/mv.c | 6 ++-- coreutils/readlink.c | 3 +- coreutils/rm.c | 3 +- coreutils/shuf.c | 7 ++-- coreutils/sort.c | 10 +++--- coreutils/split.c | 7 ++-- coreutils/stat.c | 8 +++-- coreutils/sync.c | 3 +- coreutils/tail.c | 8 +++-- coreutils/tr.c | 4 +-- coreutils/truncate.c | 3 +- coreutils/unlink.c | 3 +- coreutils/uudecode.c | 6 ++-- coreutils/uuencode.c | 3 +- coreutils/who.c | 3 +- debianutils/run_parts.c | 5 +-- debianutils/start_stop_daemon.c | 20 ++++++----- debianutils/which.c | 3 +- e2fsprogs/tune2fs.c | 3 +- editors/cmp.c | 10 +++--- editors/diff.c | 4 +-- editors/sed.c | 6 ++-- findutils/grep.c | 11 +++--- include/libbb.h | 3 -- libbb/getopt32.c | 74 ++++++++++++++++++++++------------------- libbb/parse_config.c | 5 +-- libbb/vfork_daemon_rexec.c | 3 -- loginutils/addgroup.c | 7 ++-- loginutils/adduser.c | 13 +++++--- loginutils/chpasswd.c | 6 ++-- loginutils/cryptpw.c | 7 ++-- loginutils/getty.c | 5 ++- loginutils/vlock.c | 3 +- mailutils/popmaildir.c | 6 ++-- mailutils/reformime.c | 6 ++-- mailutils/sendmail.c | 12 ++++--- miscutils/adjtimex.c | 7 ++-- miscutils/crond.c | 14 +++++--- miscutils/crontab.c | 5 +-- miscutils/flash_eraseall.c | 3 +- miscutils/flashcp.c | 3 +- miscutils/i2c_tools.c | 25 +++++++------- miscutils/makedevs.c | 3 +- miscutils/man.c | 3 +- miscutils/microcom.c | 5 +-- miscutils/nandwrite.c | 9 +++-- miscutils/setserial.c | 3 +- miscutils/time.c | 5 +-- miscutils/ubi_tools.c | 9 ++--- miscutils/watchdog.c | 5 +-- modutils/modinfo.c | 3 +- modutils/modprobe-small.c | 3 +- modutils/modprobe.c | 8 +++-- networking/arping.c | 6 ++-- networking/ether-wake.c | 3 +- networking/ftpd.c | 17 ++++++---- networking/ftpgetput.c | 7 ++-- networking/httpd.c | 10 +++--- networking/ipcalc.c | 7 ++-- networking/nc_bloaty.c | 14 +++++--- networking/ntpd.c | 9 ++--- networking/ping.c | 12 ++++--- networking/pscan.c | 7 ++-- networking/slattach.c | 5 +-- networking/tcpudp.c | 7 ++-- networking/telnetd.c | 10 +++--- networking/tftp.c | 15 +++++---- networking/traceroute.c | 6 ++-- networking/tunctl.c | 18 ++++++---- networking/udhcp/d6_dhcpc.c | 7 ++-- networking/udhcp/dhcpc.c | 10 +++--- networking/udhcp/dhcpd.c | 7 ++-- networking/udhcp/dumpleases.c | 8 +++-- networking/wget.c | 8 +++-- networking/whois.c | 3 +- networking/zcip.c | 5 +-- procps/fuser.c | 3 +- procps/iostat.c | 3 +- procps/pmap.c | 3 +- procps/ps.c | 8 +++-- procps/pstree.c | 3 +- procps/pwdx.c | 3 +- procps/watch.c | 6 ++-- runit/chpst.c | 7 ++-- runit/runsvdir.c | 3 +- runit/sv.c | 5 +-- runit/svlogd.c | 7 ++-- selinux/chcon.c | 11 +++--- selinux/matchpathcon.c | 10 ++++-- selinux/runcon.c | 9 +++-- selinux/sestatus.c | 3 +- selinux/setfiles.c | 20 +++++++---- sysklogd/syslogd.c | 3 +- util-linux/acpid.c | 8 +++-- util-linux/blkdiscard.c | 3 +- util-linux/chrt.c | 3 +- util-linux/eject.c | 5 +-- util-linux/fallocate.c | 3 +- util-linux/fdformat.c | 3 +- util-linux/flock.c | 3 +- util-linux/fsck_minix.c | 3 +- util-linux/fsfreeze.c | 5 +-- util-linux/fstrim.c | 5 +-- util-linux/hexdump_xxd.c | 5 +-- util-linux/hwclock.c | 7 ++-- util-linux/losetup.c | 3 +- util-linux/mkfs_reiser.c | 3 +- util-linux/mkfs_vfat.c | 5 +-- util-linux/mkswap.c | 3 +- util-linux/mount.c | 12 ++++--- util-linux/mountpoint.c | 3 +- util-linux/rdate.c | 3 +- util-linux/rtcwake.c | 6 ++-- util-linux/script.c | 6 ++-- util-linux/setsid.c | 4 +-- util-linux/switch_root.c | 5 ++- util-linux/taskset.c | 3 +- util-linux/unshare.c | 21 ++++++------ 143 files changed, 597 insertions(+), 502 deletions(-) (limited to 'runit') diff --git a/archival/ar.c b/archival/ar.c index 46c10aad4..027cd6b5a 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -243,10 +243,13 @@ int ar_main(int argc UNUSED_PARAM, char **argv) /* prepend '-' to the first argument if required */ if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') argv[1] = xasprintf("-%s", argv[1]); - /* -1: at least one param is reqd */ - /* one of p,t,x[,r] is required */ - opt_complementary = "-1:p:t:x"IF_FEATURE_AR_CREATE(":r"); - opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r")); + opt = getopt32(argv, "^" + "voc""ptx"IF_FEATURE_AR_CREATE("r") + "\0" + /* -1: at least one arg is reqd */ + /* one of p,t,x[,r] is required */ + "-1:p:t:x"IF_FEATURE_AR_CREATE(":r") + ); argv += optind; t = opt / FIRST_CMD; diff --git a/archival/bzip2.c b/archival/bzip2.c index 0b9c508df..d578eb7ad 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c @@ -195,9 +195,11 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv) * --best alias for -9 */ - opt_complementary = "s2"; /* -s means -2 (compatibility) */ - /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ - opt = getopt32(argv, "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs"); + opt = getopt32(argv, "^" + /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ + "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs" + "\0" "s2" /* -s means -2 (compatibility) */ + ); #if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */ if (opt & 0x30) // -d and/or -t return bunzip2_main(argc, argv); diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 029bc4af1..f6bf9eb04 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -80,8 +80,9 @@ int dpkg_deb_main(int argc UNUSED_PARAM, char **argv) #endif /* Must have 1 or 2 args */ - opt_complementary = "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; - opt = getopt32(argv, "cefXx"); + opt = getopt32(argv, "^" "cefXx" + "\0" "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX" + ); argv += optind; //argc -= optind; diff --git a/archival/lzop.c b/archival/lzop.c index df18ff170..1bf954f4f 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -1138,7 +1138,7 @@ int lzop_main(int argc UNUSED_PARAM, char **argv) /* -U is "anti -k", invert bit for bbunpack(): */ option_mask32 ^= OPT_KEEP; /* -k disables -U (if any): */ - /* opt_complementary = "k-U"; - nope, only handles -Uk, not -kU */ + /* opt_complementary "k-U"? - nope, only handles -Uk, not -kU */ if (option_mask32 & OPT_k) option_mask32 |= OPT_KEEP; diff --git a/archival/tar.c b/archival/tar.c index 44ab246c0..73c14ca81 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -973,18 +973,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv) /* Prepend '-' to the first argument if required */ if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') argv[1] = xasprintf("-%s", argv[1]); - opt_complementary = - "tt:vv:" // count -t,-v -#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM - "\xff::" // --exclude=PATTERN is a list -#endif - IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd - IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive - IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive -#if ENABLE_FEATURE_TAR_LONG_OPTIONS - ":\xf9+" // --strip-components=NUM -#endif - ; #if ENABLE_DESKTOP /* Lie to buildroot when it starts asking stupid questions. */ if (argv[1] && strcmp(argv[1], "--version") == 0) { @@ -1021,7 +1009,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) } } #endif - opt = GETOPT32(argv, + opt = GETOPT32(argv, "^" "txC:f:Oopvk" IF_FEATURE_TAR_CREATE( "ch" ) IF_FEATURE_SEAMLESS_BZ2( "j" ) @@ -1032,6 +1020,17 @@ int tar_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_SEAMLESS_Z( "Z" ) IF_FEATURE_TAR_NOPRESERVE_TIME("m") IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components + "\0" + "tt:vv:" // count -t,-v +#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM + "\xff::" // --exclude=PATTERN is a list +#endif + IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd + IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive + IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive +#if ENABLE_FEATURE_TAR_LONG_OPTIONS + ":\xf9+" // --strip-components=NUM +#endif LONGOPTS , &base_dir // -C dir , &tar_filename // -f filename diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c index 623d98175..81d0c3db4 100644 --- a/console-tools/loadfont.c +++ b/console-tools/loadfont.c @@ -348,8 +348,7 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv) unsigned char *buffer; // no arguments allowed! - opt_complementary = "=0"; - getopt32(argv, ""); + getopt32(argv, "^" "" "\0" "=0"); /* * We used to look at the length of the input file @@ -437,8 +436,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv) char *mapfilename; const char *tty_name = CURRENT_TTY; - opt_complementary = "=1"; - opts = getopt32(argv, "m:C:", &mapfilename, &tty_name); + opts = getopt32(argv, "^" "m:C:" "\0" "=1", &mapfilename, &tty_name); argv += optind; fd = xopen_nonblocking(tty_name); diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c index 8f4b7b7a6..bad2b76e4 100644 --- a/console-tools/setconsole.c +++ b/console-tools/setconsole.c @@ -47,8 +47,7 @@ int setconsole_main(int argc UNUSED_PARAM, char **argv) int reset; /* at most one non-option argument */ - opt_complementary = "?1"; - reset = getopt32(argv, "r"); + reset = getopt32(argv, "^" "r" "\0" "?1"); argv += 1 + reset; if (*argv) { diff --git a/coreutils/cat.c b/coreutils/cat.c index 390254512..7e35fa5ee 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c @@ -170,9 +170,11 @@ int cat_main(int argc UNUSED_PARAM, char **argv) { unsigned opts; - IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) - /* -u is ignored ("unbuffered") */ - opts = getopt32(argv, IF_FEATURE_CATV("etvA") IF_FEATURE_CATN("nb") "u"); + opts = getopt32(argv, IF_FEATURE_CATV("^") + /* -u is ignored ("unbuffered") */ + IF_FEATURE_CATV("etvA")IF_FEATURE_CATN("nb")"u" + IF_FEATURE_CATV("\0" "Aetv" /* -A == -vet */) + ); argv += optind; /* Read from stdin if there's nothing else to do. */ diff --git a/coreutils/chmod.c b/coreutils/chmod.c index 2174334d1..88989bf67 100644 --- a/coreutils/chmod.c +++ b/coreutils/chmod.c @@ -123,8 +123,7 @@ int chmod_main(int argc UNUSED_PARAM, char **argv) } /* Parse options */ - opt_complementary = "-2"; - getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */ + getopt32(argv, "^" OPT_STR "\0" "-2"); argv += optind; /* Restore option-like mode if needed */ diff --git a/coreutils/chown.c b/coreutils/chown.c index 0c77529ec..985d18d6f 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -55,7 +55,7 @@ /* This is a NOEXEC applet. Be very careful! */ -#define OPT_STR ("Rh" IF_DESKTOP("vcfLHP")) +#define OPT_STR "Rh" IF_DESKTOP("vcfLHP") #define BIT_RECURSE 1 #define OPT_RECURSE (opt & 1) #define OPT_NODEREF (opt & 2) @@ -127,11 +127,10 @@ int chown_main(int argc UNUSED_PARAM, char **argv) int opt, flags; struct param_t param; - opt_complementary = "-2"; #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS - opt = getopt32long(argv, OPT_STR, chown_longopts); + opt = getopt32long(argv, "^" OPT_STR "\0" "=2", chown_longopts); #else - opt = getopt32(argv, OPT_STR); + opt = getopt32(argv, "^" OPT_STR "\0" "=2"); #endif argv += optind; diff --git a/coreutils/comm.c b/coreutils/comm.c index 5be11468c..4bee77677 100644 --- a/coreutils/comm.c +++ b/coreutils/comm.c @@ -62,8 +62,7 @@ int comm_main(int argc UNUSED_PARAM, char **argv) int i; int order; - opt_complementary = "=2"; - getopt32(argv, "123"); + getopt32(argv, "^" "123" "\0" "=2"); argv += optind; for (i = 0; i < 2; ++i) { diff --git a/coreutils/cp.c b/coreutils/cp.c index fe408950a..5b34c27e7 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -73,15 +73,17 @@ int cp_main(int argc, char **argv) #endif }; - // Need at least two arguments - // Soft- and hardlinking doesn't mix - // -P and -d are the same (-P is POSIX, -d is GNU) - // -r and -R are the same - // -R (and therefore -r) turns on -d (coreutils does this) - // -a = -pdR - opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR"; #if ENABLE_FEATURE_CP_LONG_OPTIONS - flags = getopt32long(argv, FILEUTILS_CP_OPTSTR, + flags = getopt32long(argv, "^" + FILEUTILS_CP_OPTSTR + "\0" + // Need at least two arguments + // Soft- and hardlinking doesn't mix + // -P and -d are the same (-P is POSIX, -d is GNU) + // -r and -R are the same + // -R (and therefore -r) turns on -d (coreutils does this) + // -a = -pdR + "-2:l--s:s--l:Pd:rRd:Rd:apdR", "archive\0" No_argument "a" "force\0" No_argument "f" "interactive\0" No_argument "i" diff --git a/coreutils/cut.c b/coreutils/cut.c index 6578ce8ce..cdd90ab44 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c @@ -42,7 +42,7 @@ /* option vars */ -static const char optstring[] ALIGN1 = "b:c:f:d:sn"; +#define OPT_STR "b:c:f:d:sn" #define CUT_OPT_BYTE_FLGS (1 << 0) #define CUT_OPT_CHAR_FLGS (1 << 1) #define CUT_OPT_FIELDS_FLGS (1 << 2) @@ -201,8 +201,11 @@ int cut_main(int argc UNUSED_PARAM, char **argv) char *sopt, *ltok; unsigned opt; - opt_complementary = "b--bcf:c--bcf:f--bcf"; - opt = getopt32(argv, optstring, &sopt, &sopt, &sopt, <ok); + opt = getopt32(argv, "^" + OPT_STR + "\0" "b--bcf:c--bcf:f--bcf", + &sopt, &sopt, &sopt, <ok + ); // argc -= optind; argv += optind; if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) diff --git a/coreutils/date.c b/coreutils/date.c index 33f210434..5b15ce778 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -192,12 +192,16 @@ int date_main(int argc UNUSED_PARAM, char **argv) char *filename; char *isofmt_arg = NULL; - opt_complementary = "d--s:s--d" - IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); - opt = getopt32long(argv, "Rs:ud:r:" - IF_FEATURE_DATE_ISOFMT("I::D:"), date_longopts, + opt = getopt32long(argv, "^" + "Rs:ud:r:" + IF_FEATURE_DATE_ISOFMT("I::D:") + "\0" + "d--s:s--d" + IF_FEATURE_DATE_ISOFMT(":R--I:I--R"), + date_longopts, &date_str, &date_str, &filename - IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); + IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt) + ); argv += optind; maybe_set_utc(opt); diff --git a/coreutils/df.c b/coreutils/df.c index 4d6534bc2..121da970b 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -115,15 +115,18 @@ int df_main(int argc UNUSED_PARAM, char **argv) init_unicode(); + opt = getopt32(argv, "^" + "kPT" + IF_FEATURE_DF_FANCY("aiB:") + IF_FEATURE_HUMAN_READABLE("hm") + "\0" #if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY - opt_complementary = "k-mB:m-Bk:B-km"; + "k-mB:m-Bk:B-km" #elif ENABLE_FEATURE_HUMAN_READABLE - opt_complementary = "k-m:m-k"; + "k-m:m-k" #endif - opt = getopt32(argv, "kPT" - IF_FEATURE_DF_FANCY("aiB:") - IF_FEATURE_HUMAN_READABLE("hm") - IF_FEATURE_DF_FANCY(, &chp)); + IF_FEATURE_DF_FANCY(, &chp) + ); if (opt & OPT_MEGA) df_disp_hr = 1024*1024; diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index a3d008051..9f098e41e 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c @@ -120,8 +120,7 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv) } /* -u convert to unix, -d convert to dos */ - opt_complementary = "u--d:d--u"; /* mutually exclusive */ - o = getopt32(argv, "du"); + o = getopt32(argv, "^" "du" "\0" "u--d:d--u"); /* mutually exclusive */ /* Do the conversion requested by an argument else do the default * conversion depending on our name. */ diff --git a/coreutils/du.c b/coreutils/du.c index 947c46e74..d5ce46cf2 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -242,8 +242,11 @@ int du_main(int argc UNUSED_PARAM, char **argv) * ignore -a. This is consistent with -s being equivalent to -d 0. */ #if ENABLE_FEATURE_HUMAN_READABLE - opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; - opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth); + opt = getopt32(argv, "^" + "aHkLsxd:+lchm" + "\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s", + &G.max_print_depth + ); argv += optind; if (opt & OPT_h_for_humans) { G.disp_unit = 0; @@ -255,8 +258,11 @@ int du_main(int argc UNUSED_PARAM, char **argv) G.disp_unit = 1024; } #else - opt_complementary = "H-L:L-H:s-d:d-s"; - opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth); + opt = getopt32(argv, "^" + "aHkLsxd:+lc" + "\0" "H-L:L-H:s-d:d-s", + &G.max_print_depth + ); argv += optind; #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K if (opt & OPT_k_kbytes) { diff --git a/coreutils/expand.c b/coreutils/expand.c index fa3ff18f4..91084b80b 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c @@ -174,9 +174,10 @@ int expand_main(int argc UNUSED_PARAM, char **argv) , &opt_t ); } else { - /* -t NUM sets also -a */ - opt_complementary = "ta"; - opt = getopt32long(argv, "ft:a", + opt = getopt32long(argv, "^" + "ft:a" + "\0" + "ta" /* -t NUM sets -a */, "first-only\0" No_argument "i" "tabs\0" Required_argument "t" "all\0" No_argument "a" diff --git a/coreutils/id.c b/coreutils/id.c index 6043bca61..5a7fb9aaf 100644 --- a/coreutils/id.c +++ b/coreutils/id.c @@ -170,9 +170,12 @@ int id_main(int argc UNUSED_PARAM, char **argv) } else { /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ /* Don't allow more than one username */ - opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" - IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); - opt = getopt32(argv, "rnugG" IF_SELINUX("Z")); + opt = getopt32(argv, "^" + "rnugG" IF_SELINUX("Z") + "\0" + "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" + IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G") + ); } username = argv[optind]; diff --git a/coreutils/install.c b/coreutils/install.c index c01750f81..2e4dc257f 100644 --- a/coreutils/install.c +++ b/coreutils/install.c @@ -140,13 +140,16 @@ int install_main(int argc, char **argv) #endif }; - opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); /* -c exists for backwards compatibility, it's needed */ /* -b is ignored ("make a backup of each existing destination file") */ - opts = GETOPT32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), - LONGOPTS - &gid_str, &mode_str, &uid_str, &last - IF_SELINUX(, &scontext) + opts = GETOPT32(argv, "^" + "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:") + "\0" + "t--d:d--t:s--d:d--s" + IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")), + LONGOPTS + &gid_str, &mode_str, &uid_str, &last + IF_SELINUX(, &scontext) ); argc -= optind; argv += optind; diff --git a/coreutils/link.c b/coreutils/link.c index 6e20dafe3..81808b778 100644 --- a/coreutils/link.c +++ b/coreutils/link.c @@ -27,8 +27,7 @@ int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int link_main(int argc UNUSED_PARAM, char **argv) { - opt_complementary = "=2"; /* exactly 2 params */ - getopt32(argv, ""); + getopt32(argv, "^" "" "\0" "=2"); argv += optind; if (link(argv[0], argv[1]) != 0) { /* shared message */ diff --git a/coreutils/ln.c b/coreutils/ln.c index fed96af42..2dda5dae9 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c @@ -62,8 +62,7 @@ int ln_main(int argc, char **argv) struct stat statbuf; int (*link_func)(const char *, const char *); - opt_complementary = "-1"; /* min one arg */ - opts = getopt32(argv, "sfnbS:vT", &suffix); + opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix); last = argv[argc - 1]; argv += optind; diff --git a/coreutils/ls.c b/coreutils/ls.c index 0834cdc63..af5e6cb51 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -206,18 +206,18 @@ SPLIT_SUBDIR = 2, /* -SXvhTw GNU options, busybox optionally supports */ /* -T WIDTH Ignored (we don't use tabs on output) */ /* -Z SELinux mandated option, busybox optionally supports */ -static const char ls_options[] ALIGN1 = - "Cadi1lgnsxAk" /* 12 opts, total 12 */ - IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ - IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ - IF_SELINUX("Z") /* 1, 16 */ - "Q" /* 1, 17 */ - IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ - IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ - IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ - IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ +#define ls_options \ + "Cadi1lgnsxAk" /* 12 opts, total 12 */ \ + IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ \ + IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ \ + IF_SELINUX("Z") /* 1, 16 */ \ + "Q" /* 1, 17 */ \ + IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ \ + IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ \ + IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ \ + IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ \ IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */ -; + enum { OPT_C = (1 << 0), OPT_a = (1 << 1), @@ -1093,24 +1093,26 @@ int ls_main(int argc UNUSED_PARAM, char **argv) #endif /* process options */ - opt_complementary = - /* -n and -g imply -l */ - "nl:gl" - /* --full-time implies -l */ - IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) - /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: - * in some pairs of opts, only last one takes effect: - */ - IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ - // ":m-l:l-m" - we don't have -m - IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") - ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ - ":C-1:1-C" /* bycols/oneline */ - ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ - IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ - /* -w NUM: */ - IF_FEATURE_LS_WIDTH(":w+"); - opt = getopt32long(argv, ls_options, ls_longopts + opt = getopt32long(argv, "^" + ls_options + "\0" + /* -n and -g imply -l */ + "nl:gl" + /* --full-time implies -l */ + IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) + /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: + * in some pairs of opts, only last one takes effect: + */ + IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ + // ":m-l:l-m" - we don't have -m + IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") + ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ + ":C-1:1-C" /* bycols/oneline */ + ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ + IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ + /* -w NUM: */ + IF_FEATURE_LS_WIDTH(":w+") + , ls_longopts IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) IF_FEATURE_LS_COLOR(, &color_opt) ); diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index bcccdd64f..89d6cec0b 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c @@ -258,15 +258,14 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) #endif if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { - /* -s and -w require -c */ - opt_complementary = "s?c:w?c"; /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ + /* -s and -w require -c */ #if ENABLE_SHA3SUM if (applet_name[3] == HASH_SHA3) - flags = getopt32(argv, "scwbta:+", &sha3_width); + flags = getopt32(argv, "^" "scwbta:+" "\0" "s?c:w?c", &sha3_width); else #endif - flags = getopt32(argv, "scwbt"); + flags = getopt32(argv, "^" "scwbt" "\0" "s?c:w?c"); } else { #if ENABLE_SHA3SUM if (applet_name[3] == HASH_SHA3) diff --git a/coreutils/mktemp.c b/coreutils/mktemp.c index 944eb0e06..d4ff883fa 100644 --- a/coreutils/mktemp.c +++ b/coreutils/mktemp.c @@ -80,8 +80,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) if (!path || path[0] == '\0') path = "/tmp"; - opt_complementary = "?1"; /* 1 argument max */ - opts = getopt32(argv, "dqtp:u", &path); + opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path); chp = argv[optind]; if (!chp) { diff --git a/coreutils/mv.c b/coreutils/mv.c index 7f6e9fef5..10cbc506f 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c @@ -55,8 +55,10 @@ int mv_main(int argc, char **argv) * If more than one of -f, -i, -n is specified , only the final one * takes effect (it unsets previous options). */ - opt_complementary = "-2:f-in:i-fn:n-fi"; - flags = getopt32long(argv, "finv", + flags = getopt32long(argv, "^" + "finv" + "\0" + "-2:f-in:i-fn:n-fi", "interactive\0" No_argument "i" "force\0" No_argument "f" "no-clobber\0" No_argument "n" diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 7f8d6b239..b8e327d11 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c @@ -71,8 +71,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_READLINK_FOLLOW( unsigned opt; /* We need exactly one non-option argument. */ - opt_complementary = "=1"; - opt = getopt32(argv, "fnvsq"); + opt = getopt32(argv, "^" "fnvsq" "\0" "=1"); fname = argv[optind]; ) IF_NOT_FEATURE_READLINK_FOLLOW( diff --git a/coreutils/rm.c b/coreutils/rm.c index 5e4acab8c..b68a82dc4 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -46,8 +46,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv) int flags = 0; unsigned opt; - opt_complementary = "f-i:i-f"; - opt = getopt32(argv, "fiRrv"); + opt = getopt32(argv, "^" "fiRrv" "\0" "f-i:i-f"); argv += optind; if (opt & 1) flags |= FILEUTILS_FORCE; diff --git a/coreutils/shuf.c b/coreutils/shuf.c index 403041534..d0caaa2ce 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c @@ -70,8 +70,11 @@ int shuf_main(int argc, char **argv) unsigned numlines; char eol; - opt_complementary = "e--i:i--e"; /* mutually exclusive */ - opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str); + opts = getopt32(argv, "^" + OPT_STR + "\0" "e--i:i--e"/* mutually exclusive */, + &opt_i_str, &opt_n_str, &opt_o_str + ); argc -= optind; argv += optind; diff --git a/coreutils/sort.c b/coreutils/sort.c index 9860dca64..ceea24491 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -94,7 +94,7 @@ */ /* These are sort types */ -static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:"; +#define OPT_STR "ngMucszbrdfimS:T:o:k:*t:" enum { FLAG_n = 1, /* Numeric sort */ FLAG_g = 2, /* Sort using strtod() */ @@ -378,9 +378,11 @@ int sort_main(int argc UNUSED_PARAM, char **argv) xfunc_error_retval = 2; /* Parse command line options */ - /* -o and -t can be given at most once */ - opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */ - opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); + opts = getopt32(argv, "^" + OPT_STR + "\0" "o--o:t--t"/*-t, -o: at most one of each*/, + &str_ignored, &str_ignored, &str_o, &lst_k, &str_t + ); /* global b strips leading and trailing spaces */ if (opts & FLAG_b) option_mask32 |= FLAG_bb; diff --git a/coreutils/split.c b/coreutils/split.c index d0c63573a..4e1db190c 100644 --- a/coreutils/split.c +++ b/coreutils/split.c @@ -100,8 +100,11 @@ int split_main(int argc UNUSED_PARAM, char **argv) setup_common_bufsiz(); - opt_complementary = "?2"; /* max 2 args; -a N */ - opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len); + opt = getopt32(argv, "^" + "l:b:a:+" /* -a N */ + "\0" "?2"/*max 2 args*/, + &count_p, &count_p, &suffix_len + ); if (opt & SPLIT_OPT_l) cnt = XATOOFF(count_p); diff --git a/coreutils/stat.c b/coreutils/stat.c index 4e926a908..dafbd4e9f 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -762,11 +762,13 @@ int stat_main(int argc UNUSED_PARAM, char **argv) unsigned opts; statfunc_ptr statfunc = do_stat; - opt_complementary = "-1"; /* min one arg */ - opts = getopt32(argv, "tL" + opts = getopt32(argv, "^" + "tL" IF_FEATURE_STAT_FILESYSTEM("f") IF_SELINUX("Z") - IF_FEATURE_STAT_FORMAT("c:", &format) + IF_FEATURE_STAT_FORMAT("c:") + "\0" "-1" /* min one arg */ + IF_FEATURE_STAT_FORMAT(,&format) ); #if ENABLE_FEATURE_STAT_FILESYSTEM if (opts & OPT_FILESYS) /* -f */ diff --git a/coreutils/sync.c b/coreutils/sync.c index 66445281a..9be47ab64 100644 --- a/coreutils/sync.c +++ b/coreutils/sync.c @@ -59,8 +59,7 @@ int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) OPT_SYNCFS = (1 << 1), }; - opt_complementary = "d--f:f--d"; - opts = getopt32(argv, "df"); + opts = getopt32(argv, "^" "df" "\0" "d--f:f--d"); argv += optind; /* Handle the no-argument case. */ diff --git a/coreutils/tail.c b/coreutils/tail.c index fd310f422..7335ba11e 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -140,9 +140,11 @@ int tail_main(int argc, char **argv) #endif /* -s NUM, -F imlies -f */ - IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";) - opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"), - &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); + opt = getopt32(argv, IF_FEATURE_FANCY_TAIL("^") + "fc:n:"IF_FEATURE_FANCY_TAIL("qs:+vF") + IF_FEATURE_FANCY_TAIL("\0" "Ff"), + &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period) + ); #define FOLLOW (opt & 0x1) #define COUNT_BYTES (opt & 0x2) //if (opt & 0x1) // -f diff --git a/coreutils/tr.c b/coreutils/tr.c index 64e4efc91..c5872434a 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -298,8 +298,8 @@ int tr_main(int argc UNUSED_PARAM, char **argv) * In POSIX locale, these are the same. */ - opt_complementary = "-1"; - opts = getopt32(argv, "+Ccds"); /* '+': stop at first non-option */ + /* '+': stop at first non-option */ + opts = getopt32(argv, "^+" "Ccds" "\0" "-1"); argv += optind; str1_length = expand(*argv++, &str1); diff --git a/coreutils/truncate.c b/coreutils/truncate.c index f67abaf40..f693570aa 100644 --- a/coreutils/truncate.c +++ b/coreutils/truncate.c @@ -50,8 +50,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv) OPT_SIZE = (1 << 1), }; - opt_complementary = "s:-1"; - opts = getopt32(argv, "cs:", &size_str); + opts = getopt32(argv, "^" "cs:" "\0" "s:-1", &size_str); if (!(opts & OPT_NOCREATE)) flags |= O_CREAT; diff --git a/coreutils/unlink.c b/coreutils/unlink.c index e32a9743c..56309b1c7 100644 --- a/coreutils/unlink.c +++ b/coreutils/unlink.c @@ -25,8 +25,7 @@ int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int unlink_main(int argc UNUSED_PARAM, char **argv) { - opt_complementary = "=1"; /* must have exactly 1 param */ - getopt32(argv, ""); + getopt32(argv, "^" "" "\0" "=1"); argv += optind; xunlink(argv[0]); return 0; diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 4e72e86ee..5ef05ee4d 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c @@ -120,8 +120,7 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv) char *outname = NULL; char *line; - opt_complementary = "?1"; /* 1 argument max */ - getopt32(argv, "o:", &outname); + getopt32(argv, "^" "o:" "\0" "?1"/* 1 arg max*/, &outname); argv += optind; if (!argv[0]) @@ -196,8 +195,7 @@ int base64_main(int argc UNUSED_PARAM, char **argv) FILE *src_stream; unsigned opts; - opt_complementary = "?1"; /* 1 argument max */ - opts = getopt32(argv, "d"); + opts = getopt32(argv, "^" "d" "\0" "?1"/* 1 arg max*/); argv += optind; if (!argv[0]) diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c index 7164f838a..d6e077430 100644 --- a/coreutils/uuencode.c +++ b/coreutils/uuencode.c @@ -49,8 +49,7 @@ int uuencode_main(int argc UNUSED_PARAM, char **argv) tbl = bb_uuenc_tbl_std; mode = 0666 & ~umask(0666); - opt_complementary = "-1:?2"; /* must have 1 or 2 args */ - if (getopt32(argv, "m")) { + if (getopt32(argv, "^" "m" "\0" "-1:?2"/*must have 1 or 2 args*/)) { tbl = bb_uuenc_tbl_base64; } argv += optind; diff --git a/coreutils/who.c b/coreutils/who.c index 6be3d692e..cfe0c921e 100644 --- a/coreutils/who.c +++ b/coreutils/who.c @@ -117,8 +117,7 @@ int who_main(int argc UNUSED_PARAM, char **argv) unsigned opt; const char *fmt = "%s"; - opt_complementary = "=0"; - opt = getopt32(argv, do_who ? "aH" : ""); + opt = getopt32(argv, do_who ? "^" "aH" "\0" "=0": "^" "" "\0" "=0"); if ((opt & 2) || do_w) /* -H or we are w */ puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index b770383c4..e4d61df35 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -181,8 +181,9 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv) INIT_G(); /* We require exactly one argument: the directory name */ - opt_complementary = "=1"; - GETOPT32(argv, "a:*u:" LONGOPTS, &arg_list, &umask_p); + GETOPT32(argv, "^" "a:*u:" "\0" "=1" LONGOPTS, + &arg_list, &umask_p + ); umask(xstrtou_range(umask_p, 8, 0, 07777)); diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 45c277a53..12cf6c3a5 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -451,15 +451,17 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - /* -K or -S is required; they are mutually exclusive */ - /* -p is required if -m is given */ - /* -xpun (at least one) is required if -K is given */ - /* -xa (at least one) is required if -S is given */ - /* -q turns off -v */ - opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa" - IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"); - opt = GETOPT32(argv, "KSbqtma:n:s:u:c:x:p:" - IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), + opt = GETOPT32(argv, "^" + "KSbqtma:n:s:u:c:x:p:" + IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:") + /* -K or -S is required; they are mutually exclusive */ + /* -p is required if -m is given */ + /* -xpun (at least one) is required if -K is given */ + /* -xa (at least one) is required if -S is given */ + /* -q turns off -v */ + "\0" + "K:S:K--S:S--K:m?p:K?xpun:S?xa" + IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"), LONGOPTS &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) diff --git a/debianutils/which.c b/debianutils/which.c index b31d61871..3bd54ac42 100644 --- a/debianutils/which.c +++ b/debianutils/which.c @@ -37,8 +37,7 @@ int which_main(int argc UNUSED_PARAM, char **argv) if (!env_path) env_path = bb_default_root_path; - opt_complementary = "-1"; /* at least one argument */ - getopt32(argv, "a"); + getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); argv += optind; do { diff --git a/e2fsprogs/tune2fs.c b/e2fsprogs/tune2fs.c index 9f14b26ec..a1caf011c 100644 --- a/e2fsprogs/tune2fs.c +++ b/e2fsprogs/tune2fs.c @@ -71,8 +71,7 @@ int tune2fs_main(int argc UNUSED_PARAM, char **argv) struct ext2_super_block *sb; int fd; - opt_complementary = "=1"; - opts = getopt32(argv, "L:c:i:C:", &label, &str_c, &str_i, &str_C); + opts = getopt32(argv, "^" "L:c:i:C:" "\0" "=1", &label, &str_c, &str_i, &str_C); if (!opts) bb_show_usage(); argv += optind; // argv[0] -- device diff --git a/editors/cmp.c b/editors/cmp.c index f53d9603c..ec86c0ce2 100644 --- a/editors/cmp.c +++ b/editors/cmp.c @@ -36,7 +36,7 @@ static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"u, line %u // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; -static const char opt_chars[] ALIGN1 = "sl"; +#define OPT_STR "sl" #define CMP_OPT_s (1<<0) #define CMP_OPT_l (1<<1) @@ -52,11 +52,13 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) unsigned opt; int retval = 0; - opt_complementary = "-1" + opt = getopt32(argv, "^" + OPT_STR + "\0" "-1" IF_DESKTOP(":?4") IF_NOT_DESKTOP(":?2") - ":l--s:s--l"; - opt = getopt32(argv, opt_chars); + ":l--s:s--l" + ); argv += optind; filename1 = *argv; diff --git a/editors/diff.c b/editors/diff.c index d90ac8f94..2f254575c 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -984,8 +984,8 @@ int diff_main(int argc UNUSED_PARAM, char **argv) INIT_G(); /* exactly 2 params; collect multiple -L