This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Thread-, Signal- and Cancellation-safety documentation


On Fri, May 31, 2013 at 05:51:15PM -0300, Alexandre Oliva wrote:
> >> Sure, if two threads call it concurrently, you can't predict which one
> >> ends up as the cwd for the process, but that's just as impredictable as
> >> the result when two threads call write concurrently, or rename
> >> concurrently from or to the same pathname.  But you wouldn't say
> >> multi-threaded programs shouldn't call write or rename, would you?
> 
> > That's because the immediate caller can ensure that it has exclusive
> > access to the resource (or determine that the race is benign),
> 
> Huh?  How could anyone ensure it has exclusive access to a filename
> that's about to be renamed, or overwritten by a rename?  That's not even
> something that could be guaranteed even involving all the threads of a
> process: other processes could mess with the files!

If the directory has a 255-character random name and is located in a
non-readable directory owned by root on a system where no process has
retained root, then you can be quite certain that only the process(es)
which have the name of the directory or a live file descriptor for it
can perform a rename in it.

Extreme examples aside, if an application is working in a working
directory that (by contract/convention) belongs to it, and which has
the right permissions so that other users cannot mess with it, and the
application has documented that the user running the application
cannot mess with the contents of this directory while the application
is running without invoking UB, then you have a reasonable real-world
situation where exclusivity is "guaranteed".

Rich


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]