LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Core dump to a pipe is failing (https://www.linuxquestions.org/questions/programming-9/core-dump-to-a-pipe-is-failing-4175445816/)

bsnote 01-16-2013 03:04 AM

Core dump to a pipe is failing
 
Tried this on MIPS platform:

> uname -a
Linux (none) 2.6.29 #2 Mon Jan 14 13:26:04 PST 2013 mips GNU/Linux
> ulimit -c unlimited
> which gzip
/bin/gzip
> echo "|/bin/gzip - > /home/core-%t-%s-%e.gz" > /proc/sys/kernel/core_pattern
> ./fault
hello there
Segmentation fault (core dumped)
> ls /home/core*.gz
ls: /home/core*: No such file or directory

i.e. piping to a program doesn't work. if I specify a file:

> echo "/home/core-%t-%s-%e" > /proc/sys/kernel/core_pattern

then it works. What did I miss?

NevemTeve 01-16-2013 10:21 AM

Is there any documentation stating that it should it work?

bsnote 01-17-2013 04:24 AM

Quote:

Originally Posted by NevemTeve (Post 4871425)
Is there any documentation stating that it should it work?

http://www.kernel.org/doc/man-pages/...n5/core.5.html

Piping core dumps to a program

Since kernel 2.6.19, Linux supports an alternate syntax for the
/proc/sys/kernel/core_pattern file. If the first character of this file is a
pipe symbol (|), then the remainder of the line is interpreted as a program to
be executed. Instead of being written to a disk file, the core dump is given
as standard input to the program.

millgates 01-17-2013 06:24 AM

It also states
Quote:

Command-line arguments can be supplied to the program (since kernel
2.6.24), delimited by white space (up to a total line length of 128 bytes).
It does not, however, say anything about redirection. ">file" is not an argument to gzip.

You can use tar, which takes output filename as an argument:

Code:

$ cat /proc/sys/kernel/core_pattern
|/usr/bin/tar - -zcvf /path/to/whatever.tar.gz

or you can put it in a shell script:
Code:

$ cat /proc/sys/kernel/core_pattern
|/path/to/shellscript.sh /path/to/whatever.tar.gz
$
$ cat /path/to/shellscript.sh
#!/bin/bash
gzip > "$1"


bsnote 01-17-2013 07:09 AM

Quote:

Originally Posted by millgates (Post 4872089)
It also states


It does not, however, say anything about redirection. ">file" is not an argument to gzip.

You can use tar, which takes output filename as an argument:

Code:

$ cat /proc/sys/kernel/core_pattern
|/usr/bin/tar - -zcvf /path/to/whatever.tar.gz

or you can put it in a shell script:
Code:

$ cat /proc/sys/kernel/core_pattern
|/path/to/shellscript.sh /path/to/whatever.tar.gz
$
$ cat /path/to/shellscript.sh
#!/bin/bash
gzip > "$1"


Thank you millgates! It's not possible to pipe content to tar, but putting it in a shell did the trick!

bhat_a 01-27-2017 03:02 AM

I am exactly encountering the same problem now. Only change is I have a shell script (start.sh) which starts my application. To, pipe core file, I opened an another shell script (shellscript.sh) from start.sh which contains gzip commands.

Start.sh : (required lines for core file generation)
############################################################################
#!/bin/sh

cat >/tmp/shellscript.sh <<EOF1
#!/bin/sh
/bin/gzip > \$1
EOF1

chmod +x /tmp/shellscript.sh

ulimit -c unlimited
echo "|/tmp/shellscript.sh /tmp/core.tar.gz" > /proc/sys/kernel/core_pattern

############################################################################

If I do above script, then there is no core generated.

But the same script without piping works (i.e core file is generated).
I am looking to zip my core file while it is generating. Anybody here have some inputs ?

NevemTeve 01-27-2017 03:57 AM

Please use [code] and [/code] tags when quoting source code.

Command 'ulimit -c' should be executed before starting the program-to-fail, not in this script.

Cosmetic change: use "quotes"
Code:

cat >/tmp/shellscript.sh <<"EOF1"
#!/bin/sh
exec /bin/gzip >"$1"
EOF1


bhat_a 01-27-2017 04:51 AM

Hello NavemTeve,

I did use the command 'ulimit -c' before executing the program. This script starts our application "bb_d" Please check the complete code below

Code:

#!/bin/sh
# is release or debug
APP="bb_d"
if ! test -f /tmp/$APP; then
        APP="bb"
fi

# kill running application
killall $APP

# enhance library path variable
LD_LIBRARY_PATH="/opt/folder"; export LD_LIBRARY_PATH

# move packages to target directory
chmod 744 /tmp/*
mv /tmp/*.so /opt/folder/
mv /tmp/$APP/opt/folder/

cat >/tmp/shellscript.sh <<"EOF1"
#!/bin/sh
/bin/gzip > "\$1"
EOF1

chmod +x /tmp/shellscript.sh

ulimit -c unlimited
echo "|/tmp/shellscript.sh /tmp/core.tar.gz" > /proc/sys/kernel/core_pattern

# start the APP as background job
cd /opt/folder/
./$APP"" 2 &

Even with the "quotes" the above script is doesn't dump core file.

NOTE : Without 'piping to a program (in this case shellscript.sh)', I am able to get the core file.

NevemTeve 01-27-2017 05:25 AM

Ok, here is a complete working example, of course you have to run it as root,
and you have the change the name of the program
Code:

#!/bin/sh

set -e

cat >/tmp/shellscript.sh <<"EOF1"
#!/bin/sh
exec /bin/gzip >"$1"
EOF1

chmod +x /tmp/shellscript.sh
echo '|/tmp/shellscript.sh /tmp/core.%p.gz' >/proc/sys/kernel/core_pattern

ulimit -c unlimited

exec ./sajatdumptest

running:
Code:

$ su -c ./test_script.sh
...
$ ls -ltr /tmp/
-rwxr-xr-x 1 root    root      31 Jan 27 12:20 shellscript.sh
-rw-rw-rw- 1 root    root  21794 Jan 27 12:20 core.4888.gz


bhat_a 01-27-2017 10:52 AM

It works on normal ubuntu system. But it doesn't work on embedded linux - "busybox".

linux version running :
Linux (none) 4.4.0 #1 SMP Mon Jul 11 11:05:12 CEST 2016 x86_64 GNU/Linux

I meant, piping to a program (like gzip) on busybox is not working. Without piping, it is fine.

Any inputs on the same?


All times are GMT -5. The time now is 01:55 PM.