|
| 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