Commit | Line | Data |
---|---|---|
57f0bd0c CB |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (C) 2013 - Christian Babeux <christian.babeux@efficios.com> | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU General Public License | |
7 | # as published by the Free Software Foundation; only version 2 | |
8 | # of the License. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | # | |
19 | ||
20 | # System binaries paths. | |
21 | CAT_BIN="cat" | |
22 | PGREP_BIN="pgrep" | |
23 | MKDIR_BIN="mkdir" | |
24 | LTTNG_BIN="lttng" | |
25 | ||
26 | # Core file settings. | |
27 | CORE_PATH="/tmp/lttng/core" | |
28 | CORE_PREFIX="core" | |
29 | ||
30 | # Folder where to save snapshot output. | |
31 | # Can also be a remote URI. | |
32 | SNAPSHOT_PATH="/tmp/lttng/snapshot" | |
33 | SNAPSHOT_OUTPUT="file://${SNAPSHOT_PATH}" | |
34 | ||
35 | # Sessiond binary name. | |
36 | SESSIOND_BIN_NAME="lttng-sessiond" | |
37 | ||
38 | # Core specifiers, see man core(5) | |
39 | ||
40 | p=$1 # PID of dumped process | |
41 | u=$2 # (numeric) real UID of dumped process | |
42 | g=$3 # (numeric) real GID of dumped process | |
43 | s=$4 # number of signal causing dump | |
44 | t=$5 # time of dump, expressed as seconds since the Epoch, | |
45 | # 1970-01-01 00:00:00 +0000 (UTC) | |
46 | h=$6 # hostname (same as nodename returned by uname(2)) | |
47 | e=$7 # executable filename (without path prefix) | |
48 | E=$8 # pathname of executable, with slashes ('/') replaced | |
49 | # by exclamation marks ('!'). | |
50 | c=$9 # core file size soft resource limit of crashing process | |
51 | # (since Linux 2.6.24) | |
52 | ||
53 | # Save core dump from stdin. | |
54 | $MKDIR_BIN -p "${CORE_PATH}" | |
55 | $CAT_BIN - > "${CORE_PATH}/${CORE_PREFIX}.$p" | |
56 | ||
57 | # Optional, chain core dump handler with original systemd script. | |
58 | #$CAT_BIN - | /usr/lib/systemd/systemd-coredump $p $u $g $s $t $e | |
59 | ||
60 | # TODO: Checking for a sessiond lockfile would be more appropriate. | |
61 | if $PGREP_BIN -u root "${SESSIOND_BIN_NAME}" > /dev/null 2>&1 | |
62 | then | |
63 | # Since we are called via the kernel coredump mechanism, we need to | |
64 | # setup our environment manually. | |
65 | # | |
66 | # The lttng command line tool lookup $HOME to adjust the .lttngrc | |
67 | # path. This is useful to have automatic session name lookup. | |
68 | export HOME="/root" | |
69 | $MKDIR_BIN -p "${SNAPSHOT_PATH}" | |
70 | $LTTNG_BIN snapshot add-output "${SNAPSHOT_OUTPUT}" > /dev/null 2>&1 | |
71 | $LTTNG_BIN snapshot record > /dev/null 2>&1 | |
72 | fi |