handler is working properly:
# ./test.sh
-Setup...
-Spawning a session daemon
-Session auto-20130626-224838 created.
-Kernel channel chan enabled for session auto-20130626-224838
-kernel event sched_switch created in channel chan
-Tracing started for session auto-20130626-224838
+Setup coredump-handler...
+Session coredump-handler created.
+Default snapshot output set to: /tmp/lttng/snapshot
+Snapshot mode set. Every channel enabled for that session will be set in overwrite mode and mmap output
+kernel event sched_switch created in channel channel0
+Tracing started for session coredump-handler
Sleeping...
Crashing...
-./test.sh: line 35: 16980 Segmentation fault (core dumped)
-$(dirname $0)/crash
+Segmentation fault (core dumped)
+Sleeping...
Waiting for data availability
-Tracing stopped for session auto-20130626-224838
-Session auto-20130626-224838 destroyed
-Core dump and snapshot will be available in /tmp/lttng/{core,snapshot}.
+Tracing stopped for session coredump-handler
+Session coredump-handler destroyed
+Core dump will be available in /tmp/lttng/core.
+Snapshot will be available in /tmp/lttng/snapshot.
# tree /tmp/lttng
/tmp/lttng
-|-- core
-| `-- core.16980
-`-- snapshot
- `-- snapshot
- |-- chan_0
- |-- chan_1
- |-- chan_2
- |-- chan_3
- |-- chan_4
- |-- chan_5
- |-- chan_6
- |-- chan_7
- `-- metadata
+├── core
+│ └── core.29085
+└── snapshot
+ └── snapshot-1-20130719-175041-0
+ └── kernel
+ ├── channel0_0
+ ├── channel0_1
+ ├── channel0_2
+ ├── channel0_3
+ └── metadata
Chaining with other core dump handler:
[...]
# Save core dump from stdin.
-$MKDIR_BIN -p "${CORE_PATH}"
+#$MKDIR_BIN -p "${CORE_PATH}"
+#$CAT_BIN - > "${CORE_PATH}/${CORE_PREFIX}.$p"
# Optional, chain core dump handler with original systemd script.
$CAT_BIN - | /usr/lib/systemd/systemd-coredump $p $u $g $s $t $e
MKDIR_BIN="mkdir"
LTTNG_BIN="lttng"
-# Core file settings.
-CORE_PATH="/tmp/lttng/core"
-CORE_PREFIX="core"
-
-# Folder where to save snapshot output.
-# Can also be a remote URI.
-SNAPSHOT_PATH="/tmp/lttng/snapshot"
-SNAPSHOT_OUTPUT="file://${SNAPSHOT_PATH}"
+# Session name
+SESSION_NAME="coredump-handler"
# Sessiond binary name.
SESSIOND_BIN_NAME="lttng-sessiond"
+# Core file settings.
+CORE_PATH="/tmp/lttng/core"
+CORE_PREFIX="core"
+
# Core specifiers, see man core(5)
p=$1 # PID of dumped process
# TODO: Checking for a sessiond lockfile would be more appropriate.
if $PGREP_BIN -u root "${SESSIOND_BIN_NAME}" > /dev/null 2>&1
then
- # Since we are called via the kernel coredump mechanism, we need to
- # setup our environment manually.
- #
- # The lttng command line tool lookup $HOME to adjust the .lttngrc
- # path. This is useful to have automatic session name lookup.
- export HOME="/root"
- $MKDIR_BIN -p "${SNAPSHOT_PATH}"
- $LTTNG_BIN snapshot add-output "${SNAPSHOT_OUTPUT}" > /dev/null 2>&1
- $LTTNG_BIN snapshot record > /dev/null 2>&1
+ $LTTNG_BIN snapshot record -s ${SESSION_NAME} > /dev/null 2>&1
fi
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
-CORE_PATTERN="/proc/sys/kernel/core_pattern"
+CORE_PATTERN_PATH="/proc/sys/kernel/core_pattern"
CORE_HANDLER_PATH="$(dirname $(readlink -e $0))/handler.sh"
+CORE_PATTERN="$(cat ${CORE_PATTERN_PATH})"
-cat ${CORE_PATTERN} > core_pattern.bkp
+echo ${CORE_PATTERN} > core_pattern.bkp
echo "Backup current core_pattern in core_pattern.bkp."
-echo "|$CORE_HANDLER_PATH %p %u %g %s %t %h %e %E %c" > ${CORE_PATTERN}
+echo "|$CORE_HANDLER_PATH %p %u %g %s %t %h %e %E %c" > ${CORE_PATTERN_PATH}
if [ $? -eq 0 ]
then
- echo "Successfully installed core_pattern."
+ echo "Successfully installed core_pattern."
else
- echo "Installation of core_pattern failed."
+ echo "Installation of core_pattern failed."
+ exit 1
fi
LTTNG_BIN="lttng"
-CHANNEL_NAME="chan"
+SESSION_NAME="coredump-handler"
+
+# Just recording kernel event sched_switch as an example, but we can as
+# well record user-space events from UST domain.
EVENT_NAME="sched_switch"
-echo "Setup..."
-$LTTNG_BIN create --no-output
-$LTTNG_BIN enable-channel "${CHANNEL_NAME}" -k --overwrite --output mmap
-$LTTNG_BIN enable-event "${EVENT_NAME}" -c "${CHANNEL_NAME}" -k
-$LTTNG_BIN start
+SNAPSHOT_PATH="/tmp/lttng/snapshot"
+SNAPSHOT_URI="file://${SNAPSHOT_PATH}"
+
+echo "Setup ${SESSION_NAME}..."
+$LTTNG_BIN create ${SESSION_NAME} --snapshot -U ${SNAPSHOT_PATH}
+$LTTNG_BIN enable-event ${EVENT_NAME} -k -s ${SESSION_NAME}
+$LTTNG_BIN start ${SESSION_NAME}
echo "Sleeping..."
sleep 10
echo "Sleeping..."
sleep 10
-$LTTNG_BIN stop
-$LTTNG_BIN destroy
+$LTTNG_BIN stop ${SESSION_NAME}
+$LTTNG_BIN destroy ${SESSION_NAME}
-echo "Core dump and snapshot will be available in /tmp/lttng/{core,snapshot}."
+echo "Core dump will be available in /tmp/lttng/core."
+echo "Snapshot will be available in ${SNAPSHOT_PATH}."