[PATCH] kernelscan: add -k option to specify klog json filename
Colin King
colin.king at canonical.com
Wed Sep 19 07:43:40 UTC 2018
From: Colin Ian King <colin.king at canonical.com>
This allows one to specify the location of the klog json file. Currently
this is hard coded to be /usr/share/fwts/klog.json, but this new option
allows one to specify the full path. This allows us to use the json file
in the fwts src rather than the installed version.
E.g.
./kernelscan.sh -k ~/repos/fwts/data/klog.json ~/repos/linux
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/utilities/kernelscan.c | 29 ++++++++++++++++++++++++++---
src/utilities/kernelscan.sh | 33 +++++++++++++++++++++++++++++----
2 files changed, 55 insertions(+), 7 deletions(-)
diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c
index 1974f53a..c1655fe4 100644
--- a/src/utilities/kernelscan.c
+++ b/src/utilities/kernelscan.c
@@ -191,6 +191,8 @@ static char *funcs[] = {
#define TABLE_SIZE (5000)
+static char *klog_file = DATAROOTDIR "/fwts/klog.json";
+
static char *hash_funcs[TABLE_SIZE];
static int get_token(parser *p, token *t);
@@ -348,7 +350,7 @@ static klog_pattern *klog_load(const char *table)
json_object *klog_table;
klog_pattern *patterns;
- klog_objs = json_object_from_file(DATAROOTDIR "/fwts/klog.json");
+ klog_objs = json_object_from_file(klog_file);
if (JSON_ERROR(klog_objs)) {
fprintf(stderr, "Cannot load klog data\n");
exit(EXIT_FAILURE);
@@ -1015,6 +1017,13 @@ static void hash_init(void)
}
}
+void help(void)
+{
+ printf("kernelscan:\n");
+ printf("-h\t\thelp\n");
+ printf("-k file\t\tspecify klog json file\n");
+}
+
/*
* Scan kernel source for printk KERN_ERR and dev_err
* calls.
@@ -1030,8 +1039,22 @@ static void hash_init(void)
*/
int main(int argc, char **argv)
{
- (void)argc;
- (void)argv;
+ for (;;) {
+ int c = getopt(argc, argv, "hk:");
+ if (c == -1)
+ break;
+ switch (c) {
+ case 'h':
+ help();
+ exit(0);
+ case 'k':
+ klog_file = optarg;
+ break;
+ default:
+ help();
+ exit(1);
+ }
+ }
patterns = klog_load("firmware_error_warning_patterns");
hash_init();
diff --git a/src/utilities/kernelscan.sh b/src/utilities/kernelscan.sh
index 7b274959..61207662 100755
--- a/src/utilities/kernelscan.sh
+++ b/src/utilities/kernelscan.sh
@@ -32,17 +32,42 @@ if [ $# -lt 1 ]; then
exit 1
fi
-src=$1
+KLOG=/usr/share/fwts/klog.json
-if [ ! -d $1 ]; then
- echo "Path '$1' not found"
+while [[ $# -gt 0 ]]
+do
+
+case "$1" in
+ -k)
+ shift
+ KLOG=$1
+ shift
+ ;;
+ *)
+ src=$1
+ shift
+ ;;
+esac
+done
+
+if [ "$src" == "" ]; then
+ echo "Please provide path to linux source"
+ exit 1
+fi
+
+if [ ! -d "$src" ]; then
+ echo "Path '$src' not found"
+ exit 1
+fi
+if [ ! -e "${KLOG}" ]; then
+ echo "Path '${KLOG}' not found"
exit 1
fi
scan_source_file()
{
if [ -f $1 ]; then
- $KERNELSCAN -P < $1 > $TMP
+ $KERNELSCAN -k ${KLOG} < $1 > $TMP
if [ $(stat -c%s $TMP) -gt 0 ]; then
echo "Source: $1"
cat $TMP
--
2.17.1
More information about the fwts-devel
mailing list