diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2010-10-16 08:31:55 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2010-10-16 08:31:55 +0000 |
commit | f56b4ec2ffa6d5667a3bd86040a1c771c1de33a5 (patch) | |
tree | a06294130e18067eca755eb7e91ad6faa548e55c | |
parent | 6c42f1a89e16d69d5fe24bb8b3f6b37148cfa308 (diff) |
Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.
-rw-r--r-- | client.c | 2 | ||||
-rw-r--r-- | cmd-pipe-pane.c | 4 | ||||
-rw-r--r-- | job.c | 4 | ||||
-rw-r--r-- | server-client.c | 8 | ||||
-rw-r--r-- | server.c | 2 | ||||
-rw-r--r-- | tmux.c | 2 | ||||
-rw-r--r-- | tty.c | 3 | ||||
-rw-r--r-- | window.c | 4 |
8 files changed, 8 insertions, 21 deletions
@@ -90,8 +90,6 @@ server_started: fatal("fcntl failed"); if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); imsg_init(&client_ibuf, fd); event_set(&client_event, fd, EV_READ, client_callback, NULL); diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index be6f8e25..d287d3b6 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -112,6 +112,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO) close(null_fd); + closefrom(STDERR_FILENO + 1); + command = status_replace(c, NULL, data->arg, time(NULL), 0); execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL); _exit(1); @@ -130,8 +132,6 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) fatal("fcntl failed"); if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); - if (fcntl(wp->pipe_fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); return (0); } } @@ -169,6 +169,8 @@ job_run(struct job *job) if (nullfd != STDIN_FILENO && nullfd != STDERR_FILENO) close(nullfd); + closefrom(STDERR_FILENO + 1); + execl(_PATH_BSHELL, "sh", "-c", job->cmd, (char *) NULL); fatal("execl failed"); default: /* parent */ @@ -179,8 +181,6 @@ job_run(struct job *job) fatal("fcntl failed"); if (fcntl(job->fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); - if (fcntl(job->fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); if (job->event != NULL) bufferevent_free(job->event); diff --git a/server-client.c b/server-client.c index 427f8dfb..cd3eb079 100644 --- a/server-client.c +++ b/server-client.c @@ -60,8 +60,6 @@ server_client_create(int fd) fatal("fcntl failed"); if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); c = xcalloc(1, sizeof *c); c->references = 0; @@ -706,8 +704,6 @@ server_client_msg_dispatch(struct client *c) if ((mode = fcntl(c->stdin_fd, F_GETFL)) != -1) fcntl(c->stdin_fd, F_SETFL, mode|O_NONBLOCK); - if (fcntl(c->stdin_fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); server_client_msg_identify(c, &identifydata, imsg.fd); break; @@ -725,8 +721,6 @@ server_client_msg_dispatch(struct client *c) if ((mode = fcntl(c->stdout_fd, F_GETFL)) != -1) fcntl(c->stdout_fd, F_SETFL, mode|O_NONBLOCK); - if (fcntl(c->stdout_fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); break; case MSG_STDERR: if (datalen != 0) @@ -742,8 +736,6 @@ server_client_msg_dispatch(struct client *c) if ((mode = fcntl(c->stderr_fd, F_GETFL)) != -1) fcntl(c->stderr_fd, F_SETFL, mode|O_NONBLOCK); - if (fcntl(c->stderr_fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); break; case MSG_RESIZE: if (datalen != 0) @@ -98,8 +98,6 @@ server_create_socket(void) fatal("fcntl failed"); if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); server_update_socket(); @@ -223,6 +223,8 @@ shell_exec(const char *shell, const char *shellcmd) xasprintf(&argv0, "%s", shellname); setenv("SHELL", shell, 1); + closefrom(STDERR_FILENO + 1); + execl(shell, argv0, "-c", shellcmd, (char *) NULL); fatal("execl failed"); } @@ -61,9 +61,6 @@ tty_init(struct tty *tty, int fd, char *term) tty->termname = xstrdup("unknown"); else tty->termname = xstrdup(term); - - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); tty->fd = fd; if ((path = ttyname(fd)) == NULL) @@ -573,6 +573,8 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell, if (tcsetattr(STDIN_FILENO, TCSANOW, &tio2) != 0) fatal("tcgetattr failed"); + closefrom(STDERR_FILENO + 1); + environ_push(env); clear_signals(1); @@ -603,8 +605,6 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell, fatal("fcntl failed"); if (fcntl(wp->fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); - if (fcntl(wp->fd, F_SETFD, FD_CLOEXEC) == -1) - fatal("fcntl failed"); wp->event = bufferevent_new(wp->fd, window_pane_read_callback, NULL, window_pane_error_callback, wp); bufferevent_enable(wp->event, EV_READ|EV_WRITE); |