bin/140493: truss(1) log file descriptor shared with traced program

Erik erik at datahack.se
Thu Nov 12 17:30:04 UTC 2009


The following reply was made to PR bin/140493; it has been noted by GNATS.

From: Erik <erik at datahack.se>
To: bug-followup at FreeBSD.org, erik at datahack.se
Cc:  
Subject: Re: bin/140493: truss(1) log file descriptor shared with traced program
Date: Thu, 12 Nov 2009 18:06:41 +0100

 This is a multi-part message in MIME format.
 --------------020501070508070709040003
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Not reporting issues 10pm...we could of course set FD_CLOEXEC on the fd. 
 See proposed patched.
 
 --------------020501070508070709040003
 Content-Type: text/x-patch;
  name="truss-cloexec.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="truss-cloexec.patch"
 
 --- main.c-original	2009-11-12 18:52:25.000000000 +0000
 +++ main.c	2009-11-12 18:59:42.000000000 +0000
 @@ -227,6 +227,17 @@
  	if (fname != NULL) { /* Use output file */
  		if ((trussinfo->outfile = fopen(fname, "w")) == NULL)
  			errx(1, "cannot open %s", fname);
 +
 +		/*
 +		 * Do not share the file descriptor with the traced
 +		 * process executed with execvp().
 +		 */
 +		int fd = fileno(trussinfo->outfile);
 +		int flags = fcntl(fd, F_GETFD, 0);
 +		if (flags != -1)
 +		{
 +			fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
 +		}
  	}
  
  	/*
 
 --------------020501070508070709040003--


More information about the freebsd-bugs mailing list