|
Packit |
8ea169 |
#!/bin/bash
|
|
Packit |
8ea169 |
# Install coredump handler which saves segfault data
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
# For debugging
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
dry_run=false
|
|
Packit |
8ea169 |
verbose=false
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
PATTERN_FILE="/proc/sys/kernel/core_pattern"
|
|
Packit |
8ea169 |
SAVED_PATTERN_DIR="@VAR_RUN@/abrt"
|
|
Packit |
8ea169 |
SAVED_PATTERN_FILE="@VAR_RUN@/abrt/saved_core_pattern"
|
|
Packit |
8ea169 |
HOOK_BIN="@libexecdir@/abrt-hook-ccpp"
|
|
Packit |
8ea169 |
# Must match percent_specifiers[] order in abrt-hook-ccpp.c:
|
|
Packit |
8ea169 |
PATTERN="|$HOOK_BIN %s %c %p %u %g %t %P %I %h %e"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
# core_pipe_limit specifies how many dump_helpers can run at the same time
|
|
Packit |
8ea169 |
# 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing
|
|
Packit |
8ea169 |
# process will be available for dump_helper.
|
|
Packit |
8ea169 |
# 4 - means that 4 dump_helpers can run at the same time (the rest will also
|
|
Packit |
8ea169 |
# run, but they will fail to read /proc/<pid>).
|
|
Packit |
8ea169 |
#
|
|
Packit |
8ea169 |
# This should be enough for ABRT, we can miss some crashes, but what are
|
|
Packit |
8ea169 |
# the odds that more processes crash at the same time? And moreover,
|
|
Packit |
8ea169 |
# do people want to save EVERY ONE of the crashes when they have
|
|
Packit |
8ea169 |
# a crash storm? I don't think so.
|
|
Packit |
8ea169 |
# The value of 4 has been recommended by nhorman.
|
|
Packit |
8ea169 |
#
|
|
Packit |
8ea169 |
CORE_PIPE_LIMIT_FILE="/proc/sys/kernel/core_pipe_limit"
|
|
Packit |
8ea169 |
CORE_PIPE_LIMIT="4"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
start() {
|
|
Packit |
8ea169 |
if ! $HOOK_BIN --test-config; then
|
|
Packit |
8ea169 |
echo "Invalid configuration."
|
|
Packit |
8ea169 |
exit 1
|
|
Packit |
8ea169 |
fi
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
cur=`cat "$PATTERN_FILE"`
|
|
Packit |
8ea169 |
cur_first=`printf "%s" "$cur" | sed 's/ .*//'`
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
$verbose && printf "cur:'%s'\n" "$cur"
|
|
Packit |
8ea169 |
# Is it already installed?
|
|
Packit |
8ea169 |
if test x"$cur_first" != x"|$HOOK_BIN"; then # no
|
|
Packit |
8ea169 |
# It is not installed
|
|
Packit |
8ea169 |
mkdir -p -- "$SAVED_PATTERN_DIR"
|
|
Packit |
8ea169 |
printf "%s\n" "$cur" >"$SAVED_PATTERN_FILE"
|
|
Packit |
8ea169 |
# Install new handler
|
|
Packit |
8ea169 |
$verbose && printf "Installing to %s:'%s'\n" "$PATTERN_FILE" "$PATTERN"
|
|
Packit |
8ea169 |
$dry_run || echo "$PATTERN" >"$PATTERN_FILE"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
# Check core_pipe_limit and change it if it's 0,
|
|
Packit |
8ea169 |
# otherwise the abrt-hook-ccpp won't be able to read /proc/<pid>
|
|
Packit |
8ea169 |
# of the crashing process
|
|
Packit |
8ea169 |
if test x"`cat "$CORE_PIPE_LIMIT_FILE"`" = x"0"; then
|
|
Packit |
8ea169 |
echo "$CORE_PIPE_LIMIT" >"$CORE_PIPE_LIMIT_FILE"
|
|
Packit |
8ea169 |
fi
|
|
Packit |
8ea169 |
fi
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
stop() {
|
|
Packit |
8ea169 |
if test -f "$SAVED_PATTERN_FILE"; then
|
|
Packit |
8ea169 |
$verbose && printf "Restoring to %s:'%s'\n" "$PATTERN_FILE" "`cat "$SAVED_PATTERN_FILE"`"
|
|
Packit |
8ea169 |
$dry_run || cat "$SAVED_PATTERN_FILE" >"$PATTERN_FILE"
|
|
Packit |
8ea169 |
fi
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
status() {
|
|
Packit |
8ea169 |
cur=`cat "$PATTERN_FILE"`
|
|
Packit |
8ea169 |
cur_first=`printf "%s" "$cur" | sed 's/ .*//'`
|
|
Packit |
8ea169 |
# Is it already installed?
|
|
Packit |
8ea169 |
if test x"$cur_first" = x"|$HOOK_BIN"; then # yes
|
|
Packit |
8ea169 |
$verbose && printf "Installed\n"
|
|
Packit |
8ea169 |
return 0
|
|
Packit |
8ea169 |
else
|
|
Packit |
8ea169 |
$verbose && printf "Not installed\n"
|
|
Packit |
8ea169 |
return 1
|
|
Packit |
8ea169 |
fi
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
case "$1" in
|
|
Packit |
8ea169 |
install)
|
|
Packit |
8ea169 |
start
|
|
Packit |
8ea169 |
;;
|
|
Packit |
8ea169 |
uninstall)
|
|
Packit |
8ea169 |
stop
|
|
Packit |
8ea169 |
;;
|
|
Packit |
8ea169 |
is-installed)
|
|
Packit |
8ea169 |
status
|
|
Packit |
8ea169 |
;;
|
|
Packit |
8ea169 |
*)
|
|
Packit |
8ea169 |
echo $"Usage: $0 {install|uninstall|is-installed}"
|
|
Packit |
8ea169 |
exit 2
|
|
Packit |
8ea169 |
esac
|