1 |
dmorgan |
109812 |
#!/bin/bash |
2 |
|
|
# Install abrt coredump hook |
3 |
|
|
# |
4 |
|
|
# chkconfig: 35 82 16 |
5 |
|
|
# description: Installs coredump handler which saves segfault data |
6 |
|
|
### BEGIN INIT INFO |
7 |
|
|
# Provides: abrt-ccpp |
8 |
|
|
# Required-Start: $abrtd |
9 |
|
|
# Default-Stop: 0 1 2 6 |
10 |
|
|
# Default-Start: 3 5 |
11 |
|
|
# Short-Description: Installs coredump handler which saves segfault data |
12 |
|
|
# Description: Installs coredump handler which saves segfault data |
13 |
|
|
### END INIT INFO |
14 |
|
|
|
15 |
|
|
# Source function library. |
16 |
|
|
. /etc/rc.d/init.d/functions |
17 |
|
|
|
18 |
|
|
# For debugging |
19 |
|
|
dry_run=false |
20 |
|
|
verbose=false |
21 |
|
|
|
22 |
|
|
# We don't have pid files, therefore have to use |
23 |
|
|
# a flag file in /var/lock/subsys to enable GUI service tools |
24 |
|
|
# to figure out our status |
25 |
|
|
LOCK="/var/lock/subsys/abrt-ccpp" |
26 |
|
|
|
27 |
|
|
PATTERN_FILE="/proc/sys/kernel/core_pattern" |
28 |
|
|
SAVED_PATTERN_FILE="/var/run/abrt/saved_core_pattern" |
29 |
|
|
HOOK_BIN="/usr/libexec/abrt-hook-ccpp" |
30 |
|
|
PATTERN="|$HOOK_BIN /var/spool/abrt %s %c %p %u %g %t %h %e" |
31 |
|
|
|
32 |
|
|
# core_pipe_limit specifies how many dump_helpers can run at the same time |
33 |
|
|
# 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing |
34 |
|
|
# process will be available for dump_helper. |
35 |
|
|
# 4 - means that 4 dump_helpers can run at the same time (the rest will also |
36 |
|
|
# run, but they will fail to read /proc/<pid>). |
37 |
|
|
# |
38 |
|
|
# This should be enough for ABRT, we can miss some crashes, but what are |
39 |
|
|
# the odds that more processes crash at the same time? And moreover, |
40 |
|
|
# do people want to save EVERY ONE of the crashes when they have |
41 |
|
|
# a crash storm? I don't think so. |
42 |
|
|
# The value of 4 has been recommended by nhorman. |
43 |
|
|
# |
44 |
|
|
CORE_PIPE_LIMIT_FILE="/proc/sys/kernel/core_pipe_limit" |
45 |
|
|
CORE_PIPE_LIMIT="4" |
46 |
|
|
|
47 |
|
|
RETVAL=0 |
48 |
|
|
|
49 |
|
|
check() { |
50 |
|
|
# Check that we're a privileged user |
51 |
|
|
[ "`id -u`" = 0 ] || exit 4 |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
start() { |
55 |
|
|
check |
56 |
|
|
|
57 |
|
|
cur=`cat "$PATTERN_FILE"` |
58 |
|
|
cur_first=`printf "%s" "$cur" | sed 's/ .*//'` |
59 |
|
|
|
60 |
|
|
$verbose && printf "cur:'%s'\n" "$cur" |
61 |
|
|
# Is it already installed? |
62 |
|
|
if test x"$cur_first" != x"|$HOOK_BIN"; then # no |
63 |
|
|
# It is not installed |
64 |
|
|
printf "%s\n" "$cur" >"$SAVED_PATTERN_FILE" |
65 |
|
|
OLD_PATTERN="" |
66 |
|
|
# Does old pattern start with '|'? |
67 |
|
|
if test x"${cur#|}" = x"$cur"; then # no |
68 |
|
|
# Encode it as hex string, NUL terminated |
69 |
|
|
OLD_PATTERN=`printf "%s" "$cur" | od -tx1 | sed 's/000[^ ]*//' | xargs | sed 's/ //g'` |
70 |
|
|
$verbose && printf "OLD_PATTERN:'%s'\n" "$OLD_PATTERN" |
71 |
|
|
OLD_PATTERN=" ${OLD_PATTERN}00" |
72 |
|
|
fi |
73 |
|
|
# Install new handler |
74 |
|
|
$verbose && printf "Installing to %s:'%s'\n" "$PATTERN_FILE" "${PATTERN}${OLD_PATTERN}" |
75 |
|
|
$dry_run || echo "${PATTERN}${OLD_PATTERN}" >"$PATTERN_FILE" |
76 |
|
|
$dry_run || touch -- "$LOCK" |
77 |
|
|
|
78 |
|
|
# Check core_pipe_limit and change it if it's 0, |
79 |
|
|
# otherwise the abrt-hook-ccpp won't be able to read /proc/<pid> |
80 |
|
|
# of the crashing process |
81 |
|
|
if test x"`cat "$CORE_PIPE_LIMIT_FILE"`" = x"0"; then |
82 |
|
|
echo "$CORE_PIPE_LIMIT" >"$CORE_PIPE_LIMIT_FILE" |
83 |
|
|
fi |
84 |
|
|
fi |
85 |
|
|
return $RETVAL |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
stop() { |
89 |
|
|
check |
90 |
|
|
|
91 |
|
|
if test -f "$SAVED_PATTERN_FILE"; then |
92 |
|
|
$verbose && printf "Restoring to %s:'%s'\n" "$PATTERN_FILE" "`cat "$SAVED_PATTERN_FILE"`" |
93 |
|
|
$dry_run || cat "$SAVED_PATTERN_FILE" >"$PATTERN_FILE" |
94 |
|
|
fi |
95 |
|
|
$dry_run || rm -f -- "$LOCK" |
96 |
|
|
return $RETVAL |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
restart() { |
100 |
|
|
stop |
101 |
|
|
start |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
reload() { |
105 |
|
|
restart |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
case "$1" in |
109 |
|
|
start) |
110 |
|
|
start |
111 |
|
|
;; |
112 |
|
|
stop) |
113 |
|
|
stop |
114 |
|
|
;; |
115 |
|
|
reload) |
116 |
|
|
reload |
117 |
|
|
;; |
118 |
|
|
force-reload) |
119 |
|
|
echo "$0: Unimplemented feature." |
120 |
|
|
RETVAL=3 |
121 |
|
|
;; |
122 |
|
|
restart) |
123 |
|
|
restart |
124 |
|
|
;; |
125 |
|
|
condrestart) |
126 |
|
|
cur=`cat "$PATTERN_FILE"` |
127 |
|
|
cur_first=`printf "%s" "$cur" | sed 's/ .*//'` |
128 |
|
|
# Is it already installed? |
129 |
|
|
if test x"$cur_first" = x"|$HOOK_BIN"; then # yes |
130 |
|
|
$verbose && printf "Installed, re-installing\n" |
131 |
|
|
restart |
132 |
|
|
fi |
133 |
|
|
;; |
134 |
|
|
status) |
135 |
|
|
cur=`cat "$PATTERN_FILE"` |
136 |
|
|
cur_first=`printf "%s" "$cur" | sed 's/ .*//'` |
137 |
|
|
# Is it already installed? |
138 |
|
|
if test x"$cur_first" = x"|$HOOK_BIN"; then # yes |
139 |
|
|
$verbose && printf "Installed\n" |
140 |
|
|
RETVAL=0 |
141 |
|
|
else |
142 |
|
|
$verbose && printf "Not installed\n" |
143 |
|
|
RETVAL=3 # "stopped normally" |
144 |
|
|
fi |
145 |
|
|
;; |
146 |
|
|
*) |
147 |
|
|
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}" |
148 |
|
|
RETVAL=2 |
149 |
|
|
esac |
150 |
|
|
|
151 |
|
|
exit $RETVAL |
152 |
|
|
|