Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 286360 - app-shells/bash-4.0_p28: wait with trap SIGCHLD has different behaviour from bash-3.2
Summary: app-shells/bash-4.0_p28: wait with trap SIGCHLD has different behaviour from ...
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: x86 Linux
: High major (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-25 05:03 UTC by Alex Efros
Modified: 2009-09-30 03:25 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Efros 2009-09-25 05:03:55 UTC
Looks like 'wait' command in bash-4 is broken: if used together with 'trap myhandler SIGCHLD' the 'wait' (without params) exit just after receiving first child exit, instead of waiting for all childs exit.

This command works differently on bash-3.2 and bash-4:
$ time bash -c '
  function spawn { echo SPAWN; sleep 1 & sleep 2 & }
  set -m
  spawn
  trap spawn SIGCHLD
  wait
  '
On app-shells/bash-3.2_p39 (and all previous bash I've used for years) it works as expected:
---cut---
SPAWN 
SPAWN
[1]   Done                    sleep 1
SPAWN
[2]   Done                    sleep 2
SPAWN
[3]   Done                    sleep 1
SPAWN
[4]   Done                    sleep 2
SPAWN
SPAWN
<Ctrl-C>

real    0m3.288s
user    0m0.004s
sys     0m0.005s
---cut---
but on app-shells/bash-4.0_p28 it exit in 1 second without requiring to press Ctrl-C:
---cut---
SPAWN
SPAWN

real    0m1.004s
user    0m0.001s
sys     0m0.001s
---cut---

Reproducible: Always




Portage 2.1.6.13 (hardened/linux/x86/10.0, gcc-3.4.6, glibc-2.9_p20081201-r2, 2.6.28-hardened-r9 i686)
=================================================================
System uname: Linux-2.6.28-hardened-r9-i686-Intel-R-_Core-TM-2_CPU_6600_@_2.40GHz-with-gentoo-1.12.11.1
Timestamp of tree: Wed, 23 Sep 2009 02:30:01 +0000
app-shells/bash:     3.2_p39
dev-java/java-config: 2.1.8-r1
dev-lang/python:     2.6.2-r1
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.6-r2
sys-devel/autoconf:  2.13, 2.63-r1
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.2.6a
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=prescott -O2 -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /service /usr/inferno/keydb /usr/inferno/lib /usr/inferno/services /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config /var/log /var/qmail/alias /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-march=prescott -O2 -pipe"
DISTDIR="/usr/portage-distfiles"
EMERGE_DEFAULT_OPTS="--with-bdeps=y"
FEATURES="distlocks fixpackages parallel-fetch protect-owned sandbox sfperms splitdebug strict unmerge-orphans userfetch userpriv usersandbox"
GENTOO_MIRRORS="http://ftp.lug.ro/gentoo/ http://mirror.qubenet.net/mirror/gentoo/"
LANG="ru_RU.UTF-8"
LDFLAGS="-Wl,-O1"
LINGUAS="en ru"
MAKEOPTS="-j3"
PKGDIR="/usr/portage-packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/layman/powerman /usr/portage/local/layman/sunrise /usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X Xaw3d a52 aac acl acpi aim alsa apache2 arts asf avi bash-completion berkdb bitmap-fonts bzip2 cdr cli cracklib crypt cscope curl dbus dga divx4linux dlloader dri dts dvd dvdr dvdread encode fastcgi ffmpeg flac flash gd gdbm gif gnutls gpgme gtk gtk2 hardened hddtemp iconv icq idn imagemagick imap imlib irc isdnlog jabber javascript jpeg kdeenablefinal lm_sensors lzo mad mailbox mbox mmx mng modules motif mp3 mpeg msn mudflap mysql ncurses nls nptl nptlonly ogg opengl oss pam pcre perl pic png pppd pwdb python qt quicktime rcc readline reflection rss rtc samba sdl session spell spl sse sse2 ssl ssse3 svg sysfs tcltk tcpd tiff truetype truetype-fonts type1-fonts unicode urandom vim-pager vim-syntax vim-with-x vorbis win32codecs x86 xinetd xorg xv xvid yahoo zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 	emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m 	maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="     log_config vhost_alias     autoindex alias rewrite dir deflate filter mime negotiation     auth_basic authn_file authz_host authz_user authz_groupfile     cgi actions headers env setenvif     " ELIBC="glibc" INPUT_DEVICES="keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en ru" LIRC_DEVICES="serial" USERLAND="GNU" VIDEO_CARDS="vesa fbdev nv nvidia"
Unset:  CPPFLAGS, CTARGET, FFLAGS, INSTALL_MASK, LC_ALL, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Alex Efros 2009-09-28 18:11:00 UTC
I've also reported this using bashbug, and got some replies:

---cut---
From: Chet Ramey <chet.ramey@case.edu>

> Bash Version: 4.0
> Patch Level: 28
> Release Status: release
>
> Description:
>         Looks like 'wait' command in bash-4 is broken: if used together
>         with 'trap myhandler SIGCHLD' the 'wait' (without params) exit
>         just after receiving first child exit, instead of waiting for all
>         childs exit.

Posix requires this behavior.

"When the shell is waiting, by means of the wait utility, for asynchronous
commands to complete, the reception of a signal for which a trap has been
set shall cause the wait utility to return immediately with an exit status
>128, immediately after which the trap associated with that signal shall be
taken."

This was reported as a bug against bash-3.2.

Chet
---cut---

---cut---
From: Chet Ramey <chet.ramey@case.edu>

> > This was reported as a bug against bash-3.2.
>
> Cool. Is there any hint/doc/faq/how-to implement old behaviour, i.e. wait
> until all children of current bash process will exit?

I imagine a loop on wait until it returns because there are no unwaited-for
children.  You can detect the "interrupted" exit status and behave
accordingly.

I'll probably make this posix-mode-specific behavior or add an option for
it in the next version.

> P.S. I've not seen this information in 'help wait' or 'man bash' - is this
> current 'correct' behaviour is documented?

No.  I'm not able to put everything from the Posix spec into a man page.

Chet
---cut---
Comment 2 SpanKY gentoo-dev 2009-09-30 03:25:09 UTC
you can read the POSIX specs:
http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html