From 80767b1fa970d90bd78d7a7e119f4a5407e387a1 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 20 Jun 2022 12:54:25 +0100 Subject: [PATCH] Revert "Fix "/dev/null: cannot create [Bad file descriptor]" (re: feeb62d1)" This reverts commit a72ba2cf596542ad7978f02395d4f5da3a7bba17. It's broken: test coprocess begins at 2022-06-20+02:34:59 coprocess.sh[198]: FAIL: traps when reading from cat coprocess not working coprocess.sh[198]: FAIL: traps when reading from /bin/cat coprocess not working test coprocess failed at 2022-06-20+02:35:01 with exit code 2 [ 32 tests 2 errors ] Reopens: https://github.com/ksh93/ksh/issues/483 --- src/cmd/ksh93/sh/io.c | 4 ++-- src/cmd/ksh93/sh/jobs.c | 9 ++++----- src/cmd/ksh93/sh/path.c | 7 ++----- src/cmd/ksh93/sh/subshell.c | 6 ++---- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index fc88cb0bc..5db81ba3e 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -1045,9 +1045,9 @@ static Sfoff_t file_offset(int fn, char *fname) */ void sh_pclose(register int pv[]) { - if(pv[0] > -1) + if(pv[0]>=2) sh_close(pv[0]); - if(pv[1] > -1) + if(pv[1]>=2) sh_close(pv[1]); pv[0] = pv[1] = -1; } diff --git a/src/cmd/ksh93/sh/jobs.c b/src/cmd/ksh93/sh/jobs.c index 0d55fe9b4..27abc493b 100644 --- a/src/cmd/ksh93/sh/jobs.c +++ b/src/cmd/ksh93/sh/jobs.c @@ -396,11 +396,10 @@ int job_reap(register int sig) /* check for coprocess completion */ if(pid==sh.cpid) { - if(sh.coutpipe > -1) - sh_close(sh.coutpipe); - if(sh.cpipe[1] > -1) - sh_close(sh.cpipe[1]); - sh.coutpipe = sh.cpipe[1] = -1; + sh_close(sh.coutpipe); + sh_close(sh.cpipe[1]); + sh.cpipe[1] = -1; + sh.coutpipe = -1; } else if(sh.subshell) sh_subjobcheck(pid); diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 363a1debf..e3bda4046 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -1275,13 +1275,10 @@ static noreturn void exscript(register char *path,register char *argv[],char **e sh.bckpid = 0; sh.st.ioset=0; /* clean up any cooperating processes */ - if(sh.cpipe[0] > -1) + if(sh.cpipe[0]>0) sh_pclose(sh.cpipe); - if(sh.cpid && sh.outpipe && *sh.outpipe > -1) - { + if(sh.cpid && sh.outpipe) sh_close(*sh.outpipe); - *sh.outpipe = -1; - } sh.cpid = 0; if(sp=fcfile()) while(sfstack(sp,SF_POPSTACK)); diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index 92b2a78a7..05dbdf2cd 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -455,10 +455,8 @@ void sh_subjobcheck(pid_t pid) { if(sp->cpid==pid) { - if(sp->coutpipe > -1) - sh_close(sp->coutpipe); - if(sp->cpipe > -1) - sh_close(sp->cpipe); + sh_close(sp->coutpipe); + sh_close(sp->cpipe); sp->coutpipe = sp->cpipe = -1; return; }