summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorghelmer <ghelmer@FreeBSD.org>2012-01-10 19:53:25 +0000
committerghelmer <ghelmer@FreeBSD.org>2012-01-10 19:53:25 +0000
commit9446d41409ef9748c6f20034374a472d777b7135 (patch)
tree4f74c9cb5ce5efb84ef61828351446984695db41 /lib/libutil
parentf6e21fcb264de7e7e3df9d592037f2dd84bb4008 (diff)
downloadFreeBSD-src-9446d41409ef9748c6f20034374a472d777b7135.zip
FreeBSD-src-9446d41409ef9748c6f20034374a472d777b7135.tar.gz
Add pidfile_fileno() to obtain the file descriptor for an open
pidfile.
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/libutil.h1
-rw-r--r--lib/libutil/pidfile.330
-rw-r--r--lib/libutil/pidfile.c10
3 files changed, 39 insertions, 2 deletions
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index 47896c1..25ac1db 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -170,6 +170,7 @@ struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr);
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_
diff --git a/lib/libutil/pidfile.3 b/lib/libutil/pidfile.3
index c42b95b..7ab9857 100644
--- a/lib/libutil/pidfile.3
+++ b/lib/libutil/pidfile.3
@@ -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
@@ -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.
.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
+.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 ,
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c
index fcd504c..cf5acce 100644
--- a/lib/libutil/pidfile.c
+++ b/lib/libutil/pidfile.c
@@ -266,3 +266,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);
+}
OpenPOWER on IntegriCloud