Re: read() builtin doesnt read integer value /proc files (but bashs does)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi Cristian,

Cristian Ionescu-Idbohrn wrote:
> On Sun, 28 Nov 2010, Herbert Xu wrote:
> > On Sat, Sep 04, 2010 at 07:35:04PM +0000, Jilles Tjoelker wrote:

>>> This discarding is still bad as it throws away valid data if the open
>>> file description is shared. This happens if stdin is redirected inside a
>>
>> I'm with Jilles on this.  I also don't particularly feel like
>> bloating dash just because of the borked /proc interface when
>> there is a perfectly adequate work-around in "cat".
>>
>> 	value=$(cat /proc/file)
>
> I wouldn't call that "a perfectly adequate work-around", but a painful and
> unadequate work-around.

For what it's worth, here's what bash does (based on strace):

1. Determine whether the file is seekable.  That is, seek using
SEEK_CUR with offset 0.

2. If seekable, read a nice big chunk and then seek back to put the
file offset back in the right place.  If not seekable, read one byte
at a time.

This works in /proc because files in /proc are seekable.

That said, I don't think borked /proc is a great reason to do this
(it's a better reason to fix /proc).  Speeding up the read builtin
might be a good reason.

Regards,
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

Powered by Linux