Date: Tue, 3 Apr 2012 21:10:31 +0000 (UTC) From: Guy Helmer <ghelmer@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r233856 - stable/9/lib/libutil Message-ID: <201204032110.q33LAV2D069341@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204032110.q33LAV2D069341>