Author: jh
Date: Sat Nov 13 09:28:49 2010
New Revision: 215235
URL: http://svn.freebsd.org/changeset/base/215235

Log:
  Set FD_CLOEXEC for the output file only when the file has been specified
  with the -o option. Setting the flag for stderr (the default) could
  cause the traced process to redirect stderr to a random file.
  
  PR:           bin/152151
  Submitted by: ashish
  MFC after:    5 days

Modified:
  head/usr.bin/truss/main.c

Modified: head/usr.bin/truss/main.c
==============================================================================
--- head/usr.bin/truss/main.c   Sat Nov 13 08:58:36 2010        (r215234)
+++ head/usr.bin/truss/main.c   Sat Nov 13 09:28:49 2010        (r215235)
@@ -241,13 +241,14 @@ main(int ac, char **av)
        if (fname != NULL) { /* Use output file */
                if ((trussinfo->outfile = fopen(fname, "w")) == NULL)
                        errx(1, "cannot open %s", fname);
+               /*
+                * Set FD_CLOEXEC, so that the output file is not shared with
+                * the traced process.
+                */
+               if (fcntl(fileno(trussinfo->outfile), F_SETFD, FD_CLOEXEC) ==
+                   -1)
+                       warn("fcntl()");
        }
-       /*
-        * Set FD_CLOEXEC, so that the output file is not shared with
-        * the traced process.
-        */
-       if (fcntl(fileno(trussinfo->outfile), F_SETFD, FD_CLOEXEC) == -1)
-               warn("fcntl()");
 
        /*
         * If truss starts the process itself, it will ignore some signals --
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to