Skip to content

Commit f3fc857

Browse files
miguelinuxwenlingz
authored andcommitted
crashlog: introducing crashlogctl
This patch introduce the command `crashlogctl`, it is used to enable/disable the ACRN crashlog services. Also a systemd-tmpfile config file is introduced to create the /var/log/crashlog directory, and a sysctl config file where the usercrash-wrapper will be configured at boot time. Tracked-On: #1386 Signed-off-by: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com> Reviewed-by: Zhi Jin <zhi.jin@intel.com> Acked-by: Chen Gang <gang.c.chen@intel.com>
1 parent b1a05d1 commit f3fc857

File tree

3 files changed

+201
-0
lines changed

3 files changed

+201
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is part of acrn-hypervisor.
2+
3+
# See sysctl.d(5) for the description of the files in this directory,
4+
# and systemd-coredump(8) and core(5) for the explanation of the
5+
# setting below.
6+
7+
kernel.core_pattern=|/usr/bin/usercrash-wrapper %E %P %u %g %s %t %c %h %e %p %i %I %d
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Type Path Mode UID GID Age Argument
2+
d /var/log/crashlog 0750 telemetry telemetry -

tools/acrn-crashlog/data/crashlogctl

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) <2018> Intel Corporation
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
7+
declare -a CRASHLOG_SERVICES=(
8+
acrnprobe.service
9+
usercrash.service
10+
)
11+
12+
declare -a TELEMD_SERVICES=(
13+
hprobe.timer
14+
telemd-update-trigger.service
15+
pstore-clean.service
16+
pstore-probe.service
17+
oops-probe.service
18+
klogscanner.service
19+
journal-probe.service
20+
bert-probe.service
21+
)
22+
23+
SCRIPT="$0"
24+
TELEM_DIR=/etc/telemetrics
25+
OPT_OUT_FILE=${TELEM_DIR}/opt-out
26+
USER_CONF_FILE=${TELEM_DIR}/telemetrics.conf
27+
SYSTEM_CONF_FILE=/usr/share/defaults/telemetrics/telemetrics.conf
28+
CRASHLOG_SHARE_DIR=/usr/share/acrn/crashlog
29+
CRASHLOG_SYSTEM_CONF=${CRASHLOG_SHARE_DIR}/40-watchdog.conf
30+
CRASHLOG_SYSCTL_CONF=${CRASHLOG_SHARE_DIR}/80-coredump.conf
31+
CRASHLOG_VAR_DIR=/var/log/crashlog
32+
CRASHLOG_CORE_BACKUP=${CRASHLOG_VAR_DIR}/default_core_pattern
33+
CRASHLOG_S_D_BACKUP=${CRASHLOG_VAR_DIR}/server_delivery_enabled
34+
CRASHLOG_R_R_BACKUP=${CRASHLOG_VAR_DIR}/record_retention_enabled
35+
CRASHLOG_WRK_DIRS_CONF=/usr/lib/tmpfiles.d/acrn-crashlog-dirs.conf
36+
CORE_PATTERN_CONF="/proc/sys/kernel/core_pattern"
37+
38+
create_work_dirs() {
39+
# Creates dirs if missing, adjust ownership if exists
40+
systemd-tmpfiles --create ${CRASHLOG_WRK_DIRS_CONF}
41+
}
42+
43+
exit_ok() {
44+
echo "$1" > /dev/stderr
45+
exit 0
46+
}
47+
48+
exit_err() {
49+
echo "$1" > /dev/stderr
50+
exit 1
51+
}
52+
53+
notice() {
54+
echo "$1" > /dev/stderr
55+
}
56+
57+
for_each_service() {
58+
local action=$1 && shift
59+
local -a array=($*)
60+
for service in "${array[@]}"; do
61+
systemctl $action $service
62+
[ $? -ne 0 ] && notice "Failed to $action ${service}. Continuing..."
63+
done
64+
}
65+
66+
crashlog_enable() {
67+
[ -f $OPT_OUT_FILE ] && exit_err "Opt out is enabled. Cannot start services."
68+
# trigger systemd-tmpfiles work dirs creation
69+
create_work_dirs
70+
71+
# backup the default core_pattern
72+
if [ -f ${CRASHLOG_CORE_BACKUP} ]
73+
then
74+
notice "... ${CRASHLOG_CORE_BACKUP} already exist. Do not perform backup"
75+
else
76+
cat ${CORE_PATTERN_CONF} > ${CRASHLOG_CORE_BACKUP}
77+
notice "... Backup core pattern to ${CRASHLOG_CORE_BACKUP}"
78+
fi
79+
80+
# copy the configure file
81+
if [ ! -f ${USER_CONF_FILE} ]
82+
then
83+
mkdir -p ${TELEM_DIR}
84+
cp -v ${SYSTEM_CONF_FILE} ${USER_CONF_FILE}
85+
fi
86+
87+
# modify the telemetics configure file
88+
if grep --quiet server_delivery_enabled=true ${USER_CONF_FILE}
89+
then
90+
sed -i "s/server_delivery_enabled=true/server_delivery_enabled=false/g" ${USER_CONF_FILE}
91+
echo 1 > ${CRASHLOG_S_D_BACKUP}
92+
notice "... Set server_delivery_enabled=false in ${USER_CONF_FILE}"
93+
fi
94+
95+
if grep --quiet record_retention_enabled=false ${USER_CONF_FILE}
96+
then
97+
sed -i "s/record_retention_enabled=false/record_retention_enabled=true/g" ${USER_CONF_FILE}
98+
echo 1 > ${CRASHLOG_R_R_BACKUP}
99+
notice "... Set record_retention_enabled=true in ${USER_CONF_FILE}"
100+
fi
101+
102+
# Copy watchdog and coredump conf files
103+
mkdir -p /etc/systemd/system.conf.d
104+
cp -v ${CRASHLOG_SYSTEM_CONF} /etc/systemd/system.conf.d
105+
mkdir -p /etc/sysctl.d
106+
cp -v ${CRASHLOG_SYSCTL_CONF} /etc/sysctl.d
107+
108+
# Mask telemd services
109+
for_each_service "mask" ${TELEMD_SERVICES[@]}
110+
# Enable chrashlog services
111+
for_each_service "enable" ${CRASHLOG_SERVICES[@]}
112+
113+
exit_ok "*** Please reboot your system. ***"
114+
}
115+
116+
crashlog_disable() {
117+
# Disable chrashlog services
118+
for_each_service "disable" ${CRASHLOG_SERVICES[@]}
119+
# Unmask telemd services
120+
for_each_service "unmask" ${TELEMD_SERVICES[@]}
121+
122+
rm -v /etc/sysctl.d/${CRASHLOG_SYSCTL_CONF##*/}
123+
rm -v /etc/systemd/system.conf.d/${CRASHLOG_SYSTEM_CONF##*/}
124+
125+
# modify the telemetics configure file
126+
if [ -f ${CRASHLOG_S_D_BACKUP} ]
127+
then
128+
sed -i "s/server_delivery_enabled=false/server_delivery_enabled=true/g" ${USER_CONF_FILE}
129+
rm -f ${CRASHLOG_S_D_BACKUP}
130+
notice "... Set server_delivery_enabled=true in ${USER_CONF_FILE}"
131+
fi
132+
133+
if [ -f ${CRASHLOG_R_R_BACKUP} ]
134+
then
135+
sed -i "s/record_retention_enabled=true/record_retention_enabled=false/g" ${USER_CONF_FILE}
136+
rm -f ${CRASHLOG_R_R_BACKUP}
137+
notice "... Set record_retention_enabled=false in ${USER_CONF_FILE}"
138+
fi
139+
140+
rm -f ${CRASHLOG_CORE_BACKUP}
141+
142+
exit_ok "*** Please reboot your system. ***"
143+
}
144+
145+
crashlog_is_active() {
146+
# check only activation units
147+
echo "telemprobd :" $(systemctl is-active telemprobd.socket)
148+
echo "telempostd :" $(systemctl is-active telempostd.path)
149+
echo "acrnprobe :" $(systemctl is-active acrnprobe.service)
150+
echo "usercrash :" $(systemctl is-active usercrash.service)
151+
}
152+
153+
154+
usage() {
155+
format=' %-10s %s\n'
156+
printf "\n"
157+
printf "%s - Control actions for ACRN crashlog services\n" "$SCRIPT"
158+
printf "\n"
159+
printf "$format" "enable" "Enable the ACRN crashlog services"
160+
printf "$format" "disable" "Disable the ACRN crashlog services"
161+
printf "$format" "is-active" "Checks if ACRN crashlog is active"
162+
printf "\n"
163+
exit 2
164+
}
165+
166+
if [ $# -ne 1 ]; then
167+
usage
168+
fi
169+
170+
if [ $EUID -ne 0 ]; then
171+
exit_err "Must be root to run this command. Exiting..."
172+
fi
173+
174+
SUBCOMMAND=$1
175+
176+
case $SUBCOMMAND in
177+
enable)
178+
crashlog_enable ;;
179+
disable)
180+
crashlog_disable ;;
181+
is-active)
182+
crashlog_is_active ;;
183+
--help | -h)
184+
usage ;;
185+
*)
186+
notice "Unknown command passed to $SCRIPT"
187+
usage ;;
188+
esac
189+
190+
exit 0
191+
192+
# vi: ts=8 sw=2 sts=2 et tw=80

0 commit comments

Comments
 (0)