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>
This commit is contained in:
CHEN Gang 2018-08-29 15:46:48 +08:00 committed by lijinxia
parent a4cb3913b3
commit 37fd3871b7
3 changed files with 142 additions and 4 deletions

View File

@ -67,6 +67,7 @@ install:
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/debugger $(DESTDIR)/usr/bin/
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_c $(DESTDIR)/usr/bin/
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_s $(DESTDIR)/usr/bin/
@install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash-wrapper $(DESTDIR)/usr/bin/
@install -p -D -m 0755 data/acrnprobe_prepare.sh $(DESTDIR)/usr/bin/
@install -d $(DESTDIR)/usr/lib/systemd/system.conf.d/
@install -p -D -m 0644 data/40-watchdog.conf $(DESTDIR)/usr/lib/systemd/system.conf.d/
@ -94,6 +95,9 @@ uninstall:
@if [ -e "$(DESTDIR)/usr/bin/usercrash_s" ];then \
$(RM) $(DESTDIR)/usr/bin/usercrash_s; \
fi
@if [ -e "$(DESTDIR)/usr/bin/usercrash-wrapper" ];then \
$(RM) $(DESTDIR)/usr/bin/usercrash-wrapper; \
fi
@if [ -e "$(DESTDIR)/usr/lib/systemd/system.conf.d/40-watchdog.conf" ];then \
$(RM) $(DESTDIR)/usr/lib/systemd/system.conf.d/40-watchdog.conf; \
fi

View File

@ -4,14 +4,19 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# modify the core_pattern
core_pattern_conf="/proc/sys/kernel/core_pattern"
crashlog_path="/var/log/crashlog"
grep -q "coredump-wrapper" $core_pattern_conf
if [ "$?" -ne "0" ] then
echo "|/usr/bin/usercrash_c %p %e %s" > $core_pattern_conf
if [ ! -d $crashlog_path ]; then
mkdir -p $crashlog_path
fi
# backup the default core_pattern
cat $core_pattern_conf > /var/log/crashlog/default_core_pattern
# update the content of core_pattern, passdown all the parameters
echo "|/usr/bin/usercrash-wrapper %E %P %u %g %s %t %c %h %e %p %i %I %d" > $core_pattern_conf
default_conf="/usr/share/defaults/telemetrics/telemetrics.conf"
user_conf="/etc/telemetrics/telemetrics.conf"

View File

@ -0,0 +1,129 @@
#!/bin/bash
#
# Copyright (C) <2018> Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
if [ $# != 13 ]; then
logger "Expected 13 arguments, got $#"
exit -1
fi
# Error Handling
default_core_pattern_file="/var/log/crashlog/default_core_pattern"
if [ ! -f $default_core_pattern_file ]; then
logger "File default_core_pattern doesn't exist under /var/log/crashlog"
exit -1
fi
# default coredump app and usercrash parameters index file under /tmp
d_param_index_file=/tmp/default_param_index_file
u_param_index_file=/tmp/usercrash_param_index_file
# function to get the params from the input arguments
function get_params()
{
raw_params=$1
count=$[(${#raw_params} + 1) / 3]
for((i=0;i<$count;i++))
do
a_index=$[$i * 3 + 1]
param_list[$i]=${raw_params:($a_index):1}
done
return 0;
}
# function to generate the index for the parameters of default coredump app
function gen_index()
{
full_list=$1
dump_list=$2
i=0
for arg in ${dump_list[@]}
do
q=(`expr \`expr $(expr index "$full_list" "$arg") + 1\` / 2`)
index[$i]=$[$q - 1]
let i+=1
done
return 0;
}
# get default core_pattern parameters list
default_content=`cat $default_core_pattern_file`
default_params=${default_content#* }
# abstract the application of the default core_pattern
t_app=${default_content%% *}
default_app=${t_app#*|}
# function to save the index to /tmp. The index is the parameter
# index of the default coredump app and usercrash referring to
# the full parameters.
function save_index()
{
# get full coredump parameters list
pattern=`cat /proc/sys/kernel/core_pattern`
full_params=${pattern#* }
get_params "$full_params"
for((i=0;i<$count;i++))
do
full_param_list[$i]=${param_list[$i]}
done
get_params "$default_params"
for((i=0;i<$count;i++))
do
default_param_list[$i]=${param_list[$i]}
done
# get the index of default parameter list accroding to
# the full parameter list
gen_index "${full_param_list[*]}" "${default_param_list[*]}"
for((j=0;j<$i;j++))
do
default_param_index[$j]=${index[$j]}
done
echo "${default_param_index[@]}" > $d_param_index_file
# get the index of usercrash_c parameter accroding to
# the full parameter list
usercrash_param_list=("p" "e" "s")
gen_index "${full_param_list[*]}" "${usercrash_param_list[*]}"
for((j=0;j<$i;j++))
do
usercrash_param_index[$j]=${index[$j]}
done
echo "${usercrash_param_index[@]}" > $u_param_index_file
}
if [[ ! -f $d_param_index_file ]] || [[ ! -f $u_param_index_file ]];then
save_index
fi
# get all the value of parameters in var[]
i=0
for p in "$@"
do
var[$i]=$p
let i+=1
done
str_usercrash_param_index=`cat $u_param_index_file`
u_param_index_arr=(${str_usercrash_param_index// / })
for((i=0;i<${#u_param_index_arr[@]};i++))
do
usercrash_var[$i]=${var[${u_param_index_arr[$i]}]}
done
str_default_param_index=`cat $d_param_index_file`
d_param_index_arr=(${str_default_param_index// / })
for((i=0;i<${#d_param_index_arr[@]};i++))
do
default_var[$i]=${var[${d_param_index_arr[$i]}]}
done
tee >(/usr/bin/usercrash_c ${usercrash_var[*]}) | $default_app ${default_var[*]}