From: hunt Date: Tue, 9 Oct 2007 16:03:04 +0000 (+0000) Subject: 2007-10-09 Martin Hunt X-Git-Tag: release-0.6~89 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=577e7ed19be74db082ba058016fd31b643495ebd;p=systemtap.git 2007-10-09 Martin Hunt * common.c (set_clexec): New. * staprun.h: Add prototype for set_clexec. * relay*.c, ctl.c: Call set_clexec after file opens. --- diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog index cebaeb2c4..4e23c4245 100644 --- a/runtime/staprun/ChangeLog +++ b/runtime/staprun/ChangeLog @@ -1,3 +1,10 @@ +2007-10-09 Martin Hunt + + * common.c (set_clexec): New. + * staprun.h: Add prototype for set_clexec. + * relay*.c, ctl.c: Call set_clexec after + file opens. + 2007-09-14 Martin Hunt * ctl.c (init_ctl_channel): Return 1 if the ctl file opened diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c index d3f8835a9..47778efd5 100644 --- a/runtime/staprun/common.c +++ b/runtime/staprun/common.c @@ -315,3 +315,22 @@ int send_request(int type, void *data, int len) memcpy(&buf[4], data, len); return write(control_channel, buf, len+4); } + +/* + * set FD_CLOEXEC for any file descriptor + */ +int set_clexec(int fd) +{ + int val; + if ((val = fcntl(fd, F_GETFD, 0)) < 0) + goto err; + + if ((val = fcntl(fd, F_SETFD, val | FD_CLOEXEC)) < 0) + goto err; + + return 0; +err: + perr("fcntl failed"); + close(fd); + return -1; +} diff --git a/runtime/staprun/ctl.c b/runtime/staprun/ctl.c index d0b072605..7fe572069 100644 --- a/runtime/staprun/ctl.c +++ b/runtime/staprun/ctl.c @@ -36,6 +36,9 @@ int init_ctl_channel(void) perr("Couldn't open control channel '%s'", buf); return -1; } + if (set_clexec(control_channel) < 0) + return -1; + return old_transport; } diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c index 30c4ce1e1..538d027cd 100644 --- a/runtime/staprun/relay.c +++ b/runtime/staprun/relay.c @@ -148,7 +148,7 @@ int init_relayfs(void) return -1; dbug(2, "attempting to open %s\n", buf); relay_fd[i] = open(buf, O_RDONLY | O_NONBLOCK); - if (relay_fd[i] < 0) + if (relay_fd[i] < 0 || set_clexec(relay_fd[i]) < 0) break; } ncpus = i; @@ -184,6 +184,8 @@ int init_relayfs(void) perr("Couldn't open output file %s", buf); return -1; } + if (set_clexec(out_fd[i]) < 0) + return -1; } } else { /* stream mode */ @@ -193,6 +195,8 @@ int init_relayfs(void) perr("Couldn't open output file %s", outfile_name); return -1; } + if (set_clexec(out_fd[i]) < 0) + return -1; } else out_fd[0] = STDOUT_FILENO; diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c index 3f65acbb1..f138aee51 100644 --- a/runtime/staprun/relay_old.c +++ b/runtime/staprun/relay_old.c @@ -86,7 +86,7 @@ static int open_relayfs_files(int cpu, const char *relay_filebase, const char *p return -1; dbug(2, "Opening %s.\n", tmp); relay_fd[cpu] = open(tmp, O_RDONLY | O_NONBLOCK); - if (relay_fd[cpu] < 0) { + if (relay_fd[cpu] < 0 || set_clexec(relay_fd[cpu]) < 0) { relay_fd[cpu] = 0; return 0; } @@ -99,6 +99,10 @@ static int open_relayfs_files(int cpu, const char *relay_filebase, const char *p perr("Couldn't open proc file %s", tmp); goto err1; } + if (set_clexec(relay_fd[cpu]) < 0) { + relay_fd[cpu] = 0; + return -1; + } if (outfile_name) { /* special case: for testing we sometimes want to @@ -118,6 +122,10 @@ static int open_relayfs_files(int cpu, const char *relay_filebase, const char *p perr("Couldn't open output file %s", tmp); goto err2; } + if (set_clexec(fileno(percpu_tmpfile[cpu])) < 0) { + perr("Couldn't open output file %s", tmp); + goto err2; + } total_bufsize = subbuf_size * n_subbufs; relay_buffer[cpu] = mmap(NULL, total_bufsize, PROT_READ, @@ -243,7 +251,7 @@ int init_oldrelayfs(void) if (!bulkmode) { if (outfile_name) { out_fd[0] = open (outfile_name, O_CREAT|O_TRUNC|O_WRONLY, 0666); - if (out_fd[0] < 0) { + if (out_fd[0] < 0 || set_clexec(out_fd[0]) < 0) { perr("Couldn't open output file '%s'", outfile_name); return -1; } diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h index 1b0f32213..685de2946 100644 --- a/runtime/staprun/staprun.h +++ b/runtime/staprun/staprun.h @@ -152,6 +152,7 @@ void parse_args(int argc, char **argv); void usage(char *prog); void parse_modpath(const char *); void setup_signals(void); +int set_clexec(int fd); /* * variables