1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-31 06:00:54 +01:00

41789: Don't save fd if -1.

We try to move an fd which isn't opend but it will feel.
This needs handling specially in the new code for marking
saved fd's.
This commit is contained in:
Peter Stephenson 2017-09-29 16:29:49 +01:00
parent 7cb55668c2
commit a1276c88e1
2 changed files with 16 additions and 8 deletions

View file

@ -2325,16 +2325,19 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag,
* fd1 may already be closed here, so
* ignore bad file descriptor error
*/
if (fdN < 0 && errno != EBADF) {
zerr("cannot duplicate fd %d: %e", fd1, errno);
mfds[fd1] = NULL;
closemnodes(mfds);
return;
if (fdN < 0) {
if (errno != EBADF) {
zerr("cannot duplicate fd %d: %e", fd1, errno);
mfds[fd1] = NULL;
closemnodes(mfds);
return;
}
} else {
DPUTS(fdtable[fdN] != FDT_INTERNAL,
"Saved file descriptor not marked as internal");
fdtable[fdN] |= FDT_SAVED_MASK;
}
save[fd1] = fdN;
DPUTS(fdtable[fdN] != FDT_INTERNAL,
"Saved file descriptor not marked as internal");
fdtable[fdN] |= FDT_SAVED_MASK;
}
}
}