ACK: [PATCH 1/3] lib: klog: add fwts_klog_find_changes to compare klogs (LP: #1262208)
IvanHu
ivan.hu at canonical.com
Mon Dec 23 08:08:49 UTC 2013
On 12/18/2013 10:19 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Add a new klog helper to allow one to compare any changes
> in the kernel log between an old and new klog lists.
>
> Remove fwts_klog_clear as it won't be needed anymore.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/lib/include/fwts_klog.h | 2 +-
> src/lib/src/fwts_klog.c | 51 +++++++++++++++++++++++++++++++++++++++------
> 2 files changed, 46 insertions(+), 7 deletions(-)
>
> diff --git a/src/lib/include/fwts_klog.h b/src/lib/include/fwts_klog.h
> index fe8f520..512992e 100644
> --- a/src/lib/include/fwts_klog.h
> +++ b/src/lib/include/fwts_klog.h
> @@ -53,9 +53,9 @@ typedef void (*fwts_klog_scan_func)(fwts_framework *fw, char *line, int repeated
> int fwts_klog_scan(fwts_framework *fw, fwts_list *klog, fwts_klog_scan_func callback, fwts_klog_progress_func progress, void *private, int *errors);
> void fwts_klog_scan_patterns(fwts_framework *fw, char *line, int repeated, char *prevline, void *private, int *errors);
> fwts_list *fwts_klog_read(void);
> +fwts_list *fwts_klog_find_changes(fwts_list *klog_old, fwts_list *klog_new);
> void fwts_klog_free(fwts_list *list);
>
> -int fwts_klog_clear(void);
>
> int fwts_klog_firmware_check(fwts_framework *fw, fwts_klog_progress_func progress, fwts_list *klog, int *errors);
> int fwts_klog_pm_check(fwts_framework *fw, fwts_klog_progress_func progress, fwts_list *klog, int *errors);
> diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
> index 9ae93d6..82e5b0b 100644
> --- a/src/lib/src/fwts_klog.c
> +++ b/src/lib/src/fwts_klog.c
> @@ -46,14 +46,53 @@ void fwts_klog_free(fwts_list *klog)
> }
>
> /*
> - * fwts_klog_clear()
> - * clear messages out of kernel log
> + * fwts_klog_find_changes()
> + * find new lines added to kernel log, clone them from new list
> + * must be freed with fwts_list_free(klog_diff, NULL);
> */
> -int fwts_klog_clear(void)
> +fwts_list *fwts_klog_find_changes(fwts_list *klog_old, fwts_list *klog_new)
> {
> - if (klogctl(5, NULL, 0) < 0)
> - return FWTS_ERROR;
> - return FWTS_OK;
> + fwts_list_link *l_old, *l_new, *l_old_last = NULL;
> + fwts_list *klog_diff;
> + char *old;
> +
> + if (klog_new == NULL) {
> + /* Nothing new to compare, return nothing */
> + return NULL;
> + }
> + if ((klog_diff = fwts_list_new()) == NULL)
> + return NULL;
> +
> + if (klog_old == NULL) {
> + /* Nothing in old log, so clone all of new list */
> + l_new = klog_new->head;
> + } else {
> + /* Clone just the new differences */
> +
> + /* Find last item in old log */
> + fwts_list_foreach(l_old, klog_old)
> + l_old_last = l_old;
> +
> + /* And now look for that last line in the new log */
> + old = fwts_list_data(char *, l_old_last);
> + fwts_list_foreach(l_new, klog_new) {
> + char *new = fwts_list_data(char *, l_new);
> + if (!strcmp(new, old)) {
> + /* Found last line that matches, bump to next */
> + l_new = l_new->next;
> + break;
> + }
> + }
> + }
> +
> + /* Clone the new unique lines to the klog_diff list */
> + for (; l_new; l_new = l_new->next) {
> + if (fwts_list_append(klog_diff, l_new->data) == NULL) {
> + fwts_list_free(klog_diff, NULL);
> + return NULL;
> + }
> + }
> + return klog_diff;
> }
>
> /*
>
Acked-by: Ivan Hu <ivan.hu at canonical.com>
More information about the fwts-devel
mailing list