svn commit: r233837 - stable/9/lib/libutil
Guy Helmer
ghelmer at FreeBSD.org
Tue Apr 3 15:42:09 UTC 2012
Author: ghelmer
Date: Tue Apr 3 15:42:08 2012
New Revision: 233837
URL: http://svn.freebsd.org/changeset/base/233837
Log:
MFC r229937:
Add pidfile_fileno() to obtain the file descriptor for an open
pidfile.
Modified:
stable/9/lib/libutil/libutil.h
stable/9/lib/libutil/pidfile.3
stable/9/lib/libutil/pidfile.c
Directory Properties:
stable/9/lib/libutil/ (props changed)
Modified: stable/9/lib/libutil/libutil.h
==============================================================================
--- stable/9/lib/libutil/libutil.h Tue Apr 3 14:29:24 2012 (r233836)
+++ stable/9/lib/libutil/libutil.h Tue Apr 3 15:42:08 2012 (r233837)
@@ -163,6 +163,7 @@ struct pidfh *pidfile_open(const char *p
int pidfile_write(struct pidfh *pfh);
int pidfile_close(struct pidfh *pfh);
int pidfile_remove(struct pidfh *pfh);
+int pidfile_fileno(struct pidfh *pfh);
#endif
#ifdef _UFS_UFS_QUOTA_H_
Modified: stable/9/lib/libutil/pidfile.3
==============================================================================
--- stable/9/lib/libutil/pidfile.3 Tue Apr 3 14:29:24 2012 (r233836)
+++ stable/9/lib/libutil/pidfile.3 Tue Apr 3 15:42:08 2012 (r233837)
@@ -46,6 +46,8 @@
.Fn pidfile_close "struct pidfh *pfh"
.Ft int
.Fn pidfile_remove "struct pidfh *pfh"
+.Ft int
+.Fn pidfile_fileno "struct pidfh *pfh"
.Sh DESCRIPTION
The
.Nm pidfile
@@ -89,6 +91,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.
.Sh RETURN VALUES
The
.Fn pidfile_open
@@ -102,15 +108,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
+.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;
@@ -239,6 +255,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: stable/9/lib/libutil/pidfile.c
==============================================================================
--- stable/9/lib/libutil/pidfile.c Tue Apr 3 14:29:24 2012 (r233836)
+++ stable/9/lib/libutil/pidfile.c Tue Apr 3 15:42:08 2012 (r233837)
@@ -252,3 +252,13 @@ pidfile_remove(struct pidfh *pfh)
return (_pidfile_remove(pfh, 1));
}
+
+int
+pidfile_fileno(struct pidfh *pfh)
+{
+ if (pfh == NULL || pfh->pf_fd == -1) {
+ errno = EDOOFUS;
+ return (-1);
+ }
+ return (pfh->pf_fd);
+}
More information about the svn-src-stable-9
mailing list