first patch for process-shared semaphore

John Baldwin jhb at freebsd.org
Mon Dec 28 16:37:07 UTC 2009


On Thursday 24 December 2009 8:15:45 pm David Xu wrote:
> John Baldwin wrote:
> 
> > Yes, Solaris uses files in /tmp and Darwin uses special file descriptors 
> > similar to what we do.  However, you will have to restrict the namespace if 
> > you go the /tmp route to be safe I think similar to what Solaris does (no path 
> > separators, just simple names like 'foo'). 
> 
> I will only allow names like /XXX, make sure to be compatible with
> current implementation.

Actually, the current implementation in 8+ allow for arbitrary pathnames.
However, that is a relatively recent change and it is probably ok to restrict
it again.

> > You might also want to use the 
> > same naming convention as Solaris if you go the /tmp route (I think they use a 
> > path other than .semaphore under /tmp IIRC).
> 
> What is their name convention? The patch just create all semaphore files
> in directory /tmp/.semaphore and semaphore name is not changed.

They actually create two files in /tmp for each semaphore, a lock file and a
data file.  _Solaris Internals_ doesn't really indicate why the lock file
exists.  The files are named /tmp/SEML<name> and /tmp/SEMD<name> where <name>
does not include the leading '/', a sem_open() of '/foo' opens /tmp/SEMDfoo.

It is perhaps safer to not assume that a /tmp/.semaphore directory exists
and to create files in /tmp directly?

> >  Not sure if we want to do 
> > anything special to ensure that those particular set of files in /tmp always 
> > get purged on reboot to avoid weird bugs with semaphores unexpectedly 
> > persisting across reboots.
> > 
> 
> Yes, this is an issue, I would like to purge it on reboot.

Perhaps /etc/rc.d/cleartmp should always clean semaphores, or at least have a
separate rc.conf variable (similar to the one for X files) that is enabled by
default?

-- 
John Baldwin


More information about the freebsd-threads mailing list