busybox 1.5.x ash read builtin only reads one character at a time?
Clem Taylor
clem.taylor at gmail.com
Thu May 24 00:38:12 UTC 2007
I'm trying to reduce the amount of forking in my startup scripts, so I
started converting various: "var=$(cat filename)" to: "read var <
filename".
The ash read builtin doesn't like reading from /proc, only the first
character ends up in the variable. read is only reading one character
at a time from /proc and the second read call is returning 0.
Should the 'read' builtin be reading a buffer at a time instead of
just one character?
# echo moo.com > /proc/sys/kernel/domainname
# cat /proc/sys/kernel/domainname
moo.com
# read domainname < /proc/sys/kernel/domainname
# echo "domainname=$domainname"
domainname=m
# dn=$(cat /proc/sys/kernel/domainname)
# echo "dn=$dn"
dn=moo.com
cat seems to be getting all the data:
# strace cat /proc/sys/kernel/domainname
....
open("/proc/sys/kernel/domainname", O_RDONLY|O_LARGEFILE) = 3
ioctl(3, TIOCNXCL, 0x7fe6abb0) = -1 ENOTTY (Inappropriate ioctl for de)
brk(0x49b000) = 0x49b000
brk(0x49c000) = 0x49c000
read(3, "moo.com\n", 4096) = 8
write(1, "moo.com\n", 8) = 8
read(3, "", 4096) = 0
close(3) = 0
exit(0) = ?
But read is reading 1 byte at a time:
# echo -e "#!/bin/sh\nread moo < /proc/sys/kernel/domainname\n" > script
# chmod 755 script
# strace script
read(10, "#!/bin/sh\nread moo < /proc/sys/k"..., 4095) = 50
open("/proc/sys/kernel/domainname", O_RDONLY|O_LARGEFILE) = 3
fcntl64(0, F_DUPFD, 10) = 11
close(0) = 0
fcntl64(3, F_DUPFD, 0) = 0
close(3) = 0
read(0, "m", 1) = 1
read(0, "", 1) = 0
close(0) = 0
fcntl64(11, F_DUPFD, 0) = 0
close(11) = 0
read(10, "", 4095) = 0
exit(1) = ?
More information about the busybox
mailing list