tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: /bin/sh redirection in 'while' loop not closed afterwards?



On Monday, at 22:23, David Laight wrote:
| At a guess the fd for redirection usually get opened, duped above 10, then
| duped to the required number very late on (in the child).

Yes, exactly.
The problem seems to appear around redir.c:144

fcntl() returns EBADF, 'try' is incremented and the redirection is never
registered in sv->renamed. Then popredir() does not undo it afterwards.

With a simpler redirection like "ls 9</dev/null" fcntl does not return EBADF.
So I'm not sure what's wrong.

again:
                        if ((i = fcntl(fd, F_DUPFD, 10)) == -1) {
                                switch (errno) {
                                case EBADF:
                                        if (!try) {
                                                openredirect(n, memory, flags);
                                                try++;
                                                goto again;
                                        }
[...]
                        }
                        if (!try) {
                                sv->renamed[fd] = i;
                                close(fd);
                        }



| The redirect on a while loop (or any other builtin) forces a subshell
| so something is probably suspect in that subshell path.

I think there is no subshell. At least I don't see it while follwing the code
under gdb and that's also how I understand how it works. evaltree() gets called
thrice with NREDIR, NWHILE and NCMD. But I may miss something.


Home | Main Index | Thread Index | Old Index