/[packages]/cauldron/abrt/pristine/SOURCES/abrt-ccpp.init
ViewVC logotype

Contents of /cauldron/abrt/pristine/SOURCES/abrt-ccpp.init

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.28