Re: sed not working on /proc files

Malcolm Beattie (mbeattie@sable.ox.ac.uk)
Tue, 27 Apr 1999 13:52:22 +0100 (BST)


Richard B. Johnson writes:
> On Mon, 26 Apr 1999, David B. Rees wrote:
>
> > On 27-Apr-99 Richard B. Johnson wrote:
> > > If everything seems to work okay, then ask Linus. It's his code. There
> > > is zero overhead to making such a phony size, but, as I said, it's
> > > Linus' code. He may have a good reason for zero-length files.
> >
> > So what happens if the length of a /proc file is bigger than 1000 bytes?
> >
> > Programs which expect it to be only 1000 bytes will not read all the data.
> > Seems like a hack, to me.
> >
>
> Well it is a 'hack' as you say. However, there (presently) doesn't seem
> to be anything that has more than about 900 bytes of text in them.

% cat /proc/scsi/BusLogic/0 | wc -c
4440

> Also,
> most tools will read until EOF (no more data), ignoring the file size so
> the file-size doesn't limit it.

This thread started with the failure of sed to work which (at least in
modern versions) stats the source to find its size and then mmaps it.
If you kludge the filesize to be fixed at 1000 (say) then sed will map
the first 1000 bytes (well, maybe rounded up to a whole PAGE_SIZE),
operate on that and happily ignore the rest.

Having an arbitrary limit for a fake filesize is bad. At least with
zero length output, it's obvious that something is wrong. If people
start getting bogus truncated output just because somebody hot-adds a
disk or some statistic gatherer ups the number of bytes in a /proc
file then it would lead to problems that are much harder to trace.

--Malcolm

-- 
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Unix Systems Programmer
Oxford University Computing Services

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/