[PATCH 1/3] Move get_problems_count() to its only user - "abrt-cli status"

Nikola Pajkovsky npajkovs at redhat.com
Thu May 23 10:32:33 UTC 2013


Denys Vlasenko <dvlasenk at redhat.com> writes:

> Logic is not changed.
>
> Signed-off-by: Denys Vlasenko <dvlasenk at redhat.com>
> ---
>  src/cli/status.c          | 49 +++++++++++++++++++++++++++++++++++++++++++----
>  src/include/problem_api.h |  8 --------
>  src/lib/problem_api.c     | 38 ------------------------------------
>  3 files changed, 45 insertions(+), 50 deletions(-)
>
> diff --git a/src/cli/status.c b/src/cli/status.c
> index 6f228c6..0dbcd1d 100644
> --- a/src/cli/status.c
> +++ b/src/cli/status.c
> @@ -21,13 +21,52 @@
>  #include <sys/types.h>
>  #include "problem_api.h"
>  
> +struct time_range {
> +    unsigned count;
> +    unsigned long since;
> +};
> +
> +static int count_dir_if_newer_than(struct dump_dir *dd, void *arg)
> +{
> +    struct time_range *me = arg;
> +
> +    char *time_str = dd_load_text(dd, FILENAME_LAST_OCCURRENCE);
> +    long val = atol(time_str);
> +    free(time_str);
> +    if (val < me->since)
> +        return 0;
> +
> +    me->count++;
> +    return 0;
> +}
> +
> +static void count_problems_in_dir(gpointer data, gpointer arg)
> +{
> +    char *path = data;
> +    struct time_range *me = arg;
> +
> +    VERB2 log("scanning '%s' for problems since %lu", path, me->since);
> +
> +    for_each_problem_in_dir(path, getuid(), count_dir_if_newer_than, me);

I still think, that there is a way, how to write it without
callback. like:

     dir_for_each(path, iterator, and whatever else you is meaningful) {
             count_dir();
     }

because callbacks are moronic in sense that you you have to pass
pointers to functions and that functions the most of time do simple
thing. And I don't see any reasons to use callbacks here.

-- 
Nikola


More information about the Crash-catcher mailing list