From 5053ea39ff884a26e4f295ef081414bf2704c37a Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 16 May 2015 00:27:06 +0000 Subject: - bugfix for forbacktickx: now stdin is correctly transmitted to the loop - possible bugfix for forstdin: -p was failing in some cases with ECHILD in the final waitn. I couldn't figure it out (the code looked right...) so I changed the logic, scrapping the call to waitn. - rc for 2.1.2.2 --- src/execline/forbacktickx.c | 23 ++++++++++++++++++++++- src/execline/forstdin.c | 12 ++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/execline/forbacktickx.c b/src/execline/forbacktickx.c index 0e58106..9301581 100644 --- a/src/execline/forbacktickx.c +++ b/src/execline/forbacktickx.c @@ -1,6 +1,9 @@ /* ISC license. */ +#include +#include #include +#include #include #include #include @@ -62,7 +65,14 @@ int main (int argc, char const **argv, char const *const *envp) if (!argv[1][0]) strerr_dief1x(100, "empty block") ; { unsigned int m = 0, i = 1 ; - char const *newargv[argc + 15] ; + int fd = dup(0) ; + char const *newargv[argc + 18] ; + char fmt[UINT_FMT] ; + if (fd < 0) + { + if (errno != EBADF) strerr_diefu1sys(111, "dup stdin") ; + } + else fmt[uint_fmt(fmt, (unsigned int)fd)] = 0 ; newargv[m++] = EXECLINE_BINPREFIX "pipeline" ; newargv[m++] = "--" ; while (argv[i] && argv[i][0] != EXECLINE_BLOCK_END_CHAR && (!EXECLINE_BLOCK_END_CHAR || (argv[i][0] && argv[i][1]))) @@ -88,6 +98,17 @@ int main (int argc, char const **argv, char const *const *envp) } newargv[m++] = "--" ; newargv[m++] = argv[0] ; + if (fd < 0) + { + newargv[m++] = EXECLINE_BINPREFIX "fdclose" ; + newargv[m++] = "0" ; + } + else + { + newargv[m++] = EXECLINE_BINPREFIX "fdmove" ; + newargv[m++] = "0" ; + newargv[m++] = fmt ; + } while (argv[i]) newargv[m++] = argv[i++] ; newargv[m++] = 0 ; pathexec_run(newargv[0], newargv, envp) ; diff --git a/src/execline/forstdin.c b/src/execline/forstdin.c index 1e9d5e6..3fb52eb 100644 --- a/src/execline/forstdin.c +++ b/src/execline/forstdin.c @@ -147,11 +147,11 @@ int main (int argc, char const **argv, char const *const *envp) stralloc_free(&modif) ; } if (pids.s) - { - if (sig_restore(SIGCHLD) < 0) - strerr_diefu2sys(111, "restore", " SIGCHLD handler") ; - if (!waitn(genalloc_s(pid_t, &pids), genalloc_len(pid_t, &pids))) - strerr_diefu1sys(111, "waitn") ; - } + for (;;) + { + sig_block(SIGCHLD) ; + if (!pids.len) break ; + sig_pause() ; + } return 0 ; } -- cgit v1.3.1