bug-gnulib
[Top][All Lists]
Advanced

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

Re: RE : Re: openat-proc


From: Eric Blake
Subject: Re: RE : Re: openat-proc
Date: Mon, 09 May 2011 16:08:40 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.10

On 05/09/2011 02:34 PM, Eric Blake wrote:
> On 05/09/2011 01:10 PM, Eric Blake wrote:
>> On 05/09/2011 12:06 PM, Bastien ROUCARIES wrote:
>>> Sorry for top post (android)
>>>
>>> Proposed algo:
>>> Ofd=open(/proc,o_search)
>>> follow link /proc/self/fd/ofd/../proc
>>> If bug will resolve to
>>> /proc/self/fd/proc that does not exist
>>> If not bug suceed (because we have already opened /proc
>>
>> I still don't see quite what you are proposing, but you have made me
>> re-read the openat-proc.c code and I think we definitely have a bug there.
> 
> Then again, after reading the code yet again, I think it's okay.

Okay, I finally see what you are proposing.  The current code uses
open(), 2 stat(), and close(), along with inclusion of same-inode.h.
But we could achieve the same determination with:

n = open("/proc/self/fd",O_SEARCH);
if (n < 0)
  proc_status = -1;
else
  {
    proc_status = access ("/proc/self/fd/" n "/../fd", F_OK) ? -1 : 1;
    close (n);
  }

On Linux, where .. resolves correctly, this results in checking if
/proc/self/fd/../fd exists (which it does, because /proc/self/fd is
already opened).  On Solaris, it results in checking if /proc/self/fd/fd
exists (which it doesn't, since /proc/self/fd only contains numeric
entries).

access() is lighter-weight than two stat()s.

-- 
Eric Blake   address@hidden    +1-801-349-2682
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]