diff options
author | jh <jh@FreeBSD.org> | 2010-11-13 09:28:49 +0000 |
---|---|---|
committer | jh <jh@FreeBSD.org> | 2010-11-13 09:28:49 +0000 |
commit | 2b1dea9bfc97c67898a6be457bf8a0d422046fbf (patch) | |
tree | b9179c9b7168608a1d05662c6a11501de6ebb23e | |
parent | ddac66fcc1cfaa77c9fd52a89bb1aaab313d3ee4 (diff) | |
download | FreeBSD-src-2b1dea9bfc97c67898a6be457bf8a0d422046fbf.zip FreeBSD-src-2b1dea9bfc97c67898a6be457bf8a0d422046fbf.tar.gz |
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
-rw-r--r-- | usr.bin/truss/main.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index b9dcfe4..d25c4de 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -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 -- |