On Tue, Jan 10, 2012 at 07:53:25PM +0000, Guy Helmer wrote: > Author: ghelmer > Date: Tue Jan 10 19:53:25 2012 > New Revision: 229937 > URL: http://svn.freebsd.org/changeset/base/229937 > > Log: > Add pidfile_fileno() to obtain the file descriptor for an open > pidfile. > > Modified: > head/lib/libc/gen/getnetgrent.c > head/lib/libutil/libutil.h > head/lib/libutil/pidfile.3 > head/lib/libutil/pidfile.c [...] > @@ -92,6 +94,10 @@ to start a child process. > The > .Fn pidfile_remove > function closes and removes a pidfile. > +.Pp > +The > +.Fn pidfile_fileno > +function returns the file descriptor for the open pid file.
In other places in this manual page we use 'pidfile' as a single word. > .Sh RETURN VALUES > The > .Fn pidfile_open > @@ -105,15 +111,25 @@ If an error occurs, > will be set. > .Pp > .Rv -std pidfile_write pidfile_close pidfile_remove > +.Pp > +The > +.Fn pidfile_fileno > +function returns the low-level file descriptor. > +It returns -1 and sets I think you should also use .Va or .Li macro for -1. > +.Va errno > +if a NULL > +.Vt pidfh > +is specified, or if the pidfile is no longer open. > .Sh EXAMPLES > The following example shows in which order these functions should be used. > Note that it is safe to pass > .Dv NULL > to > .Fn pidfile_write , > -.Fn pidfile_remove > -and > +.Fn pidfile_remove , > .Fn pidfile_close > +and > +.Fn pidfile_fileno > functions. > .Bd -literal > struct pidfh *pfh; > @@ -244,6 +260,16 @@ and > system calls and the > .Xr flopen 3 > library function. > +.Pp > +The > +.Fn pidfile_fileno > +function will fail if: > +.Bl -tag -width Er > +.It Bq Er EDOOFUS > +Improper function use. > +Probably called not from the process which used > +.Fn pidfile_open . > +.El > .Sh SEE ALSO > .Xr open 2 , > .Xr daemon 3 , > > Modified: head/lib/libutil/pidfile.c > ============================================================================== > --- head/lib/libutil/pidfile.c Tue Jan 10 18:43:27 2012 > (r229936) > +++ head/lib/libutil/pidfile.c Tue Jan 10 19:53:25 2012 > (r229937) > @@ -266,3 +266,13 @@ pidfile_remove(struct pidfh *pfh) > > return (_pidfile_remove(pfh, 1)); > } > + > +int > +pidfile_fileno(struct pidfh *pfh) > +{ Missing empty line here for function without local variables. > + if (pfh == NULL || pfh->pf_fd == -1) { > + errno = EDOOFUS; > + return (-1); > + } > + return (pfh->pf_fd); > +} BTW. If you are working on pidfile, it would be nice to move pidfile structure declaration into pidfile.c. There is no need to expose it. -- Pawel Jakub Dawidek http://www.wheelsystems.com FreeBSD committer http://www.FreeBSD.org Am I Evil? Yes, I Am! http://yomoli.com
pgptcBYpE7fgx.pgp
Description: PGP signature