From owner-svn-src-stable-9@FreeBSD.ORG Tue Apr 3 21:10:31 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A67AA106567B; Tue, 3 Apr 2012 21:10:31 +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 77B348FC15; Tue, 3 Apr 2012 21:10:31 +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 q33LAVSk069344; Tue, 3 Apr 2012 21:10:31 GMT (envelope-from ghelmer@svn.freebsd.org) Received: (from ghelmer@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q33LAV2D069341; Tue, 3 Apr 2012 21:10:31 GMT (envelope-from ghelmer@svn.freebsd.org) Message-Id: <201204032110.q33LAV2D069341@svn.freebsd.org> From: Guy Helmer Date: Tue, 3 Apr 2012 21:10:31 +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: r233856 - stable/9/lib/libutil X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Apr 2012 21:10:31 -0000 Author: ghelmer Date: Tue Apr 3 21:10:30 2012 New Revision: 233856 URL: http://svn.freebsd.org/changeset/base/233856 Log: MFC: 229942, 231938 229942: Style fixes courtesy of pjd. 231938: Set the O_CLOEXEC flag when opening the pidfile to avoid leaking the file descriptor via exec(3). Now that daemon(8) has been fixed to resolve the issue noted by trociny, the consensus is that this change should be OK. Modified: 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/pidfile.3 ============================================================================== --- stable/9/lib/libutil/pidfile.3 Tue Apr 3 20:49:26 2012 (r233855) +++ stable/9/lib/libutil/pidfile.3 Tue Apr 3 21:10:30 2012 (r233856) @@ -94,7 +94,7 @@ function closes and removes a pidfile. .Pp The .Fn pidfile_fileno -function returns the file descriptor for the open pid file. +function returns the file descriptor for the open pidfile. .Sh RETURN VALUES The .Fn pidfile_open @@ -112,7 +112,9 @@ will be set. The .Fn pidfile_fileno function returns the low-level file descriptor. -It returns -1 and sets +It returns +.Li -1 +and sets .Va errno if a NULL .Vt pidfh Modified: stable/9/lib/libutil/pidfile.c ============================================================================== --- stable/9/lib/libutil/pidfile.c Tue Apr 3 20:49:26 2012 (r233855) +++ stable/9/lib/libutil/pidfile.c Tue Apr 3 21:10:30 2012 (r233856) @@ -124,7 +124,7 @@ pidfile_open(const char *path, mode_t mo * pidfile_write() can be called multiple times. */ fd = flopen(pfh->pf_path, - O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); + O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode); if (fd == -1) { count = 0; rqtp.tv_sec = 0; @@ -263,6 +263,7 @@ pidfile_remove(struct pidfh *pfh) int pidfile_fileno(const struct pidfh *pfh) { + if (pfh == NULL || pfh->pf_fd == -1) { errno = EDOOFUS; return (-1);