dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit b5ff5e6bc9ecfe59291223d7461f52c5f3ab4922
parent 7d90970f247196d57f65e6add8484bb1eacab993
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Tue,  4 May 2010 13:01:57 +0200

Close open file descriptors before forking

Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>

Diffstat:
madtty.c | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/madtty.c b/madtty.c @@ -1204,6 +1204,7 @@ pid_t madtty_forkpty(madtty_t *t, const char *p, const char *argv[], const char struct winsize ws; pid_t pid; const char **envp = env; + int fd, maxfd; ws.ws_row = t->rows; ws.ws_col = t->cols; @@ -1215,6 +1216,12 @@ pid_t madtty_forkpty(madtty_t *t, const char *p, const char *argv[], const char if (pid == 0) { setsid(); + + maxfd = sysconf(_SC_OPEN_MAX); + for (fd = 3; fd < maxfd; fd++) + if (close(fd) == EBADF) + break; + while (envp && envp[0]) { setenv(envp[0], envp[1], 1); envp += 2;