[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Writing to /dev/stderr overwrites xtrace data
From: |
jono . chadwell |
Subject: |
Writing to /dev/stderr overwrites xtrace data |
Date: |
Wed, 30 Oct 2019 18:10:23 -0700 (PDT) |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H -I. -I../. -I.././include -I.././lib -Wdate-time
-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux birch 4.15.0-65-generic #74~16.04.1-Ubuntu SMP Wed Sep 18
09:51:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.3
Patch Level: 48
Release Status: release
Description:
I enabled xtrace to try and debug a bash script running on a validation
server. The script stored its stdout and stderr to a log file. I expected
to see trace data in the log file, but instead found a single log statement,
a bunch of NULL bytes, and the line '+ exit 1'.
After some playing around with it I found that writing to the file
/dev/stderr was responsible for deleting the xtrace data.
Repeat-By:
```
echo "#!/usr/bin/env bash" > script.sh
echo "set -o xtrace" >> script.sh
echo "echo to_stderr > /dev/stderr" >> script.sh
chmod 755 script.sh
./script.sh 2> stderr_output
```
After running these commands I expect to see find xtrace output in
stderr_output. Instead I only see 'to_stderr\n'.
If this behavior is unavoidable due to how linux file IO, then I recommend at
least adding the documentation as a known gotcha.
Thanks,
Jono Chadwell
- Writing to /dev/stderr overwrites xtrace data,
jono . chadwell <=