From owner-svn-src-all@FreeBSD.ORG Tue Apr 3 15:42:09 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9E988106566B; Tue, 3 Apr 2012 15:42:09 +0000 (UTC) (envelope-from ghelmer@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7F41C8FC19; Tue, 3 Apr 2012 15:42:09 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q33Fg9Wl056503; Tue, 3 Apr 2012 15:42:09 GMT (envelope-from ghelmer@svn.freebsd.org) Received: (from ghelmer@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q33Fg9Jj056499; Tue, 3 Apr 2012 15:42:09 GMT (envelope-from ghelmer@svn.freebsd.org) Message-Id: <201204031542.q33Fg9Jj056499@svn.freebsd.org> From: Guy Helmer Date: Tue, 3 Apr 2012 15:42:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233837 - stable/9/lib/libutil X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Apr 2012 15:42:09 -0000 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); +}