mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-08 12:01:21 +02:00
29561: Allow closing of fd's not recorded by the shell
This commit is contained in:
parent
164cf1abd5
commit
45913f43e5
3 changed files with 31 additions and 22 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2011-07-25 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* 29561: Src/exec.c, Src/utils.c, Test/A04redirect.ztst: Allow
|
||||||
|
closing of file descriptors not recorded internally by the shell.
|
||||||
|
|
||||||
2011-07-22 Mikael Magnusson <mikachu@gmail.com>
|
2011-07-22 Mikael Magnusson <mikachu@gmail.com>
|
||||||
|
|
||||||
* 29596: Completion/compinit: Fix syntax to work with KSH_ARRAYS
|
* 29596: Completion/compinit: Fix syntax to work with KSH_ARRAYS
|
||||||
|
@ -15154,5 +15159,5 @@
|
||||||
|
|
||||||
*****************************************************
|
*****************************************************
|
||||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||||
* $Revision: 1.5406 $
|
* $Revision: 1.5407 $
|
||||||
*****************************************************
|
*****************************************************
|
||||||
|
|
18
Src/exec.c
18
Src/exec.c
|
@ -2975,17 +2975,16 @@ execcmd(Estate state, int input, int output, int how, int last1)
|
||||||
fn->fd1 = (int)getintvalue(v);
|
fn->fd1 = (int)getintvalue(v);
|
||||||
if (errflag)
|
if (errflag)
|
||||||
bad = 1;
|
bad = 1;
|
||||||
else if (fn->fd1 > max_zsh_fd)
|
else if (fn->fd1 <= max_zsh_fd) {
|
||||||
bad = 3;
|
if (fn->fd1 >= 10 &&
|
||||||
else if (fn->fd1 >= 10 &&
|
|
||||||
fdtable[fn->fd1] == FDT_INTERNAL)
|
fdtable[fn->fd1] == FDT_INTERNAL)
|
||||||
bad = 4;
|
bad = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (bad) {
|
if (bad) {
|
||||||
const char *bad_msg[] = {
|
const char *bad_msg[] = {
|
||||||
"parameter %s does not contain a file descriptor",
|
"parameter %s does not contain a file descriptor",
|
||||||
"can't close file descriptor from readonly parameter %s",
|
"can't close file descriptor from readonly parameter %s",
|
||||||
"file descriptor %d out of range, not closed",
|
|
||||||
"file descriptor %d used by shell, not closed"
|
"file descriptor %d used by shell, not closed"
|
||||||
};
|
};
|
||||||
if (bad > 2)
|
if (bad > 2)
|
||||||
|
@ -2995,11 +2994,18 @@ execcmd(Estate state, int input, int output, int how, int last1)
|
||||||
execerr();
|
execerr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* Note we may attempt to close an fd beyond max_zsh_fd:
|
||||||
|
* OK as long as we never look in fdtable for it.
|
||||||
|
*/
|
||||||
if (!forked && fn->fd1 < 10 && save[fn->fd1] == -2)
|
if (!forked && fn->fd1 < 10 && save[fn->fd1] == -2)
|
||||||
save[fn->fd1] = movefd(fn->fd1);
|
save[fn->fd1] = movefd(fn->fd1);
|
||||||
if (fn->fd1 < 10)
|
if (fn->fd1 < 10)
|
||||||
closemn(mfds, fn->fd1);
|
closemn(mfds, fn->fd1);
|
||||||
zclose(fn->fd1);
|
if (zclose(fn->fd1) < 0) {
|
||||||
|
zwarn("failed to close file descriptor %d: %e",
|
||||||
|
fn->fd1, errno);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REDIR_MERGEIN:
|
case REDIR_MERGEIN:
|
||||||
case REDIR_MERGEOUT:
|
case REDIR_MERGEOUT:
|
||||||
|
|
10
Src/utils.c
10
Src/utils.c
|
@ -1802,13 +1802,10 @@ zclose(int fd)
|
||||||
{
|
{
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
/*
|
/*
|
||||||
* We sometimes zclose() an fd twice where the second
|
* Careful: we allow closing of arbitrary fd's, beyond
|
||||||
* time is a catch-all in case there was a failure using
|
* max_zsh_fd. In that case we don't try anything clever.
|
||||||
* the fd. This is harmless but we need to trap it
|
|
||||||
* for the error check here.
|
|
||||||
*/
|
*/
|
||||||
DPUTS2(fd > max_zsh_fd && fdtable[fd] != FDT_UNUSED,
|
if (fd <= max_zsh_fd) {
|
||||||
"BUG: fd is %d, max_zsh_fd is %d", fd, max_zsh_fd);
|
|
||||||
if (fdtable[fd] == FDT_FLOCK)
|
if (fdtable[fd] == FDT_FLOCK)
|
||||||
fdtable_flocks--;
|
fdtable_flocks--;
|
||||||
fdtable[fd] = FDT_UNUSED;
|
fdtable[fd] = FDT_UNUSED;
|
||||||
|
@ -1818,6 +1815,7 @@ zclose(int fd)
|
||||||
coprocin = -1;
|
coprocin = -1;
|
||||||
if (fd == coprocout)
|
if (fd == coprocout)
|
||||||
coprocout = -1;
|
coprocout = -1;
|
||||||
|
}
|
||||||
return close(fd);
|
return close(fd);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue