From bc7e2610eed532a18de5d6b29a29b81aa5bce37e Mon Sep 17 00:00:00 2001 From: Tian Baofeng Date: Fri, 30 Aug 2019 17:20:38 +0800 Subject: [PATCH] pstore_probe.c: add ramoops file support in pstore probe for cl telemetry Add support for ramoops files in pstore probe, get the crash information from "/sys/fs/pstore/dmesg-ramoops-x" files. Add the "-f" cmd option support to input runtime config file when running the probe. Change-Id: Id7f26d6e07a7c215027b9be039356b2633d4869f Signed-off-by: Tian Baofeng --- src/probes/pstore_probe.c | 42 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/probes/pstore_probe.c b/src/probes/pstore_probe.c index 39f5ad5..91dc745 100644 --- a/src/probes/pstore_probe.c +++ b/src/probes/pstore_probe.c @@ -15,6 +15,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -195,6 +196,13 @@ struct chunk_list { struct chunk_list *next; }; +static void print_usage(char *prog) +{ + printf("%s: Usage\n", prog); + printf(" -f, --config_file This overides the other parameters\n"); + printf(" -h, --help Display this help message\n"); +} + int main(int argc, char **argv) { DIR *pstore_dir; @@ -205,6 +213,32 @@ int main(int argc, char **argv) int max_part; size_t totalsize = 0; char *crash_dump = NULL; + int c; + int opt_index = 0; + + struct option opts[] = { + { "config_file", 1, NULL, 'f' }, + { "help", 0, NULL, 'h' }, + { NULL, 0, NULL, 0 } + }; + + while ((c = getopt_long(argc, argv, "f:h", opts, &opt_index)) != -1) { + switch (c) { + case 'f': + if (tm_set_config_file(optarg) != 0) { + telem_log(LOG_ERR, "Configuration file" + " path not valid\n"); + exit(EXIT_FAILURE); + } + break; + case 'h': + print_usage(argv[0]); + exit(EXIT_SUCCESS); + case '?': + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + } /* * Hash table used to store chunks belonging to a oops counter @@ -230,7 +264,13 @@ int main(int argc, char **argv) // Look for only dmesg logs. Ignore other types of pstore dumps for now. if (sscanf(entry->d_name, "dmesg-efi-%" PRIu64, &id) == 1) { parse_id(id, &count, &part); - telem_debug("DEBUG: Extracted count :%d, part : %d\n", count, part); + telem_debug("dmesg-efi Extracted count :%d, part : %d\n", + count, part); + } else if (sscanf(entry->d_name, "dmesg-ramoops-%" PRIu64, &id) == 1) { + count = (int)(id + 1); + part = 1; + telem_debug("dmesg-ramoops Extracted count :%d, part : %d\n", + count, part); } else { continue; }