Message ID | 20180620121446.31470-12-info@marcellobauer.com |
---|---|
State | Accepted |
Headers | show |
Series | None | expand |
On 20/06/18 13:14, Marcello Sylvester Bauer wrote: > Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com> > --- > src/lib/include/fwts_log_scan.h | 1 + > src/lib/src/fwts_klog.c | 27 +-------------------------- > src/lib/src/fwts_log_scan.c | 35 +++++++++++++++++++++++++++++++++++ > 3 files changed, 37 insertions(+), 26 deletions(-) > > diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h > index b2364791..438dceb2 100644 > --- a/src/lib/include/fwts_log_scan.h > +++ b/src/lib/include/fwts_log_scan.h > @@ -52,5 +52,6 @@ void fwts_log_scan_patterns(fwts_framework *fw, char *line, int repeated, > fwts_compare_mode fwts_log_compare_mode_str_to_val(const char *str); > const char *fwts_json_str(fwts_framework *fw, const char *table, int index, json_object *obj, const char *key, bool log_error); > int fwts_log_check(fwts_framework *fw, const char *table, fwts_log_scan_func fwts_log_scan_patterns, fwts_log_progress_func progress, fwts_list *log, int *errors, const char *json_data_path, const char *label, bool remove_timestamp); > +int fwts_log_regex_find(fwts_framework *fw, fwts_list *log, char *pattern, bool remove_timestamp); > > #endif > diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c > index ea8d4ed7..fe4f2728 100644 > --- a/src/lib/src/fwts_klog.c > +++ b/src/lib/src/fwts_klog.c > @@ -160,27 +160,6 @@ int fwts_klog_pm_check(fwts_framework *fw, fwts_klog_progress_func progress, > progress, klog, errors); > } > > -static void fwts_klog_regex_find_callback(fwts_framework *fw, char *line, int repeated, > - char *prev, void *pattern, int *match) > -{ > - int rc; > - regex_t compiled; > - > - FWTS_UNUSED(fw); > - FWTS_UNUSED(repeated); > - FWTS_UNUSED(prev); > - > - rc = regcomp(&compiled, (char *)pattern, REG_EXTENDED); > - if (rc) { > - fwts_log_error(fw, "Regex %s failed to compile: %d.", (char *)pattern, rc); > - } else { > - rc = regexec(&compiled, line, 0, NULL, 0); > - regfree(&compiled); > - if (!rc) > - (*match)++; > - } > -} > - > /* > * fwts_klog_regex_find() > * scan a kernel log list of lines for a given regex pattern > @@ -188,11 +167,7 @@ static void fwts_klog_regex_find_callback(fwts_framework *fw, char *line, int re > */ > int fwts_klog_regex_find(fwts_framework *fw, fwts_list *klog, char *pattern) > { > - int found = 0; > - > - fwts_klog_scan(fw, klog, fwts_klog_regex_find_callback, NULL, pattern, &found); > - > - return found; > + return fwts_log_regex_find(fw, klog, pattern, true); > } > > /* > diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c > index 79979ff1..2ba23177 100644 > --- a/src/lib/src/fwts_log_scan.c > +++ b/src/lib/src/fwts_log_scan.c > @@ -464,3 +464,38 @@ fail_put: > > return ret; > } > + > +static void fwts_log_regex_find_callback(fwts_framework *fw, char *line, int repeated, > + char *prev, void *pattern, int *match) > +{ > + int rc; > + regex_t compiled; > + > + FWTS_UNUSED(fw); > + FWTS_UNUSED(repeated); > + FWTS_UNUSED(prev); > + > + rc = regcomp(&compiled, (char *)pattern, REG_EXTENDED); > + if (rc) { > + fwts_log_error(fw, "Regex %s failed to compile: %d.", (char *)pattern, rc); > + } else { > + rc = regexec(&compiled, line, 0, NULL, 0); > + regfree(&compiled); > + if (!rc) > + (*match)++; > + } > +} > + > +/* > + * fwts_log_regex_find() > + * scan a log list of lines for a given regex pattern > + * uses fwts_log_regex_find_callback() callback > + */ > +int fwts_log_regex_find(fwts_framework *fw, fwts_list *log, char *pattern, bool remove_timestamp) > +{ > + int found = 0; > + > + fwts_log_scan(fw, log, fwts_log_regex_find_callback, NULL, pattern, &found, remove_timestamp); > + > + return found; > +} > Acked-by: Colin Ian King <colin.king@canonical.com>
On 2018-06-20 05:14 AM, Marcello Sylvester Bauer wrote: > Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com> > --- > src/lib/include/fwts_log_scan.h | 1 + > src/lib/src/fwts_klog.c | 27 +-------------------------- > src/lib/src/fwts_log_scan.c | 35 +++++++++++++++++++++++++++++++++++ > 3 files changed, 37 insertions(+), 26 deletions(-) > > diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h > index b2364791..438dceb2 100644 > --- a/src/lib/include/fwts_log_scan.h > +++ b/src/lib/include/fwts_log_scan.h > @@ -52,5 +52,6 @@ void fwts_log_scan_patterns(fwts_framework *fw, char *line, int repeated, > fwts_compare_mode fwts_log_compare_mode_str_to_val(const char *str); > const char *fwts_json_str(fwts_framework *fw, const char *table, int index, json_object *obj, const char *key, bool log_error); > int fwts_log_check(fwts_framework *fw, const char *table, fwts_log_scan_func fwts_log_scan_patterns, fwts_log_progress_func progress, fwts_list *log, int *errors, const char *json_data_path, const char *label, bool remove_timestamp); > +int fwts_log_regex_find(fwts_framework *fw, fwts_list *log, char *pattern, bool remove_timestamp); > > #endif > diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c > index ea8d4ed7..fe4f2728 100644 > --- a/src/lib/src/fwts_klog.c > +++ b/src/lib/src/fwts_klog.c > @@ -160,27 +160,6 @@ int fwts_klog_pm_check(fwts_framework *fw, fwts_klog_progress_func progress, > progress, klog, errors); > } > > -static void fwts_klog_regex_find_callback(fwts_framework *fw, char *line, int repeated, > - char *prev, void *pattern, int *match) > -{ > - int rc; > - regex_t compiled; > - > - FWTS_UNUSED(fw); > - FWTS_UNUSED(repeated); > - FWTS_UNUSED(prev); > - > - rc = regcomp(&compiled, (char *)pattern, REG_EXTENDED); > - if (rc) { > - fwts_log_error(fw, "Regex %s failed to compile: %d.", (char *)pattern, rc); > - } else { > - rc = regexec(&compiled, line, 0, NULL, 0); > - regfree(&compiled); > - if (!rc) > - (*match)++; > - } > -} > - > /* > * fwts_klog_regex_find() > * scan a kernel log list of lines for a given regex pattern > @@ -188,11 +167,7 @@ static void fwts_klog_regex_find_callback(fwts_framework *fw, char *line, int re > */ > int fwts_klog_regex_find(fwts_framework *fw, fwts_list *klog, char *pattern) > { > - int found = 0; > - > - fwts_klog_scan(fw, klog, fwts_klog_regex_find_callback, NULL, pattern, &found); > - > - return found; > + return fwts_log_regex_find(fw, klog, pattern, true); > } > > /* > diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c > index 79979ff1..2ba23177 100644 > --- a/src/lib/src/fwts_log_scan.c > +++ b/src/lib/src/fwts_log_scan.c > @@ -464,3 +464,38 @@ fail_put: > > return ret; > } > + > +static void fwts_log_regex_find_callback(fwts_framework *fw, char *line, int repeated, > + char *prev, void *pattern, int *match) > +{ > + int rc; > + regex_t compiled; > + > + FWTS_UNUSED(fw); > + FWTS_UNUSED(repeated); > + FWTS_UNUSED(prev); > + > + rc = regcomp(&compiled, (char *)pattern, REG_EXTENDED); > + if (rc) { > + fwts_log_error(fw, "Regex %s failed to compile: %d.", (char *)pattern, rc); > + } else { > + rc = regexec(&compiled, line, 0, NULL, 0); > + regfree(&compiled); > + if (!rc) > + (*match)++; > + } > +} > + > +/* > + * fwts_log_regex_find() > + * scan a log list of lines for a given regex pattern > + * uses fwts_log_regex_find_callback() callback > + */ > +int fwts_log_regex_find(fwts_framework *fw, fwts_list *log, char *pattern, bool remove_timestamp) > +{ > + int found = 0; > + > + fwts_log_scan(fw, log, fwts_log_regex_find_callback, NULL, pattern, &found, remove_timestamp); > + > + return found; > +} > Acked-by: Alex Hung <alex.hung@canonical.com>
diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h index b2364791..438dceb2 100644 --- a/src/lib/include/fwts_log_scan.h +++ b/src/lib/include/fwts_log_scan.h @@ -52,5 +52,6 @@ void fwts_log_scan_patterns(fwts_framework *fw, char *line, int repeated, fwts_compare_mode fwts_log_compare_mode_str_to_val(const char *str); const char *fwts_json_str(fwts_framework *fw, const char *table, int index, json_object *obj, const char *key, bool log_error); int fwts_log_check(fwts_framework *fw, const char *table, fwts_log_scan_func fwts_log_scan_patterns, fwts_log_progress_func progress, fwts_list *log, int *errors, const char *json_data_path, const char *label, bool remove_timestamp); +int fwts_log_regex_find(fwts_framework *fw, fwts_list *log, char *pattern, bool remove_timestamp); #endif diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c index ea8d4ed7..fe4f2728 100644 --- a/src/lib/src/fwts_klog.c +++ b/src/lib/src/fwts_klog.c @@ -160,27 +160,6 @@ int fwts_klog_pm_check(fwts_framework *fw, fwts_klog_progress_func progress, progress, klog, errors); } -static void fwts_klog_regex_find_callback(fwts_framework *fw, char *line, int repeated, - char *prev, void *pattern, int *match) -{ - int rc; - regex_t compiled; - - FWTS_UNUSED(fw); - FWTS_UNUSED(repeated); - FWTS_UNUSED(prev); - - rc = regcomp(&compiled, (char *)pattern, REG_EXTENDED); - if (rc) { - fwts_log_error(fw, "Regex %s failed to compile: %d.", (char *)pattern, rc); - } else { - rc = regexec(&compiled, line, 0, NULL, 0); - regfree(&compiled); - if (!rc) - (*match)++; - } -} - /* * fwts_klog_regex_find() * scan a kernel log list of lines for a given regex pattern @@ -188,11 +167,7 @@ static void fwts_klog_regex_find_callback(fwts_framework *fw, char *line, int re */ int fwts_klog_regex_find(fwts_framework *fw, fwts_list *klog, char *pattern) { - int found = 0; - - fwts_klog_scan(fw, klog, fwts_klog_regex_find_callback, NULL, pattern, &found); - - return found; + return fwts_log_regex_find(fw, klog, pattern, true); } /* diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c index 79979ff1..2ba23177 100644 --- a/src/lib/src/fwts_log_scan.c +++ b/src/lib/src/fwts_log_scan.c @@ -464,3 +464,38 @@ fail_put: return ret; } + +static void fwts_log_regex_find_callback(fwts_framework *fw, char *line, int repeated, + char *prev, void *pattern, int *match) +{ + int rc; + regex_t compiled; + + FWTS_UNUSED(fw); + FWTS_UNUSED(repeated); + FWTS_UNUSED(prev); + + rc = regcomp(&compiled, (char *)pattern, REG_EXTENDED); + if (rc) { + fwts_log_error(fw, "Regex %s failed to compile: %d.", (char *)pattern, rc); + } else { + rc = regexec(&compiled, line, 0, NULL, 0); + regfree(&compiled); + if (!rc) + (*match)++; + } +} + +/* + * fwts_log_regex_find() + * scan a log list of lines for a given regex pattern + * uses fwts_log_regex_find_callback() callback + */ +int fwts_log_regex_find(fwts_framework *fw, fwts_list *log, char *pattern, bool remove_timestamp) +{ + int found = 0; + + fwts_log_scan(fw, log, fwts_log_regex_find_callback, NULL, pattern, &found, remove_timestamp); + + return found; +}
Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com> --- src/lib/include/fwts_log_scan.h | 1 + src/lib/src/fwts_klog.c | 27 +-------------------------- src/lib/src/fwts_log_scan.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 26 deletions(-)