Race condition determining value of $? variable
Configuration Information [Automatically generated, do not change]: Machine: i386 OS: linux-gnu Compiler: i386-redhat-linux-gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -O2 -march=i386 -mcpu=i686 -g uname output: Linux server-testvpn 2.4.24 #33 SMP юФЧ жЕЧ 22 10:05:53 MSK 2007 i686 i686 i386 GNU/Linux Machine Type: i386-redhat-linux-gnu Bash Version: 2.05b Patch Level: 0 Release Status: release Description: Race condition, appeared when background job completed in moment between ending of foregroung program and calculating value of $? variable Repeat-By: set -m exec 4>/dev/null while true; do usleep $((RANDOM*30)) >&4 2>&1 & output=$( /bin/false ) #when sigchild appear here, become race condition ;-) # and return value of usleep is placed to $? # what was also tested: # 1. manually written usleep which always return code 22 after sleeping #tmp=$?; [ "$tmp" = 0 ] || continue ; echo $tmp => show 22 in the output # 2. output=$( exec /bin/false ) - triggers race condition # 3. output=`/bin/false` - trigger rage condition # 4. /bin/false - NOT TRIGGERS # 5. ( /bin/false ) - NOT TRIGGERS [ "$?" = 0 ] || continue echo "YEP! race condition catched!" break; done ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Bash getopts option
I am trying to parse command line options using getopts. for parsing options that are words , for e.g -help, Bash is not allowing me to do that. while getopts c:d:fh:help options do case $options in help) echo" Help" ;; done The above code does not parse -help option. Any suggestions -- View this message in context: http://www.nabble.com/Bash-getopts-option-tf3294413.html#a9163816 Sent from the Gnu - Bash mailing list archive at Nabble.com. ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: Bash getopts option
Shanks wrote: I am trying to parse command line options using getopts. for parsing options that are words , for e.g -help, Bash is not allowing me to do that. while getopts c:d:fh:help options do case $options in help) echo" Help" ;; done The above code does not parse -help option. Any suggestions I don't think getopts knows how to parse words as options (and not as non-GNU-style, certainly). You are probably better off writing your own parser, something like this: while [ $1 ] ; do [ ${1:0:1} = '-' ] || break case ${1:1} in help) echo help;; c*) if [ ${1:1} ] ; then arg=${1:1} else shift; arg=$1 fi echo "arg of -c is $arg" ;; *) echo "bad option, $1";; esac shift done -- Matthew Obscurity: +5 ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: GNU bash, 3.00.15(1)-release, referenced cmd in cwd executes alternate cmd
Bob Proulx wrote: Matthew Woehlke wrote: Бојан Ландекић wrote: Is it possible to put bash on some portable media and use it on a system that is bash-less without worrying about dependencies? Not unless you build it statically, it isn't. :-) Although I think if you build bash it gives you all the libraries you need except for libc (or your OS's equivalent). IOW if you have an entire bash install on your 'portable media', you should be able to run that bash on any system the same as, or newer than, your build system. Actually as long as you include all of the libraries in the same bundle and call ldso with the path to the bundled libc then it is perfectly possible to build a complete set that will work on most distros, on the same architecture and across compatible kernel versions of course. On my system that would be libncurses.so.5, libdl.so.2, libc.so.6, ld-linux-x86-64.so.2 plus bash itself and a portable sh script wrapper to tie it all together. I do that with other tools frequently. Oddly enough, I can get this to work on OSF, but not Linux. I don't want to use a bundled libc unless the system libc is sufficient, so what I did was drop a "sufficient" libc somewhere I can LD_LIBRARY_PATH it before trying to run bash. Like I said, this works on OSF, but on Linux I get: $ ldd /path/to/bash /path/to/bash: /lib/i686/libc.so.6: version `GLIBC_2.3' not found (required by /path/to/bash) libtermcap.so.2 => /lib/libtermcap.so.2 (0x40021000) libdl.so.2 => /lib/libdl.so.2 (0x40025000) libc.so.6 => /lib/i686/libc.so.6 (0x40029000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x4000) ...At some point I was also getting: $ ldd /path/to/bash /bin/sh: /lib/ld-linux.so.2: version `GLIBC_PRIVATE' not found (required by /path/to/my/private/libc.so.6 ...but I can't seem to reproduce this any more (I think it happened if I dropped in libdl also). Apparently selectively shadowing libc is non-trivial... any suggestions/hints? -- Matthew Obscurity: +5 ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash