| #!/bin/sh |
| pid=$1 |
| signal=$2 |
| exe=$3 |
| |
| # TODO(kedong) need to specify different size based on platform. |
| out=/user/core.gz |
| outdir=$(dirname "$out") |
| |
| # Send all output to kernel log. We don't want to use the 'logger' program |
| # here in case there's something wrong with syslogd (eg. it's the one core |
| # dumping). |
| exec >/dev/kmsg 2>&1 |
| |
| log() |
| { |
| echo "coredump:" $@ >&2; |
| } |
| |
| log "pid $pid ($exe) dying on signal $2" |
| |
| if [ ! -e "/tmp/DEBUG" ]; then |
| log "skipping coredump for process '$exe'" |
| elif [ ! -w "$outdir" ] || [ -e "$out" -a ! -w "$out" ]; then |
| log "can't dump core: $out is not writable." |
| elif pgrep -x coredump-delay >/dev/null; then |
| log "coredump-delay not yet reached; not saving." |
| else |
| # read and compress the core dump from stdin, limiting max output size |
| coredump-delay & |
| log "dumping core in '$out'" |
| gzip -c | dd bs=1024 count=163840 2>/dev/null >"$out" |
| upload-logs-now |
| log "finished dumping core for pid $pid ($exe)" |
| fi |