DASH Shell discussions
 help / color / mirror / Atom feed
* read() builtin doesn't read integer value /proc files (but bash's does)
@ 2010-09-01  8:10 Steve Schnepp
  2010-09-02 15:02 ` Steve Schnepp
  2010-09-02 19:09 ` read() builtin doesn't read integer value /proc files (but bash's does) Jilles Tjoelker
  0 siblings, 2 replies; 12+ messages in thread
From: Steve Schnepp @ 2010-09-01  8:10 UTC (permalink / raw)
  To: dash; +Cc: 595063

Hi, I opened bug 595063 on the debian BTS [1] and I was suggested to
resend the email upstream.

So I copied the body of the bug below :

dash's read() builtin seems to read the underlying file 1 char at a
time. This doesn't work with some files under /proc, since procfs isn't
fully POSIX compliant.

With bash it works :

$ bash -c 'read MAX < /proc/sys/kernel/pid_max; echo $MAX'
32768

With dash it only reads the first character :

$ dash -c 'read MAX < /proc/sys/kernel/pid_max; echo $MAX'
3

If we use the cat(1) external program it works :

$ dash -c 'MAX=$(cat /proc/sys/kernel/pid_max); echo $MAX'
32768

After a little digging, it only appears on files that contains just an
integer value. When asked to read with a non-null offset (*ppos != 0),
__do_proc_dointvec() just returns 0 (meaning an EOF) as shown on [2].

I'm aware that the issue isn't strictly a dash one, since it has the
right to read one character at a time. But since fixing procfs to be
conforming to POSIX isn't a realistic option, would it be possible to
have a workaround that doesn't involve an external tool like cat(1) ?

[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=595063
[2] http://lxr.linux.no/#linux+v2.6.32/kernel/sysctl.c#L2371
--
Steve Schnepp
http://blog.pwkf.org/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-12-18 22:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-01  8:10 read() builtin doesn't read integer value /proc files (but bash's does) Steve Schnepp
2010-09-02 15:02 ` Steve Schnepp
2010-09-03 21:25   ` Jilles Tjoelker
2010-09-04 18:20     ` Steve Schnepp
2010-09-04 19:35       ` Jilles Tjoelker
2010-11-28  8:42         ` Herbert Xu
2010-12-15  9:49           ` read() builtin doesnt read integer value /proc files (but bashs does) Cristian Ionescu-Idbohrn
2010-12-15 18:55             ` Jonathan Nieder
2010-12-15 19:12               ` Cristian Ionescu-Idbohrn
2010-12-18 22:23               ` Jilles Tjoelker
2010-09-02 19:09 ` read() builtin doesn't read integer value /proc files (but bash's does) Jilles Tjoelker
2010-09-03  9:23   ` Steve Schnepp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox