|
Packit |
8ea169 |
/*
|
|
Packit |
8ea169 |
Copyright (C) 2013 ABRT Team
|
|
Packit |
8ea169 |
Copyright (C) 2013 RedHat inc.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
8ea169 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
8ea169 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
8ea169 |
(at your option) any later version.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
8ea169 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8ea169 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8ea169 |
GNU General Public License for more details.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
You should have received a copy of the GNU General Public License along
|
|
Packit |
8ea169 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
8ea169 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
#include <unistd.h>
|
|
Packit |
8ea169 |
#include <sys/types.h>
|
|
Packit |
8ea169 |
#include "problem_api.h"
|
|
Packit |
8ea169 |
#include "abrt-cli-core.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
static unsigned int count_problem_dirs(unsigned long since)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
unsigned count = 0;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
GList *problems = get_problems_over_dbus(g_cli_authenticate);
|
|
Packit |
8ea169 |
if (problems == ERR_PTR)
|
|
Packit |
8ea169 |
return count;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
for (GList *iter = problems; iter != NULL; iter = g_list_next(iter))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
const char *problem_id = (const char *)iter->data;
|
|
Packit |
8ea169 |
if (test_exist_over_dbus(problem_id, FILENAME_REPORTED_TO))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
log_debug("Not counting problem %s: already reported", problem_id);
|
|
Packit |
8ea169 |
continue;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
char *time_str = load_text_over_dbus(problem_id, FILENAME_LAST_OCCURRENCE);
|
|
Packit |
8ea169 |
if (time_str == ERR_PTR || time_str == NULL)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
log_debug("Not counting problem %s: failed to get time element", problem_id);
|
|
Packit |
8ea169 |
continue;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
long val = atol(time_str);
|
|
Packit |
8ea169 |
free(time_str);
|
|
Packit |
8ea169 |
if (val < since)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
log_debug("Not counting problem %s: older tham limit (%ld < %ld)", problem_id, val, since);
|
|
Packit |
8ea169 |
continue;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
count++;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return count;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int cmd_status(int argc, const char **argv)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
const char *program_usage_string = _(
|
|
Packit |
8ea169 |
"& status"
|
|
Packit |
8ea169 |
);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int opt_bare = 0; /* must be _int_, OPT_BOOL expects that! */
|
|
Packit |
8ea169 |
int opt_since = 0;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
struct options program_options[] = {
|
|
Packit |
8ea169 |
OPT__VERBOSE(&g_verbose),
|
|
Packit |
8ea169 |
OPT_BOOL ('b', "bare", &opt_bare, _("Print only the problem count without any message")),
|
|
Packit |
8ea169 |
OPT_INTEGER('s', "since", &opt_since, _("Print only the problems more recent than specified timestamp")),
|
|
Packit |
8ea169 |
OPT_END()
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
parse_opts(argc, (char **)argv, program_options, program_usage_string);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
unsigned int problem_count = count_problem_dirs(opt_since);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* show only if there is at least 1 problem or user set the -v */
|
|
Packit |
8ea169 |
if (problem_count > 0 || g_verbose > 0)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
if (opt_bare)
|
|
Packit |
8ea169 |
printf("%u", problem_count);
|
|
Packit |
8ea169 |
else
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
char *list_arg = opt_since ? xasprintf(" --since %d", opt_since) : xstrdup("");
|
|
Packit |
8ea169 |
printf(_("ABRT has detected %u problem(s). For more info run: abrt-cli list%s\n"), problem_count, list_arg);
|
|
Packit |
8ea169 |
free(list_arg);
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return 0;
|
|
Packit |
8ea169 |
}
|