Broken PIPESTATUS with --disable-job-control

2016-09-17 Thread Felix Janda
Hello,

below this mail you can find a minimal script misbehaving when
job-control is configured out (tested on linx with different archs,
libc's, and versions (including current git)).

Notice that the configure script disables job-control when a run-time
test (which could easily be a built-time test) fails. So by default,
a cross-compiled bash will have this bug.

-- Felix

#!/bin/bash

g() {
p=$PIPESTATUS
if [[ $p -ne 0 ]]
then
echo FAIL!!
fi
}

f() {
false && false
true | true
g
}

f



Re: Broken PIPESTATUS with --disable-job-control

2016-09-18 Thread Felix Janda
Chet Ramey wrote:
> On 9/17/16 1:27 PM, Felix Janda wrote:
> > Hello,
> > 
> > below this mail you can find a minimal script misbehaving when
> > job-control is configured out (tested on linx with different archs,
> > libc's, and versions (including current git)).
> 
> Yes.  PIPESTATUS doesn't really have any valid values when the shell
> is compiled without job control.  The internal machinery to set it
> doesn't exist.

Ok.

> > 
> > Notice that the configure script disables job-control when a run-time
> > test (which could easily be a built-time test) fails. So by default,
> > a cross-compiled bash will have this bug.
> 
> Which test?

I am referring to BASH_SYS_JOB_CONTROL_MISSING.

Thanks,
Felix



Re: Broken PIPESTATUS with --disable-job-control

2016-09-19 Thread Felix Janda
Chet Ramey wrote:
> On 9/18/16 11:20 PM, Felix Janda wrote:
> 
> >>> Notice that the configure script disables job-control when a run-time
> >>> test (which could easily be a built-time test) fails. So by default,
> >>> a cross-compiled bash will have this bug.
> >>
> >> Which test?
> > 
> > I am referring to BASH_SYS_JOB_CONTROL_MISSING.
> 
> Sure.  I'm asking which part of that run-time test can easily be converted
> to a build-time test that handles conditional compilation and definitions.

Everything could easily be a preprocessor test:


#include 
#ifdef HAVE_SYS_WAIT_H
#include 
#endif
#ifdef HAVE_UNISTD_H
#include 
#endif
#include 

/* signal type */
#if !defined (HAVE_POSIX_SIGNALS) && !defined (HAVE_BSD_SIGNALS)
#error
#endif

/* signals and tty control. */
#if !defined (SIGTSTP) || !defined (SIGSTOP) || !defined (SIGCONT)
#error
#endif

/* process control */
#if !defined (WNOHANG) || !defined (WUNTRACED) 
#error
#endif

/* Posix systems have tcgetpgrp and waitpid. */
#if defined (_POSIX_VERSION) && !defined (HAVE_TCGETPGRP)
#error
#endif

#if defined (_POSIX_VERSION) && !defined (HAVE_WAITPID)
#error
#endif

/* Other systems have TIOCSPGRP/TIOCGPRGP and wait3. */
#if !defined (_POSIX_VERSION) && !defined (HAVE_WAIT3)
#error
#endif


I think that the only reason that it is currently a run-time test is
related to the comment:

/* Add more tests in here as appropriate. */

So it was conceived that in future run-time only tests might be
necessary.


Felix



Re: Broken PIPESTATUS with --disable-job-control

2016-10-15 Thread Felix Janda
Chet Ramey wrote:
> On 9/18/16 11:20 PM, Felix Janda wrote:
> 
> >>> Notice that the configure script disables job-control when a run-time
> >>> test (which could easily be a built-time test) fails. So by default,
> >>> a cross-compiled bash will have this bug.
> >>
> >> Which test?
> > 
> > I am referring to BASH_SYS_JOB_CONTROL_MISSING.
> 
> Sure.  I'm asking which part of that run-time test can easily be converted
> to a build-time test that handles conditional compilation and definitions.

below a patch to make things more concrete:

--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1357,7 +1357,7 @@
 [AC_REQUIRE([BASH_SYS_SIGNAL_VINTAGE])
 AC_MSG_CHECKING(for presence of necessary job control definitions)
 AC_CACHE_VAL(bash_cv_job_control_missing,
-[AC_TRY_RUN([
+[AC_TRY_COMPILE([
 #include 
 #ifdef HAVE_SYS_WAIT_H
 #include 
@@ -1367,42 +1367,35 @@
 #endif
 #include 
 
-/* Add more tests in here as appropriate. */
-main()
-{
 /* signal type */
 #if !defined (HAVE_POSIX_SIGNALS) && !defined (HAVE_BSD_SIGNALS)
-exit(1);
+#error
 #endif
 
 /* signals and tty control. */
 #if !defined (SIGTSTP) || !defined (SIGSTOP) || !defined (SIGCONT)
-exit (1);
+#error
 #endif
 
 /* process control */
 #if !defined (WNOHANG) || !defined (WUNTRACED) 
-exit(1);
+#error
 #endif
 
 /* Posix systems have tcgetpgrp and waitpid. */
 #if defined (_POSIX_VERSION) && !defined (HAVE_TCGETPGRP)
-exit(1);
+#error
 #endif
 
 #if defined (_POSIX_VERSION) && !defined (HAVE_WAITPID)
-exit(1);
+#error
 #endif
 
 /* Other systems have TIOCSPGRP/TIOCGPRGP and wait3. */
 #if !defined (_POSIX_VERSION) && !defined (HAVE_WAIT3)
-exit(1);
+#error
 #endif
-
-exit(0);
-}], bash_cv_job_control_missing=present, bash_cv_job_control_missing=missing,
-[AC_MSG_WARN(cannot check job control if cross-compiling -- defaulting to 
missing)
- bash_cv_job_control_missing=missing]
+], bash_cv_job_control_missing=present, bash_cv_job_control_missing=missing
 )])
 AC_MSG_RESULT($bash_cv_job_control_missing)
 if test $bash_cv_job_control_missing = missing; then