From ecbb6d348f381253ff0c15b5022fa287f0acfac5 Mon Sep 17 00:00:00 2001 From: Jaakko Heinonen Date: Sun, 20 Dec 2009 11:00:53 +0000 Subject: [PATCH] Avoid sharing the file descriptor of the output file with traced processes by setting the FD_CLOEXEC flag for the output file. PR: bin/140493 Submitted by: Erik Lax OK'ed by: delphij Approved by: trasz (mentor) --- usr.bin/truss/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index d0dd073e632..586fcd64299 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -239,6 +239,12 @@ main(int ac, char **av) 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()"); /* * If truss starts the process itself, it will ignore some signals --