coreutils
[Top][All Lists]
Advanced

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

Re: "ls -l": Avoid unnecessary getxattr() overhead


From: Eric Blake
Subject: Re: "ls -l": Avoid unnecessary getxattr() overhead
Date: Fri, 17 Feb 2012 07:05:02 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20120131 Thunderbird/10.0

On 02/17/2012 06:58 AM, Jim Meyering wrote:

>>>   eval "LD_PRELOAD=$PWD/k.so ls --color=always -l . $fd>x" || exit 1
>>>
>>> Hmm... that means the case of no getxattr calls would still
>>> require a little special handling to map "empty file" to "0".
>>
>> No.  Just add 'echo 0 >x' prior to the actual test, so that x is never
>> empty.
> 
> But the eval'd code will then truncate "x".

Oh right.  But not the end of the world - in the eval, use $fd<>x to
avoid the truncation.

> On some systems there will be no intercepted *getxattr call,
> and hence x will still be empty.
> 
> Ahh... or maybe you meant to suggest that the eval'd code append to x?

Alas, $fd>>x opens x with O_APPEND, so seeking to position 0 then
calling write() will still append, which is not what we want.

And hopefully no one is running this on the buggy version of dash, since
it was only about 18 months ago where dash had a bug fix to quit using
O_TRUNCATE for $fd<>x (bash and ksh have always followed that part of
POSIX).

Hmm, if we can't rely on $fd<>x, maybe we _can_ use $fd>>x coupled with
fcntl() on fd to reset the O_APPEND before doing any write()s, but that
starts to feel complicated.  I'd rather go with $fd<>x and tell users to
upgrade to a fixed version of dash.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]