Skip to content

Commit 37fd387

Browse files
chengangclijinxia
authored andcommitted
tools: acrn-crashlog: add usercrash_c in the pipe of core_pattern
This patch adds the usercrash client in the pipe of core_pattern without affecting default core_pattern program. In acrnprobe_prepare.sh, core_pattern will be set as usercrash-wrapper with all of the arguments, which parses the parameters of the default core_pattern program and the usercrash client, and then invokes them separately. Tracked-On: #1024 Signed-off-by: CHEN Gang <gang.c.chen@intel.com> Reviewed-by: Zhi Jin <zhi.jin@intel.com> Reviewed-by: xiaojin2 <xiaojing.liu@intel.com> Acked-by: Zhang Di <di.zhang@intel.com>
1 parent a4cb391 commit 37fd387

File tree

3 files changed

+142
-4
lines changed

3 files changed

+142
-4
lines changed

tools/acrn-crashlog/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ install:
6767
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/debugger $(DESTDIR)/usr/bin/
6868
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_c $(DESTDIR)/usr/bin/
6969
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_s $(DESTDIR)/usr/bin/
70+
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash-wrapper $(DESTDIR)/usr/bin/
7071
@install -p -D -m 0755 data/acrnprobe_prepare.sh $(DESTDIR)/usr/bin/
7172
@install -d $(DESTDIR)/usr/lib/systemd/system.conf.d/
7273
@install -p -D -m 0644 data/40-watchdog.conf $(DESTDIR)/usr/lib/systemd/system.conf.d/
@@ -94,6 +95,9 @@ uninstall:
9495
@if [ -e "$(DESTDIR)/usr/bin/usercrash_s" ];then \
9596
$(RM) $(DESTDIR)/usr/bin/usercrash_s; \
9697
fi
98+
@if [ -e "$(DESTDIR)/usr/bin/usercrash-wrapper" ];then \
99+
$(RM) $(DESTDIR)/usr/bin/usercrash-wrapper; \
100+
fi
97101
@if [ -e "$(DESTDIR)/usr/lib/systemd/system.conf.d/40-watchdog.conf" ];then \
98102
$(RM) $(DESTDIR)/usr/lib/systemd/system.conf.d/40-watchdog.conf; \
99103
fi

tools/acrn-crashlog/data/acrnprobe_prepare.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

7-
# modify the core_pattern
87
core_pattern_conf="/proc/sys/kernel/core_pattern"
8+
crashlog_path="/var/log/crashlog"
99

10-
grep -q "coredump-wrapper" $core_pattern_conf
11-
if [ "$?" -ne "0" ] then
12-
echo "|/usr/bin/usercrash_c %p %e %s" > $core_pattern_conf
10+
if [ ! -d $crashlog_path ]; then
11+
mkdir -p $crashlog_path
1312
fi
1413

14+
# backup the default core_pattern
15+
cat $core_pattern_conf > /var/log/crashlog/default_core_pattern
16+
17+
# update the content of core_pattern, passdown all the parameters
18+
echo "|/usr/bin/usercrash-wrapper %E %P %u %g %s %t %c %h %e %p %i %I %d" > $core_pattern_conf
19+
1520
default_conf="/usr/share/defaults/telemetrics/telemetrics.conf"
1621
user_conf="/etc/telemetrics/telemetrics.conf"
1722

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) <2018> Intel Corporation
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
7+
if [ $# != 13 ]; then
8+
logger "Expected 13 arguments, got $#"
9+
exit -1
10+
fi
11+
12+
# Error Handling
13+
default_core_pattern_file="/var/log/crashlog/default_core_pattern"
14+
15+
if [ ! -f $default_core_pattern_file ]; then
16+
logger "File default_core_pattern doesn't exist under /var/log/crashlog"
17+
exit -1
18+
fi
19+
20+
# default coredump app and usercrash parameters index file under /tmp
21+
d_param_index_file=/tmp/default_param_index_file
22+
u_param_index_file=/tmp/usercrash_param_index_file
23+
24+
# function to get the params from the input arguments
25+
function get_params()
26+
{
27+
raw_params=$1
28+
29+
count=$[(${#raw_params} + 1) / 3]
30+
for((i=0;i<$count;i++))
31+
do
32+
a_index=$[$i * 3 + 1]
33+
param_list[$i]=${raw_params:($a_index):1}
34+
done
35+
return 0;
36+
}
37+
38+
# function to generate the index for the parameters of default coredump app
39+
function gen_index()
40+
{
41+
full_list=$1
42+
dump_list=$2
43+
44+
i=0
45+
for arg in ${dump_list[@]}
46+
do
47+
q=(`expr \`expr $(expr index "$full_list" "$arg") + 1\` / 2`)
48+
index[$i]=$[$q - 1]
49+
let i+=1
50+
done
51+
return 0;
52+
}
53+
54+
# get default core_pattern parameters list
55+
default_content=`cat $default_core_pattern_file`
56+
default_params=${default_content#* }
57+
58+
# abstract the application of the default core_pattern
59+
t_app=${default_content%% *}
60+
default_app=${t_app#*|}
61+
62+
# function to save the index to /tmp. The index is the parameter
63+
# index of the default coredump app and usercrash referring to
64+
# the full parameters.
65+
function save_index()
66+
{
67+
# get full coredump parameters list
68+
pattern=`cat /proc/sys/kernel/core_pattern`
69+
full_params=${pattern#* }
70+
71+
get_params "$full_params"
72+
for((i=0;i<$count;i++))
73+
do
74+
full_param_list[$i]=${param_list[$i]}
75+
done
76+
77+
get_params "$default_params"
78+
for((i=0;i<$count;i++))
79+
do
80+
default_param_list[$i]=${param_list[$i]}
81+
done
82+
83+
# get the index of default parameter list accroding to
84+
# the full parameter list
85+
gen_index "${full_param_list[*]}" "${default_param_list[*]}"
86+
for((j=0;j<$i;j++))
87+
do
88+
default_param_index[$j]=${index[$j]}
89+
done
90+
echo "${default_param_index[@]}" > $d_param_index_file
91+
92+
# get the index of usercrash_c parameter accroding to
93+
# the full parameter list
94+
usercrash_param_list=("p" "e" "s")
95+
gen_index "${full_param_list[*]}" "${usercrash_param_list[*]}"
96+
for((j=0;j<$i;j++))
97+
do
98+
usercrash_param_index[$j]=${index[$j]}
99+
done
100+
echo "${usercrash_param_index[@]}" > $u_param_index_file
101+
}
102+
103+
if [[ ! -f $d_param_index_file ]] || [[ ! -f $u_param_index_file ]];then
104+
save_index
105+
fi
106+
107+
# get all the value of parameters in var[]
108+
i=0
109+
for p in "$@"
110+
do
111+
var[$i]=$p
112+
let i+=1
113+
done
114+
115+
str_usercrash_param_index=`cat $u_param_index_file`
116+
u_param_index_arr=(${str_usercrash_param_index// / })
117+
for((i=0;i<${#u_param_index_arr[@]};i++))
118+
do
119+
usercrash_var[$i]=${var[${u_param_index_arr[$i]}]}
120+
done
121+
122+
str_default_param_index=`cat $d_param_index_file`
123+
d_param_index_arr=(${str_default_param_index// / })
124+
for((i=0;i<${#d_param_index_arr[@]};i++))
125+
do
126+
default_var[$i]=${var[${d_param_index_arr[$i]}]}
127+
done
128+
129+
tee >(/usr/bin/usercrash_c ${usercrash_var[*]}) | $default_app ${default_var[*]}

0 commit comments

Comments
 (0)