From: Wichert Akkerman Date: Fri, 3 Aug 2001 11:43:35 +0000 (+0000) Subject: set CLOEXEC flag for outputfile X-Git-Tag: v4.5.18~1028 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54b4f79216c819ec93aaf5031acb1772fccef7a9;p=strace set CLOEXEC flag for outputfile --- diff --git a/ChangeLog b/ChangeLog index dfd18dca..25ebed66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2001-08-03 Wichert Akkerman + + * strace.c: set CLOEXEC flag for outputfile + 2001-08-03 Wichert Akkerman * linux/sparc/syscall.h, linux/sparc/syscallent.h: add some LFS calls diff --git a/strace.c b/strace.c index 083e850c..dd3e9356 100644 --- a/strace.c +++ b/strace.c @@ -314,11 +314,23 @@ char *argv[]; /* Check if they want to redirect the output. */ if (outfname) { + long f; + if ((outf = fopen(outfname, "w")) == NULL) { fprintf(stderr, "%s: can't fopen '%s': %s\n", progname, outfname, strerror(errno)); exit(1); } + + if ((f=fcntl(fileno(outf), F_GETFD)) < 0 ) { + perror("failed to get flags for outputfile"); + exit(1); + } + + if (fcntl(fileno(outf), F_SETFD, f|FD_CLOEXEC) < 0 ) { + perror("failed to set flags for outputfile"); + exit(1); + } } #ifndef SVR4