summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-05-16 00:27:06 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-05-16 00:27:06 +0000
commit5053ea39ff884a26e4f295ef081414bf2704c37a (patch)
tree3308f589eae6cc5c1378cdda66ceaca5ad67c05d /src
parentb42e1a56a48282be171cc5c094a8b0a3b55da453 (diff)
downloadexecline-5053ea39ff884a26e4f295ef081414bf2704c37a.tar.xz
- 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
Diffstat (limited to 'src')
-rw-r--r--src/execline/forbacktickx.c23
-rw-r--r--src/execline/forstdin.c12
2 files changed, 28 insertions, 7 deletions
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 <unistd.h>
+#include <errno.h>
#include <skalibs/ushort.h>
+#include <skalibs/uint.h>
#include <skalibs/bytestr.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
@@ -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 ;
}