diff options
-rw-r--r-- | runtime/staprun/ChangeLog | 7 | ||||
-rw-r--r-- | runtime/staprun/common.c | 19 | ||||
-rw-r--r-- | runtime/staprun/ctl.c | 3 | ||||
-rw-r--r-- | runtime/staprun/relay.c | 6 | ||||
-rw-r--r-- | runtime/staprun/relay_old.c | 12 | ||||
-rw-r--r-- | runtime/staprun/staprun.h | 1 |
6 files changed, 45 insertions, 3 deletions
diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog index cebaeb2c..4e23c424 100644 --- a/runtime/staprun/ChangeLog +++ b/runtime/staprun/ChangeLog @@ -1,3 +1,10 @@ +2007-10-09 Martin Hunt <hunt@redhat.com> + + * 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 <hunt@redhat.com> * 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 d3f8835a..47778efd 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 d0b07260..7fe57206 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 30c4ce1e..538d027c 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 3f65acbb..f138aee5 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 1b0f3221..685de294 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 |