|
Packit |
8ea169 |
/*
|
|
Packit |
8ea169 |
Copyright (C) 2011 ABRT Team
|
|
Packit |
8ea169 |
Copyright (C) 2011 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 "libabrt.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
#include "abrt-cli-core.h"
|
|
Packit |
8ea169 |
#include "builtin-cmd.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int _cmd_report(const char **dirs_strv, int flags)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
int ret = 0;
|
|
Packit |
8ea169 |
while (*dirs_strv)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
const char *dir_name = *dirs_strv++;
|
|
Packit |
8ea169 |
char *const real_problem_id = hash2dirname_if_necessary(dir_name);
|
|
Packit |
8ea169 |
if (real_problem_id == NULL)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
error_msg(_("Can't find problem '%s'"), dir_name);
|
|
Packit |
8ea169 |
++ret;
|
|
Packit |
8ea169 |
continue;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
const int not_reportable = test_exist_over_dbus(real_problem_id, FILENAME_NOT_REPORTABLE);
|
|
Packit |
8ea169 |
if (not_reportable != 0)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
if (!(flags & CMD_REPORT_UNSAFE))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
if (g_verbose > 0)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
char *reason = load_text_over_dbus(real_problem_id, FILENAME_NOT_REPORTABLE);
|
|
Packit |
8ea169 |
if (reason != NULL)
|
|
Packit |
8ea169 |
log_warning("%s\n", reason);
|
|
Packit |
8ea169 |
free(reason);
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
error_msg(_("Problem '%s' cannot be reported"), real_problem_id);
|
|
Packit |
8ea169 |
free(real_problem_id);
|
|
Packit |
8ea169 |
++ret;
|
|
Packit |
8ea169 |
continue;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
log_info(_("Problem '%s' is labeled as 'not-reportable'?"), real_problem_id);
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
const int res = chown_dir_over_dbus(real_problem_id);
|
|
Packit |
8ea169 |
if (res != 0)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
error_msg(_("Can't take ownership of '%s'"), real_problem_id);
|
|
Packit |
8ea169 |
free(real_problem_id);
|
|
Packit |
8ea169 |
++ret;
|
|
Packit |
8ea169 |
continue;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int lr_flags = LIBREPORT_WAIT | LIBREPORT_RUN_CLI;
|
|
Packit |
8ea169 |
if (flags & CMD_REPORT_UNSAFE)
|
|
Packit |
8ea169 |
lr_flags |= LIBREPORT_IGNORE_NOT_REPORTABLE;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int status = report_problem_in_dir(real_problem_id, lr_flags);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* the problem was successfully reported and option is -d */
|
|
Packit |
8ea169 |
if((flags & CMD_REPORT_REMOVE) && (status == 0 || status == EXIT_STOP_EVENT_RUN))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
log_warning(_("Deleting '%s'"), real_problem_id);
|
|
Packit |
8ea169 |
delete_dump_dir_possibly_using_abrtd(real_problem_id);
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
free(real_problem_id);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
if (status)
|
|
Packit |
8ea169 |
exit(status);
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return ret;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int cmd_report(int argc, const char **argv)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
const char *program_usage_string = _(
|
|
Packit |
8ea169 |
"& report [options] DIR..."
|
|
Packit |
8ea169 |
);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
enum {
|
|
Packit |
8ea169 |
OPT_v = 1 << 0,
|
|
Packit |
8ea169 |
OPT_d = 1 << 1,
|
|
Packit |
8ea169 |
OPT_u = 1 << 2,
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
struct options program_options[] = {
|
|
Packit |
8ea169 |
OPT__VERBOSE(&g_verbose),
|
|
Packit |
8ea169 |
OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
|
|
Packit |
8ea169 |
OPT_BOOL('u', "unsafe", NULL, _("Ignore security checks to be able to "
|
|
Packit |
8ea169 |
"report all problems")),
|
|
Packit |
8ea169 |
OPT_END()
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
|
|
Packit |
8ea169 |
argv += optind;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
if (!argv[0])
|
|
Packit |
8ea169 |
show_usage_and_die(program_usage_string, program_options);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
export_abrt_envvars(/*prog_prefix:*/ 0);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
load_abrt_conf();
|
|
Packit |
8ea169 |
free_abrt_conf_data();
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int report_flags = 0;
|
|
Packit |
8ea169 |
if (opts & OPT_d)
|
|
Packit |
8ea169 |
report_flags |= CMD_REPORT_REMOVE;
|
|
Packit |
8ea169 |
if (opts & OPT_u)
|
|
Packit |
8ea169 |
report_flags |= CMD_REPORT_UNSAFE;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return _cmd_report(argv, report_flags);
|
|
Packit |
8ea169 |
}
|