]> sourceware.org Git - systemtap.git/commitdiff
2007-10-09 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Tue, 9 Oct 2007 16:03:04 +0000 (16:03 +0000)
committerhunt <hunt>
Tue, 9 Oct 2007 16:03:04 +0000 (16:03 +0000)
* common.c (set_clexec): New.
* staprun.h: Add prototype for set_clexec.
* relay*.c, ctl.c: Call set_clexec after
file opens.

runtime/staprun/ChangeLog
runtime/staprun/common.c
runtime/staprun/ctl.c
runtime/staprun/relay.c
runtime/staprun/relay_old.c
runtime/staprun/staprun.h

index cebaeb2c421b7f00b7daea3a295ff06361ca79f1..4e23c4245a9d5b3d9a1e086ec036f726860d1aa0 100644 (file)
@@ -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
index d3f8835a9ebf635ae82f237592c15841cdbf1439..47778efd598ad0f4fa1e3259647d9b9dce04a93b 100644 (file)
@@ -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;
+}
index d0b0726051c828cd041a1dfc7dc6925f49ab666b..7fe572069cf8cb0a6b968b7a3015820ae4afeb33 100644 (file)
@@ -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;
 }
 
index 30c4ce1e1ef2d482518106b8d662e77333f39ece..538d027cd2f9bff20ea2d74e64e0179869eca064 100644 (file)
@@ -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;
                
index 3f65acbb16c0d6fbbe9b29e10228ad1e2f04ad09..f138aee51572984caf24ea82ea833479bbeca78a 100644 (file)
@@ -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;
                        }
index 1b0f322130c440e79b8358db2a9ee9790d017b90..685de2946257ca333c9d73408971152ae25af4dd 100644 (file)
@@ -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 
This page took 0.035811 seconds and 5 git commands to generate.