svn commit: r229936 - head/lib/libutil

Guy Helmer guy.helmer at palisadesystems.com
Tue Jan 10 21:40:20 UTC 2012


On Jan 10, 2012, at 3:27 PM, Pawel Jakub Dawidek wrote:

> On Tue, Jan 10, 2012 at 10:25:26PM +0100, Pawel Jakub Dawidek wrote:
>> On Tue, Jan 10, 2012 at 06:43:27PM +0000, Guy Helmer wrote:
>>> Author: ghelmer
>>> Date: Tue Jan 10 18:43:27 2012
>>> New Revision: 229936
>>> URL: http://svn.freebsd.org/changeset/base/229936
>>> 
>>> Log:
>>>  Set the FD_CLOEXEC flag on the open pidfile file descriptor.
>>> 
>>>  Discussed with: pjd, des
>> 
>> Could you also update manual page to note that pidfile_open(3) can now
>> also set errno via fcntl(2)?
> 
> Actually, it would also be useful to document the fact that we now set
> FD_CLOEXEC flag, so one doesn't have to look at the code to find it.

Thanks for reminding me, I mean to do that earlier.

Guy

> 
>>> Modified:
>>>  head/lib/libutil/pidfile.c
>>> 
>>> Modified: head/lib/libutil/pidfile.c
>>> ==============================================================================
>>> --- head/lib/libutil/pidfile.c	Tue Jan 10 18:20:19 2012	(r229935)
>>> +++ head/lib/libutil/pidfile.c	Tue Jan 10 18:43:27 2012	(r229936)
>>> @@ -137,6 +137,20 @@ pidfile_open(const char *path, mode_t mo
>>> 		free(pfh);
>>> 		return (NULL);
>>> 	}
>>> +
>>> +	/*
>>> +	 * Prevent the file descriptor from escaping to other
>>> +	 * programs via exec(3).
>>> +	 */
>>> +	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
>>> +		error = errno;
>>> +		unlink(pfh->pf_path);
>>> +		close(fd);
>>> +		free(pfh);
>>> +		errno = error;
>>> +		return (NULL);
>>> +	}
>>> +
>>> 	/*
>>> 	 * Remember file information, so in pidfile_write() we are sure we write
>>> 	 * to the proper descriptor.
> 
> -- 
> Pawel Jakub Dawidek                       http://www.wheelsystems.com
> FreeBSD committer                         http://www.FreeBSD.org
> Am I Evil? Yes, I Am!                     http://yomoli.com


--------
This message has been scanned by ComplianceSafe, powered by Palisade's PacketSure.


More information about the svn-src-all mailing list