* common.c (set_clexec): New.
* staprun.h: Add prototype for set_clexec.
* relay*.c, ctl.c: Call set_clexec after
file opens.
+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
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;
+}
perr("Couldn't open control channel '%s'", buf);
return -1;
}
+ if (set_clexec(control_channel) < 0)
+ return -1;
+
return old_transport;
}
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;
perr("Couldn't open output file %s", buf);
return -1;
}
+ if (set_clexec(out_fd[i]) < 0)
+ return -1;
}
} else {
/* stream mode */
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;
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;
}
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
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,
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;
}
void usage(char *prog);
void parse_modpath(const char *);
void setup_signals(void);
+int set_clexec(int fd);
/*
* variables