Comment 15 for bug 1027203

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

This is not a problem with strace itself, but with the default shell used by Ubuntu.

While when running by hand it worked fine, it probably just worked because it was using bash, which is not the default at ubuntu (dash is, check /bin/sh).

The results:
linaro@linaro-nano:~$ cat foo.sh
#!/bin/sh

check_kernel_oops()
{
 KERNEL_ERR=`dmesg | grep "Unable to handle kernel "`
 if ! ([[ -z "$KERNEL_ERR" ]]); then
  echo "Kernel OOPS. Abort!!"
  exit 1
 fi
}

check_kernel_oops
echo " with strace on ubuntu you never reach me"
linaro@linaro-nano:~$ sh foo.sh
foo.sh: 6: foo.sh: [[: not found
Kernel OOPS. Abort!!
linaro@linaro-nano:~$ bash foo.sh
 with strace on ubuntu you never reach me

Now with a modified script, which is also compatible with minimal shells like dash:
linaro@linaro-nano:~$ cat foo.sh
#!/bin/sh

check_kernel_oops()
{
 KERNEL_ERR=`dmesg | grep "Unable to handle kernel "`
 if [ -n "$KERNEL_ERR" ]; then
  echo "Kernel OOPS. Abort!!"
  exit 1
 fi
}

check_kernel_oops
echo " with strace on ubuntu you never reach me"
linaro@linaro-nano:~$ sh foo.sh
 with strace on ubuntu you never reach me
linaro@linaro-nano:~$ bash foo.sh
 with strace on ubuntu you never reach me
linaro@linaro-nano:~$ strace -o output-kernel-oops.log -f /bin/sh foo.sh
 with strace on ubuntu you never reach me