2012/11/28 Clark WANG <[email protected]>:
> ~{fd} is new to me. Please help me a bit...
>
>>
>> >>>
>> >>> This isn't readlink support. It's a a smart solution to allow child
>> >>> processes to access the shell's inherited file descriptors.
>
>
> Lionel, I don't quite understand this. Can you explain a bit more?
ls -l /proc/$$/fd/ gives you a list of file descriptors which are
opened by the current process. In the same manner you can access file
descriptors opened by other processes if the privileges allow it.
>
>>
>> We already
>> >>> heavily rely on this feature, both for IPC and to shorten very long
>> >>> paths to speed processing up.
>> >>>
>> >
>> > Yes, it's an ingenious solution to the problem of long paths. You pass
>> > a dir fd in which acts as virtual "/" and all paths are appended to
>> > it. Using /proc/.../fd instead of /megalong/path/ is MUCH faster and
>> > easier.
>
>
> Cedric, how can you get a dir fd? All I know about opening a dir is
> opendir(3).
You can open the current directory with open(".", O_RDONLY). If the
directory is not readable by the current set of privileges you can use
O_SEARCH on POSIX systems and O_PATH on Linux.
>>
>>
>> Yes, we like this feature, too. At first it was a bit 'getting used
>> to' but if you imagine that each fd works - as Cedric stated - a
>> virtual root then script hackers will quickly understand the power of
>> this feature. Suddenly you can have as many cwds as you wish and
>> that's worth $$$$.
>
>
> Irek, I don't quite understand you here either. Can't you have as many cwds
> without using ~{x}?
No, you can only have paths without ~{x}. The feature we're talking
about is that you can open a directory with open(directory_name ...)
which returns a file descriptor representing that point in the file
system. That file descriptor can be used for many purposes, including
the POSIX openat() API to access files *relative* to that point in the
file system or fchdir() to change the global cwd to that point.
This becomes very handy if you have a fixed set of multiple points in
the file system which are repeatedly accessed, and it makes accesses
to file system locations which are behind very long paths much faster
Irek
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users