broken read in ash

Stefan Seyfried stefan.seyfried at googlemail.com
Sun Apr 1 19:50:17 UTC 2012


Am 01.04.2012 20:14, schrieb Stefan Seyfried:

> Hi all,
> 
> commit 10c0131a8a1b3db7fd6b23b72ebd7b33afc7b018
> Author: Denys Vlasenko <vda.linux at googlemail.com>
> Date:   Wed May 11 11:49:21 2011 +0200
> 
>     hush: use SA_RESTARTed signal handlers across read.
> 
> breaks code like this in ash:


> actually "read a < /proc/bus/input/devices" does not work, while
> "read a < /bin/busybox" does work.
> 
> ARCH is sh4, config is attached.


Ok, it is reproducible with git master on x86_64, "make defconfig"
and then disable all that did not build for me (ext2 utilities).

Now the funny part: it seems to be specific to /proc/bus/input/devices.
With /proc/bus/input/handlers and others, it works.

strace:

seife at susi:/local/seife/src/git-repos/busybox> cat test1.sh
read a < /proc/bus/input/devices
seife at susi:/local/seife/src/git-repos/busybox> cat test2.sh
read a < /proc/bus/input/handlers
seife at susi:/local/seife/src/git-repos/busybox> strace build/busybox sh test1.sh
[...]
getpid()                                = 7670
rt_sigaction(SIGCHLD, {SIG_DFL, [CHLD], SA_RESTORER|SA_RESTART, 0x7f18fda40ba0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGHUP, {SIG_DFL, [HUP], SA_RESTORER|SA_RESTART, 0x7f18fda40ba0}, {SIG_DFL, [], 0}, 8) = 0
getppid()                               = 7669
stat("/local/seife/src/git-repos/busybox", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("test1.sh", O_RDONLY)              = 3
fcntl(3, F_DUPFD, 10)                   = 10
close(3)                                = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, {0x4484b3, ~[RTMIN RT_1], SA_RESTORER, 0x7f18fda40ba0}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN, ~[RTMIN RT_1], SA_RESTORER, 0x7f18fda40ba0}, NULL, 8) = 0
rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7f18fda40ba0}, NULL, 8) = 0
read(10, "read a < /proc/bus/input/devices"..., 1023) = 33
open("/proc/bus/input/devices", O_RDONLY) = 3
fcntl(0, F_DUPFD, 10)                   = 11
dup2(3, 0)                              = 0
close(3)                                = 0
wait4(-1, 0x7fff9271cc3c, WNOHANG, NULL) = -1 ECHILD (No child processes)
poll([{fd=0, events=POLLIN}], 1, -1)    = 1 ([{fd=0, revents=POLLIN}])
read(0, "I", 1)                         = 1
poll([{fd=0, events=POLLIN}], 1, -1^C <unfinished ...>
seife at susi:/local/seife/src/git-repos/busybox> strace build/busybox sh test2.sh 
[...]
brk(0x1482000)                          = 0x1482000
getpid()                                = 7687
rt_sigaction(SIGCHLD, {SIG_DFL, [CHLD], SA_RESTORER|SA_RESTART, 0x7f0daca8cba0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGHUP, {SIG_DFL, [HUP], SA_RESTORER|SA_RESTART, 0x7f0daca8cba0}, {SIG_DFL, [], 0}, 8) = 0
getppid()                               = 7686
stat("/local/seife/src/git-repos/busybox", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("test2.sh", O_RDONLY)              = 3
fcntl(3, F_DUPFD, 10)                   = 10
close(3)                                = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, {0x4484b3, ~[RTMIN RT_1], SA_RESTORER, 0x7f0daca8cba0}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN, ~[RTMIN RT_1], SA_RESTORER, 0x7f0daca8cba0}, NULL, 8) = 0
rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7f0daca8cba0}, NULL, 8) = 0
read(10, "read a < /proc/bus/input/handler"..., 1023) = 34
open("/proc/bus/input/handlers", O_RDONLY) = 3
fcntl(0, F_DUPFD, 10)                   = 11
dup2(3, 0)                              = 0
close(3)                                = 0
wait4(-1, 0x7fffedeb649c, WNOHANG, NULL) = -1 ECHILD (No child processes)
poll([{fd=0, events=POLLIN}], 1, -1)    = 1 ([{fd=0, revents=POLLIN}])
read(0, "N", 1)                         = 1
poll([{fd=0, events=POLLIN}], 1, -1)    = 1 ([{fd=0, revents=POLLIN}])
read(0, ":", 1)                         = 1
poll([{fd=0, events=POLLIN}], 1, -1)    = 1 ([{fd=0, revents=POLLIN}])
read(0, " ", 1)                         = 1
poll([{fd=0, events=POLLIN}], 1, -1)    = 1 ([{fd=0, revents=POLLIN}])
[...]
poll([{fd=0, events=POLLIN}], 1, -1)    = 1 ([{fd=0, revents=POLLIN}])
read(0, "\n", 1)                        = 1
dup2(11, 0)                             = 0
close(11)                               = 0
read(10, "", 1023)                      = 0
exit_group(0)                           = ?


So it might be, that /proc/bus/input/devices is somehow strange regarding poll(),
however, this worked before (it actually works again if I revert the shell_common
part of 10c0131a8a1b3db7fd6b23b72ebd7b33afc7b018) and it also works with other
shells -- hey, it even works with dash, the most crippled and useless of all bourne
shells ;-)

Best regards,

	Stefan
-- 
Stefan Seyfried

"Dispatch war rocket Ajax to bring back his body!"


More information about the busybox mailing list