aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-03 19:00:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-03 19:03:32 +0200
commit39194f030918b87eeb3e11e94cfa05f575fb47b4 (patch)
tree97ea35e2c5984c5c6757ff9a540630ada4b234d5
parent663ae52676eae3b0fdc6bb968ff6497279a034a4 (diff)
downloadbusybox-w32-39194f030918b87eeb3e11e94cfa05f575fb47b4.tar.gz
busybox-w32-39194f030918b87eeb3e11e94cfa05f575fb47b4.tar.bz2
busybox-w32-39194f030918b87eeb3e11e94cfa05f575fb47b4.zip
new NOFORKs: pwdx,kill[all5],ttysize,realpath,readlink NOEXECs: date,resize
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>
-rw-r--r--NOFORK_NOEXEC.lst140
-rw-r--r--console-tools/resize.c2
-rw-r--r--coreutils/date.c21
-rw-r--r--coreutils/readlink.c7
-rw-r--r--coreutils/realpath.c3
-rw-r--r--docs/nofork_noexec.txt2
-rw-r--r--libbb/bb_pwd.c3
-rw-r--r--libbb/vfork_daemon_rexec.c6
-rw-r--r--miscutils/ttysize.c2
-rw-r--r--procps/kill.c10
-rw-r--r--procps/pwdx.c3
11 files changed, 106 insertions, 93 deletions
diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst
index 02eba46e8..7073611a4 100644
--- a/NOFORK_NOEXEC.lst
+++ b/NOFORK_NOEXEC.lst
@@ -1,11 +1,10 @@
1Why an applet can't be NOFORK or NOEXEC? 1Why an applet can't be NOFORK or NOEXEC?
2 2
3Why can't be NOFORK: 3Why can't be NOFORK:
4daemon: runs indefinitely
5interactive: may wait for user input, ^C has to work 4interactive: may wait for user input, ^C has to work
6spawner: "tool PROG ARGS" which changes program's environment - must fork 5spawner: "tool PROG ARGS" which changes program's environment - must fork
7changes state: e.g. environment, signal handlers 6changes state: e.g. environment, signal handlers
8runner: sometimes may run for long time, and/or works with network: 7runner: sometimes may run for long(ish) time, and/or works with network:
9 ^C has to work (cat BIGFILE, chmod -R, ftpget, nc) 8 ^C has to work (cat BIGFILE, chmod -R, ftpget, nc)
10 9
11"runners" can become eligible after hush is taught ^C to interrupt NOFORKs! 10"runners" can become eligible after hush is taught ^C to interrupt NOFORKs!
@@ -15,9 +14,12 @@ suid: runs under different uid - must fork+exec
15 14
16Why shouldn't be NOFORK/NOEXEC: 15Why shouldn't be NOFORK/NOEXEC:
17complex: no immediately obvious reason why NOFORK wouldn't work, 16complex: no immediately obvious reason why NOFORK wouldn't work,
18 but does some non-obvoius operations (example: fuser, lsof, losetup). 17 but does some non-obvoius operations (example: fuser, lsof, losetup);
19 for NOFORK, nested xmallocs (typical in complex code) is a problem. 18 nested xmallocs (typical in complex code) is a problem for NOFORK
20rare: not used often enough to bother optimizing (example: poweroff) 19rare: not used often enough to bother optimizing (example: poweroff)
20longterm: often runs for a long time (many seconds), execing would make
21 memory footprint smaller
22daemon: runs indefinitely
21 23
22[ - NOFORK 24[ - NOFORK
23[[ - NOFORK 25[[ - NOFORK
@@ -31,7 +33,7 @@ arch - NOFORK
31arp 33arp
32arping - runner 34arping - runner
33ash - interactive 35ash - interactive
34awk - noexec, runner 36awk - noexec. runner
35base64 - runner 37base64 - runner
36basename - NOFORK 38basename - NOFORK
37beep 39beep
@@ -44,63 +46,63 @@ bunzip2 - runner
44busybox 46busybox
45bzcat - runner 47bzcat - runner
46bzip2 - runner 48bzip2 - runner
47cal 49cal - runner: cal -n9999
48cat - runner 50cat - runner
49chat 51chat
50chattr - runner 52chattr - runner
51chgrp - noexec, runner 53chgrp - noexec. runner
52chmod - noexec, runner 54chmod - noexec. runner
53chown - noexec, runner 55chown - noexec. runner
54chpasswd - runner (list of "user:password"s from stdin) 56chpasswd - runner (list of "user:password"s from stdin)
55chpst - spawner 57chpst - spawner
56chroot - spawner 58chroot - spawner
57chrt - spawner 59chrt - spawner
58chvt 60chvt
59cksum - noexec, runner 61cksum - noexec. runner
60clear - NOFORK 62clear - NOFORK
61cmp - runner 63cmp - runner
62comm - runner 64comm - runner
63conspy - interactive 65conspy - interactive
64cp - noexec, runner 66cp - noexec. runner
65cpio - runner 67cpio - runner
66crond - daemon 68crond - daemon
67crontab 69crontab
68cryptpw 70cryptpw
69cttyhack - spawner 71cttyhack - spawner
70cut - noexec, runner 72cut - noexec. runner
71date 73date - noexec. nofork candidate(needs to stop messing up env, free xasprintf result, not use xfuncs after xasprintf)
72dc - runner (eats stdin if no params) 74dc - runner (eats stdin if no params)
73dd - noexec, runner 75dd - noexec. runner
74deallocvt 76deallocvt
75delgroup 77delgroup
76deluser 78deluser
77depmod 79depmod
78devmem 80devmem - runner, complex (access to device memory may hang)
79df 81df - complex (nested allocs)
80dhcprelay - daemon 82dhcprelay - daemon
81diff - runner 83diff - runner
82dirname - NOFORK 84dirname - NOFORK
83dmesg 85dmesg - runner
84dnsd - daemon 86dnsd - daemon
85dnsdomainname 87dnsdomainname - DNS resolution may trigger, need ^C
86dos2unix - noexec, runner 88dos2unix - noexec. runner
87dpkg - runner 89dpkg - runner
88du 90du - runner
89dumpkmap 91dumpkmap
90dumpleases 92dumpleases
91echo - NOFORK 93echo - NOFORK
92ed - interactive 94ed - interactive
93egrep - runner 95egrep - runner
94eject 96eject
95env - noexec, changes state (env) 97env - noexec. changes state (env)
96envdir - spawner 98envdir - spawner
97envuidgid - spawner 99envuidgid - spawner
98expand - runner 100expand - runner
99expr 101expr - complex (nested allocs)
100factor - runner (eats stdin if no params) 102factor - runner (eats stdin if no params)
101fakeidentd - daemon 103fakeidentd - daemon
102false - NOFORK 104false - NOFORK
103fatattr 105fatattr - complex (xopen+xioctl can leak fd)
104fbset 106fbset
105fbsplash - runner, interactive 107fbsplash - runner, interactive
106fdflush 108fdflush
@@ -108,15 +110,15 @@ fdformat - runner
108fdisk - interactive 110fdisk - interactive
109fgconsole 111fgconsole
110fgrep - runner 112fgrep - runner
111find - noexec, runner 113find - noexec. runner
112findfs - suid 114findfs - suid
113flash_eraseall 115flash_eraseall
114flash_lock 116flash_lock
115flash_unlock 117flash_unlock
116flashcp 118flashcp
117flock 119flock
118fold - noexec, runner 120fold - noexec. runner
119free 121free - nofork candidate(struct globals, needs to close /proc/meminfo fd)
120freeramdisk 122freeramdisk
121fsck - interactive 123fsck - interactive
122fsck.minix 124fsck.minix
@@ -134,12 +136,12 @@ groups - noexec
134gunzip - runner 136gunzip - runner
135gzip - runner 137gzip - runner
136halt - rare 138halt - rare
137hd - noexec, runner 139hd - noexec. runner
138hdparm - complex, rare 140hdparm - complex, rare
139head - noexec, runner 141head - noexec. runner
140hexdump - noexec, runner 142hexdump - noexec. runner
141hostid - NOFORK 143hostid - NOFORK
142hostname 144hostname - DNS resolution may trigger, need ^C
143httpd - daemon 145httpd - daemon
144hush - interactive 146hush - interactive
145hwclock 147hwclock
@@ -169,11 +171,11 @@ iproute
169iprule 171iprule
170iptunnel 172iptunnel
171kbd_mode 173kbd_mode
172kill 174kill - NOFORK
173killall 175killall - NOFORK
174killall5 176killall5 - NOFORK
175klogd - daemon 177klogd - daemon
176last 178last - runner (I've got 1300 lines of output when tried it)
177less - interactive 179less - interactive
178link - NOFORK 180link - NOFORK
179linux32 - spawner 181linux32 - spawner
@@ -189,7 +191,7 @@ losetup - complex
189lpd - daemon 191lpd - daemon
190lpq - runner 192lpq - runner
191lpr - runner 193lpr - runner
192ls - noexec, runner 194ls - noexec. runner
193lsattr 195lsattr
194lsmod 196lsmod
195lsof - complex 197lsof - complex
@@ -203,7 +205,7 @@ lzopcat - runner
203makedevs 205makedevs
204makemime - runner 206makemime - runner
205man - spawner, interactive 207man - spawner, interactive
206md5sum - noexec, runner 208md5sum - noexec. runner
207mdev - daemon 209mdev - daemon
208mesg 210mesg
209microcom - interactive, complex 211microcom - interactive, complex
@@ -225,11 +227,11 @@ mount - suid
225mountpoint 227mountpoint
226mpstat 228mpstat
227mt 229mt
228mv 230mv - runner (can be noexec?)
229nameif 231nameif
230nbd-client 232nbd-client
231nc - runner 233nc - runner
232netstat 234netstat - runner with -c
233nice - spawner 235nice - spawner
234nl - runner 236nl - runner
235nmeter - runner 237nmeter - runner
@@ -240,40 +242,40 @@ od - runner
240openvt - spawner 242openvt - spawner
241partprobe 243partprobe
242passwd - suid 244passwd - suid
243paste - noexec, runner 245paste - noexec. runner
244patch 246patch
245pgrep 247pgrep - nofork candidate(xregcomp, procps_scan - are they ok?)
246pidof 248pidof - nofork candidate(uses find_pid_by_name, is that ok?)
247ping - suid, runner 249ping - suid, runner
248ping6 - suid, runner 250ping6 - suid, runner
249pipe_progress 251pipe_progress
250pivot_root 252pivot_root
251pkill 253pkill - nofork candidate(xregcomp, procps_scan - are they ok?)
252pmap 254pmap
253popmaildir - runner 255popmaildir - runner
254poweroff - rare 256poweroff - rare
255powertop - interactive 257powertop - interactive, longterm
256printenv - NOFORK 258printenv - NOFORK
257printf - NOFORK 259printf - NOFORK
258ps 260ps
259pscan 261pscan
260pstree 262pstree
261pwd - NOFORK 263pwd - NOFORK
262pwdx 264pwdx - NOFORK
263raidautorun 265raidautorun
264rdate 266rdate
265rdev 267rdev
266readlink 268readlink - NOFORK
267readprofile 269readprofile
268realpath 270realpath - NOFORK
269reboot - rare 271reboot - rare
270reformime - runner 272reformime - runner
271remove-shell 273remove-shell
272renice 274renice - nofork candidate(uses getpwnam, is that ok?)
273reset - spawner (execs "stty") 275reset - spawner (execs "stty")
274resize 276resize - noexec. changes state (signal handlers)
275rev - runner 277rev - runner
276rm - noexec, rm -i interactive 278rm - noexec. rm -i interactive
277rmdir - NOFORK 279rmdir - NOFORK
278rmmod 280rmmod
279route 281route
@@ -289,7 +291,7 @@ script
289scriptreplay 291scriptreplay
290sed - runner 292sed - runner
291sendmail - runner 293sendmail - runner
292seq - noexec, runner 294seq - noexec. runner
293setarch - spawner 295setarch - spawner
294setconsole 296setconsole
295setfont 297setfont
@@ -300,22 +302,22 @@ setserial
300setsid - spawner 302setsid - spawner
301setuidgid 303setuidgid
302sh - interactive 304sh - interactive
303sha1sum - noexec, runner 305sha1sum - noexec. runner
304sha256sum - noexec, runner 306sha256sum - noexec. runner
305sha3sum - noexec, runner 307sha3sum - noexec. runner
306sha512sum - noexec, runner 308sha512sum - noexec. runner
307showkey - interactive 309showkey - interactive
308shred - runner 310shred - runner
309shuf - noexec, runner 311shuf - noexec. runner
310slattach 312slattach
311sleep - runner 313sleep - runner
312smemcap - runner 314smemcap - runner
313softlimit - spawner 315softlimit - spawner
314sort - noexec, runner 316sort - noexec. runner
315split - runner 317split - runner
316ssl_client - network 318ssl_client - network
317start-stop-daemon 319start-stop-daemon
318stat 320stat - nofork candidate(needs fewer allocs)
319strings - runner 321strings - runner
320stty 322stty
321su - suid, spawner 323su - suid, spawner
@@ -326,11 +328,11 @@ svc
326svlogd - daemon 328svlogd - daemon
327swapoff - rare 329swapoff - rare
328swapon - rare 330swapon - rare
329switch_root - spawner, rare, change state 331switch_root - spawner, rare, changes state
330sync - NOFORK 332sync - NOFORK
331sysctl 333sysctl
332syslogd - daemon 334syslogd - daemon
333tac - noexec, runner 335tac - noexec. runner
334tail - runner 336tail - runner
335tar - runner 337tar - runner
336taskset - spawner 338taskset - spawner
@@ -341,9 +343,9 @@ telnetd - daemon
341test - NOFORK 343test - NOFORK
342tftp - runner 344tftp - runner
343tftpd - daemon 345tftpd - daemon
344time - spawner, change state (signals) 346time - spawner, changes state (signals)
345timeout - spawner, change state (signals) 347timeout - spawner, changes state (signals)
346top - interactive 348top - interactive, longterm
347touch - NOFORK 349touch - NOFORK
348tr - runner 350tr - runner
349traceroute - suid, runner 351traceroute - suid, runner
@@ -351,7 +353,7 @@ traceroute6 - suid, runner
351true - NOFORK 353true - NOFORK
352truncate - NOFORK 354truncate - NOFORK
353tty - NOFORK 355tty - NOFORK
354ttysize 356ttysize - NOFORK
355tunctl 357tunctl
356tune2fs 358tune2fs
357ubiattach 359ubiattach
@@ -370,14 +372,14 @@ uname - NOFORK
370uncompress - runner 372uncompress - runner
371unexpand - runner 373unexpand - runner
372uniq - runner 374uniq - runner
373unix2dos - noexec, runner 375unix2dos - noexec. runner
374unlink - NOFORK 376unlink - NOFORK
375unlzma - runner 377unlzma - runner
376unlzop - runner 378unlzop - runner
377unxz - runner 379unxz - runner
378unzip - runner 380unzip - runner
379uptime 381uptime - nofork candidate(is getutxent ok?)
380users 382users - nofork candidate(is getutxent ok?)
381usleep - NOFORK 383usleep - NOFORK
382uudecode - runner 384uudecode - runner
383uuencode - runner 385uuencode - runner
@@ -395,10 +397,10 @@ which - NOFORK
395who 397who
396whoami - NOFORK 398whoami - NOFORK
397whois 399whois
398xargs - noexec, spawner 400xargs - noexec. spawner
399xxd - noexec, runner 401xxd - noexec. runner
400xz - runner 402xz - runner
401xzcat - runner 403xzcat - runner
402yes - noexec, runner 404yes - noexec. runner
403zcat - runner 405zcat - runner
404zcip - daemon 406zcip - daemon
diff --git a/console-tools/resize.c b/console-tools/resize.c
index 62928a01e..97866673a 100644
--- a/console-tools/resize.c
+++ b/console-tools/resize.c
@@ -23,7 +23,7 @@
23//config: E.g.: 23//config: E.g.:
24//config: COLUMNS=80;LINES=44;export COLUMNS LINES; 24//config: COLUMNS=80;LINES=44;export COLUMNS LINES;
25 25
26//applet:IF_RESIZE(APPLET(resize, BB_DIR_USR_BIN, BB_SUID_DROP)) 26//applet:IF_RESIZE(APPLET_NOEXEC(resize, resize, BB_DIR_USR_BIN, BB_SUID_DROP, resize))
27 27
28//kbuild:lib-$(CONFIG_RESIZE) += resize.o 28//kbuild:lib-$(CONFIG_RESIZE) += resize.o
29 29
diff --git a/coreutils/date.c b/coreutils/date.c
index 2c6e1d4df..89b281646 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -58,7 +58,7 @@
58//config: the same format. With it on, 'date DATE' additionally supports 58//config: the same format. With it on, 'date DATE' additionally supports
59//config: MMDDhhmm[[YY]YY][.ss] format. 59//config: MMDDhhmm[[YY]YY][.ss] format.
60 60
61//applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP)) 61//applet:IF_DATE(APPLET_NOEXEC(date, date, BB_DIR_BIN, BB_SUID_DROP, date))
62 62
63//kbuild:lib-$(CONFIG_DATE) += date.o 63//kbuild:lib-$(CONFIG_DATE) += date.o
64 64
@@ -152,12 +152,6 @@ enum {
152 OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ 152 OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
153}; 153};
154 154
155static void maybe_set_utc(int opt)
156{
157 if (opt & OPT_UTC)
158 putenv((char*)"TZ=UTC0");
159}
160
161#if ENABLE_LONG_OPTS 155#if ENABLE_LONG_OPTS
162static const char date_longopts[] ALIGN1 = 156static const char date_longopts[] ALIGN1 =
163 "rfc-822\0" No_argument "R" 157 "rfc-822\0" No_argument "R"
@@ -170,6 +164,19 @@ static const char date_longopts[] ALIGN1 =
170 ; 164 ;
171#endif 165#endif
172 166
167/* We are a NOEXEC applet.
168 * Obstacles to NOFORK:
169 * - we change env
170 * - xasprintf result not freed
171 * - after xasprintf we use other xfuncs
172 */
173
174static void maybe_set_utc(int opt)
175{
176 if (opt & OPT_UTC)
177 putenv((char*)"TZ=UTC0");
178}
179
173int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 180int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
174int date_main(int argc UNUSED_PARAM, char **argv) 181int date_main(int argc UNUSED_PARAM, char **argv)
175{ 182{
diff --git a/coreutils/readlink.c b/coreutils/readlink.c
index 9690290e3..7f8d6b239 100644
--- a/coreutils/readlink.c
+++ b/coreutils/readlink.c
@@ -20,7 +20,7 @@
20//config: help 20//config: help
21//config: Enable the readlink option (-f). 21//config: Enable the readlink option (-f).
22 22
23//applet:IF_READLINK(APPLET(readlink, BB_DIR_USR_BIN, BB_SUID_DROP)) 23//applet:IF_READLINK(APPLET_NOFORK(readlink, readlink, BB_DIR_USR_BIN, BB_SUID_DROP, readlink))
24 24
25//kbuild:lib-$(CONFIG_READLINK) += readlink.o 25//kbuild:lib-$(CONFIG_READLINK) += readlink.o
26 26
@@ -85,6 +85,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)
85 if (!(opt & 4)) /* not -v */ 85 if (!(opt & 4)) /* not -v */
86 logmode = LOGMODE_NONE; 86 logmode = LOGMODE_NONE;
87 87
88 /* NOFORK: only one alloc is allowed; must free */
88 if (opt & 1) { /* -f */ 89 if (opt & 1) { /* -f */
89 buf = xmalloc_realpath(fname); 90 buf = xmalloc_realpath(fname);
90 } else { 91 } else {
@@ -94,9 +95,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)
94 if (!buf) 95 if (!buf)
95 return EXIT_FAILURE; 96 return EXIT_FAILURE;
96 printf((opt & 2) ? "%s" : "%s\n", buf); 97 printf((opt & 2) ? "%s" : "%s\n", buf);
97 98 free(buf);
98 if (ENABLE_FEATURE_CLEAN_UP)
99 free(buf);
100 99
101 fflush_stdout_and_exit(EXIT_SUCCESS); 100 fflush_stdout_and_exit(EXIT_SUCCESS);
102} 101}
diff --git a/coreutils/realpath.c b/coreutils/realpath.c
index 6a61c3dc8..f9c630135 100644
--- a/coreutils/realpath.c
+++ b/coreutils/realpath.c
@@ -13,7 +13,7 @@
13//config: Return the canonicalized absolute pathname. 13//config: Return the canonicalized absolute pathname.
14//config: This isn't provided by GNU shellutils, but where else does it belong. 14//config: This isn't provided by GNU shellutils, but where else does it belong.
15 15
16//applet:IF_REALPATH(APPLET(realpath, BB_DIR_USR_BIN, BB_SUID_DROP)) 16//applet:IF_REALPATH(APPLET_NOFORK(realpath, realpath, BB_DIR_USR_BIN, BB_SUID_DROP, realpath))
17 17
18//kbuild:lib-$(CONFIG_REALPATH) += realpath.o 18//kbuild:lib-$(CONFIG_REALPATH) += realpath.o
19 19
@@ -36,6 +36,7 @@ int realpath_main(int argc UNUSED_PARAM, char **argv)
36 } 36 }
37 37
38 do { 38 do {
39 /* NOFORK: only one alloc is allowed; must free */
39 char *resolved_path = xmalloc_realpath(*argv); 40 char *resolved_path = xmalloc_realpath(*argv);
40 if (resolved_path != NULL) { 41 if (resolved_path != NULL) {
41 puts(resolved_path); 42 puts(resolved_path);
diff --git a/docs/nofork_noexec.txt b/docs/nofork_noexec.txt
index 0ad4e6e60..cfb02145a 100644
--- a/docs/nofork_noexec.txt
+++ b/docs/nofork_noexec.txt
@@ -98,7 +98,7 @@ It itself calls run_nofork_applet(), if argv[0] turned out to be a name
98of a NOFORK applet. 98of a NOFORK applet.
99 99
100run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval, 100run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval,
101applet_name. Thus, for example, caller does not need to worry about 101logmode, applet_name. Thus, for example, caller does not need to worry about
102option_mask32 getting trashed. 102option_mask32 getting trashed.
103 103
104 104
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c
index 4829b723a..dca0a150b 100644
--- a/libbb/bb_pwd.c
+++ b/libbb/bb_pwd.c
@@ -31,9 +31,9 @@ struct group* FAST_FUNC xgetgrnam(const char *name)
31 return gr; 31 return gr;
32} 32}
33 33
34
35struct passwd* FAST_FUNC xgetpwuid(uid_t uid) 34struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
36{ 35{
36 /* Note: used in nofork applets (whoami), be careful not to leak anything */
37 struct passwd *pw = getpwuid(uid); 37 struct passwd *pw = getpwuid(uid);
38 if (!pw) 38 if (!pw)
39 bb_error_msg_and_die("unknown uid %u", (unsigned)uid); 39 bb_error_msg_and_die("unknown uid %u", (unsigned)uid);
@@ -50,6 +50,7 @@ struct group* FAST_FUNC xgetgrgid(gid_t gid)
50 50
51char* FAST_FUNC xuid2uname(uid_t uid) 51char* FAST_FUNC xuid2uname(uid_t uid)
52{ 52{
53 /* Note: used in nofork applets (whoami), be careful not to leak anything */
53 struct passwd *pw = xgetpwuid(uid); 54 struct passwd *pw = xgetpwuid(uid);
54 return pw->pw_name; 55 return pw->pw_name;
55} 56}
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 576534ee5..487ecb0e4 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -92,6 +92,7 @@ struct nofork_save_area {
92 void (*die_func)(void); 92 void (*die_func)(void);
93 const char *applet_name; 93 const char *applet_name;
94 uint32_t option_mask32; 94 uint32_t option_mask32;
95 smallint logmode;
95 uint8_t xfunc_error_retval; 96 uint8_t xfunc_error_retval;
96}; 97};
97static void save_nofork_data(struct nofork_save_area *save) 98static void save_nofork_data(struct nofork_save_area *save)
@@ -100,6 +101,7 @@ static void save_nofork_data(struct nofork_save_area *save)
100 save->die_func = die_func; 101 save->die_func = die_func;
101 save->applet_name = applet_name; 102 save->applet_name = applet_name;
102 save->option_mask32 = option_mask32; 103 save->option_mask32 = option_mask32;
104 save->logmode = logmode;
103 save->xfunc_error_retval = xfunc_error_retval; 105 save->xfunc_error_retval = xfunc_error_retval;
104} 106}
105static void restore_nofork_data(struct nofork_save_area *save) 107static void restore_nofork_data(struct nofork_save_area *save)
@@ -108,6 +110,7 @@ static void restore_nofork_data(struct nofork_save_area *save)
108 die_func = save->die_func; 110 die_func = save->die_func;
109 applet_name = save->applet_name; 111 applet_name = save->applet_name;
110 option_mask32 = save->option_mask32; 112 option_mask32 = save->option_mask32;
113 logmode = save->logmode;
111 xfunc_error_retval = save->xfunc_error_retval; 114 xfunc_error_retval = save->xfunc_error_retval;
112} 115}
113 116
@@ -118,8 +121,8 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
118 121
119 save_nofork_data(&old); 122 save_nofork_data(&old);
120 123
124 logmode = LOGMODE_STDIO;
121 xfunc_error_retval = EXIT_FAILURE; 125 xfunc_error_retval = EXIT_FAILURE;
122
123 /* In case getopt() or getopt32() was already called: 126 /* In case getopt() or getopt32() was already called:
124 * reset the libc getopt() function, which keeps internal state. 127 * reset the libc getopt() function, which keeps internal state.
125 */ 128 */
@@ -146,7 +149,6 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
146 149
147 /* Restoring some globals */ 150 /* Restoring some globals */
148 restore_nofork_data(&old); 151 restore_nofork_data(&old);
149
150 /* Other globals can be simply reset to defaults */ 152 /* Other globals can be simply reset to defaults */
151 GETOPT_RESET(); 153 GETOPT_RESET();
152 154
diff --git a/miscutils/ttysize.c b/miscutils/ttysize.c
index 7f6a84308..2c2d4ec33 100644
--- a/miscutils/ttysize.c
+++ b/miscutils/ttysize.c
@@ -18,7 +18,7 @@
18//config: error, but returns default 80x24. 18//config: error, but returns default 80x24.
19//config: Usage in shell scripts: width=`ttysize w`. 19//config: Usage in shell scripts: width=`ttysize w`.
20 20
21//applet:IF_TTYSIZE(APPLET(ttysize, BB_DIR_USR_BIN, BB_SUID_DROP)) 21//applet:IF_TTYSIZE(APPLET_NOFORK(ttysize, ttysize, BB_DIR_USR_BIN, BB_SUID_DROP, ttysize))
22 22
23//kbuild:lib-$(CONFIG_TTYSIZE) += ttysize.o 23//kbuild:lib-$(CONFIG_TTYSIZE) += ttysize.o
24 24
diff --git a/procps/kill.c b/procps/kill.c
index 09beefb2d..0ddae2f70 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -32,10 +32,10 @@
32//config: in its own session, so it won't kill the shell that is running 32//config: in its own session, so it won't kill the shell that is running
33//config: the script it was called from. 33//config: the script it was called from.
34 34
35//applet:IF_KILL(APPLET(kill, BB_DIR_BIN, BB_SUID_DROP)) 35//applet:IF_KILL( APPLET_NOFORK(kill, kill, BB_DIR_BIN, BB_SUID_DROP, kill))
36// APPLET_ODDNAME:name main location suid_type help 36// APPLET_NOFORK:name main location suid_type help
37//applet:IF_KILLALL( APPLET_ODDNAME(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall)) 37//applet:IF_KILLALL( APPLET_NOFORK(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall))
38//applet:IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5)) 38//applet:IF_KILLALL5(APPLET_NOFORK(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5))
39 39
40//kbuild:lib-$(CONFIG_KILL) += kill.o 40//kbuild:lib-$(CONFIG_KILL) += kill.o
41//kbuild:lib-$(CONFIG_KILLALL) += kill.o 41//kbuild:lib-$(CONFIG_KILLALL) += kill.o
@@ -87,7 +87,7 @@
87 * + we can't use xfunc here 87 * + we can't use xfunc here
88 * + we can't use applet_name 88 * + we can't use applet_name
89 * + we can't use bb_show_usage 89 * + we can't use bb_show_usage
90 * (Above doesn't apply for killall[5] cases) 90 * (doesn't apply for killall[5], still should be careful b/c NOFORK)
91 * 91 *
92 * kill %n gets translated into kill ' -<process group>' by shell (note space!) 92 * kill %n gets translated into kill ' -<process group>' by shell (note space!)
93 * This is needed to avoid collision with kill -9 ... syntax 93 * This is needed to avoid collision with kill -9 ... syntax
diff --git a/procps/pwdx.c b/procps/pwdx.c
index dac238950..84802bbcd 100644
--- a/procps/pwdx.c
+++ b/procps/pwdx.c
@@ -14,7 +14,7 @@
14//config: help 14//config: help
15//config: Report current working directory of a process 15//config: Report current working directory of a process
16 16
17//applet:IF_PWDX(APPLET(pwdx, BB_DIR_USR_BIN, BB_SUID_DROP)) 17//applet:IF_PWDX(APPLET_NOFORK(pwdx, pwdx, BB_DIR_USR_BIN, BB_SUID_DROP, pwdx))
18 18
19//kbuild:lib-$(CONFIG_PWDX) += pwdx.o 19//kbuild:lib-$(CONFIG_PWDX) += pwdx.o
20 20
@@ -50,6 +50,7 @@ int pwdx_main(int argc UNUSED_PARAM, char **argv)
50 50
51 sprintf(buf, "/proc/%u/cwd", pid); 51 sprintf(buf, "/proc/%u/cwd", pid);
52 52
53 /* NOFORK: only one alloc is allowed; must free */
53 s = xmalloc_readlink(buf); 54 s = xmalloc_readlink(buf);
54 // "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR" 55 // "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR"
55 printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno)); 56 printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno));