read() builtin doesnt read integer value /proc files (but bashs does)
Ralf Friedl
Ralf.Friedl at online.de
Sun Dec 19 14:59:19 UTC 2010
Cristian Ionescu-Idbohrn wrote:
> On Sun, 19 Dec 2010, Denys Vlasenko wrote:
>
>> The fix is hard. Consider that read should work properly here:
>>
>> exec </proc/some/file
>> read line
>> cat
>>
>> If read "reads ahead" 128 bytes, but finds '\n' after 5th byte,
>> how can it "roll back" so that cat starts reading at the right
>> position?
>>
>
> Seems bash somehow manages to deliver what's expected:
>
The way bash does it is to do an lseek to the right position after the
read, after verifying that lseek is possible. Of course this doesn't
necessarily work for proc files.
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa7ff48) = -1 ENOTTY
(Inappropriate ioctl for device)
_llseek(0, 0, [0], SEEK_CUR) = 0
read(0, "\nWelcome to SuSE Linux 9.2 (i586) - Kernel \\r (\\l).\n\n\n",
128) = 54
_llseek(0, -53, [1], SEEK_CUR) = 0
Ralf
More information about the busybox
mailing list