From acd647c8774a556d0df77e6779867f9fa069cd22 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 16 Aug 2004 08:38:34 +0000 Subject: [PATCH] Joe.C writes: This bug is in busybox 1.0.0-rc2. When using lash exec builtin with redirection, the opened file fd keep increasing. For example, please try the following command with lash. ls -al /proc//fd exec /bin/sh 2>/dev/null ls -al /proc//fd The last 'ls' command output will look like this. The fd number 4 shouldn't exist. lrwx------ 1 501 100 64 Aug 13 13:56 4 -> /dev/pts/5 l-wx------ 1 501 100 64 Aug 13 13:56 2 -> /dev/null lrwx------ 1 501 100 64 Aug 13 13:56 1 -> /dev/pts/5 lrwx------ 1 501 100 64 Aug 13 13:56 0 -> /dev/pts/5 dr-xr-xr-x 3 501 100 0 Aug 13 13:56 .. dr-x------ 2 501 100 0 Aug 13 13:56 . This one-line patch fix this problem by setting CLOEXEC flag for squirrel fd. Please apply. Joe.C --- shell/lash.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/lash.c b/shell/lash.c index fa416c742..f454e6990 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -656,6 +656,7 @@ static int setup_redirects(struct child_prog *prog, int squirrel[]) if (openfd != redir->fd) { if (squirrel && redir->fd < 3) { squirrel[redir->fd] = dup(redir->fd); + fcntl (squirrel[redir->fd], F_SETFD, FD_CLOEXEC); } dup2(openfd, redir->fd); close(openfd);