forwarded 357091 upstream quit Hi Rainer, thanks for the report and patch, and sorry for taking that long to reply.
Hi Herbert, please see below, I can confirm that it's an issue, and the patch fixes it for me too. I didn't check the patch thoroughly though. Thanks, Gerrit. On Wed, Mar 15, 2006 at 05:29:42PM +0100, Rainer Weikusat wrote: > Package: dash > Version: 0.5.2-5 > > dash does not handle initially closed descriptors in any > way when redirecting, which leads to 'strange' anomalies and > can be the cause of somehwat puzzling script misbehaviour. > > Two examples: > > Script 1: > ---------- > exec >&- > exec 3>bork > > printf "x\n" >&3 > > printf 55 > > ---------- > > Executing this code with dash will lead to bork being > open on stdout after the printf redirection, so the contents > will be > > x > 55 > > and not just x. > > Script 2: > --------- > exec >&- > > printf "x\n" >nork > > printf 55 > > ---------- > > Executing this code with dash will lead to nork being open > on stdout after the printf, same effect as above. Both of > this is out-of-spec wrt to SUS, cf > > Utilities other than the special built-ins (see Special > Built-In Utilities) shall be invoked in a separate environment > that consists of the following. The initial value of these > objects shall be the same as that for the parent shell, except > as noted below. > > * Open files inherited on invocation of the shell, open > files controlled by the exec special built-in plus any > modifications, and additions specified by any > redirections to the utility > > > [...] > > The environment of the shell process shall not be changed by > the utility unless explicitly specified by the utility > description (for example, cd and umask). > > (<URL:http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_12>) > > A patch that corrects this (for me): > > diff -ru dash-0.5.2/src/redir.c dash-orig/src/redir.c > --- dash-0.5.2/src/redir.c 2003-09-27 05:45:00.000000000 +0200 > +++ dash-orig/src/redir.c 2006-03-15 17:14:17.000000000 +0100 > @@ -70,6 +70,7 @@ > #include "error.h" > > > +#define CLOSEFD -3 /* fd opened for redir needs to be closed */ > #define EMPTY -2 /* marks an unused slot in redirtab */ > #ifndef PIPE_BUF > # define PIPESIZE 4096 /* amount of buffering in a pipe */ > @@ -148,10 +149,15 @@ > continue; /* redirect from/to same file descriptor */ > > newfd = openredirect(n); > - if (fd == newfd) > - continue; > if (sv && *(p = &sv->renamed[fd]) == EMPTY) { > - int i = fcntl(fd, F_DUPFD, 10); > + int i; > + > + if (fd == newfd) { > + *p = CLOSEFD; > + continue; > + } > + > + i = fcntl(fd, F_DUPFD, 10); > if (i == -1) { > i = errno; > if (i != EBADF) { > @@ -159,7 +165,7 @@ > close(newfd); > error("%d: %s", fd, m); > /* NOTREACHED */ > - } > + } else *p = CLOSEFD; > } else { > *p = i; > close(fd); > @@ -342,7 +348,8 @@ > if (rp->renamed[i] != EMPTY) { > if (!drop) { > close(i); > - copyfd(rp->renamed[i], i); > + if (rp->renamed[i] != CLOSEFD) > + copyfd(rp->renamed[i], i); > } > close(rp->renamed[i]); > } > -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]