Blame src/plugins/abrt-dump-xorg.c

Packit 8ea169
/*
Packit 8ea169
    Copyright (C) 2012  ABRT Team
Packit 8ea169
    Copyright (C) 2012  Red Hat, 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
#include "libabrt.h"
Packit 8ea169
#include "xorg-utils.h"
Packit 8ea169
Packit 8ea169
int main(int argc, char **argv)
Packit 8ea169
{
Packit 8ea169
    /* I18n */
Packit 8ea169
    setlocale(LC_ALL, "");
Packit 8ea169
#if ENABLE_NLS
Packit 8ea169
    bindtextdomain(PACKAGE, LOCALEDIR);
Packit 8ea169
    textdomain(PACKAGE);
Packit 8ea169
#endif
Packit 8ea169
Packit 8ea169
    abrt_init(argv);
Packit 8ea169
Packit 8ea169
    /* Can't keep these strings/structs static: _() doesn't support that */
Packit 8ea169
    const char *program_usage_string = _(
Packit 8ea169
        "& [-vsoxm] [-d DIR]/[-D] [FILE]\n"
Packit 8ea169
        "\n"
Packit 8ea169
        "Extract Xorg crash from FILE (or standard input)"
Packit 8ea169
    );
Packit 8ea169
    enum {
Packit 8ea169
        OPT_v = 1 << 0,
Packit 8ea169
        OPT_s = 1 << 1,
Packit 8ea169
        OPT_o = 1 << 2,
Packit 8ea169
        OPT_d = 1 << 3,
Packit 8ea169
        OPT_D = 1 << 4,
Packit 8ea169
        OPT_x = 1 << 5,
Packit 8ea169
        OPT_m = 1 << 6,
Packit 8ea169
    };
Packit 8ea169
    char *dump_location = NULL;
Packit 8ea169
    /* Keep OPT_z enums and order of options below in sync! */
Packit 8ea169
    struct options program_options[] = {
Packit 8ea169
        OPT__VERBOSE(&g_verbose),
Packit 8ea169
        OPT_BOOL(  's', NULL, NULL, _("Log to syslog")),
Packit 8ea169
        OPT_BOOL(  'o', NULL, NULL, _("Print found crash data on standard output")),
Packit 8ea169
        OPT_STRING('d', NULL, &dump_location, "DIR", _("Create problem directory in DIR for every crash found")),
Packit 8ea169
        OPT_BOOL(  'D', NULL, NULL, _("Same as -d DumpLocation, DumpLocation is specified in abrt.conf")),
Packit 8ea169
        OPT_BOOL(  'x', NULL, NULL, _("Make the problem directory world readable")),
Packit 8ea169
        OPT_BOOL(  'm', NULL, NULL, _("Print search string(s) to stdout and exit")),
Packit 8ea169
        OPT_END()
Packit 8ea169
    };
Packit 8ea169
    unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
Packit 8ea169
Packit 8ea169
    export_abrt_envvars(0);
Packit 8ea169
Packit 8ea169
    msg_prefix = g_progname;
Packit 8ea169
    if ((opts & OPT_s) || getenv("ABRT_SYSLOG"))
Packit 8ea169
    {
Packit 8ea169
        logmode = LOGMODE_JOURNAL;
Packit 8ea169
    }
Packit 8ea169
Packit 8ea169
    if (opts & OPT_m)
Packit 8ea169
    {
Packit 8ea169
        puts("Backtrace");
Packit 8ea169
        return 0;
Packit 8ea169
    }
Packit 8ea169
Packit 8ea169
    if (opts & OPT_D)
Packit 8ea169
    {
Packit 8ea169
        if (opts & OPT_d)
Packit 8ea169
            show_usage_and_die(program_usage_string, program_options);
Packit 8ea169
        load_abrt_conf();
Packit 8ea169
        dump_location = g_settings_dump_location;
Packit 8ea169
        g_settings_dump_location = NULL;
Packit 8ea169
        free_abrt_conf_data();
Packit 8ea169
    }
Packit 8ea169
Packit 8ea169
    argv += optind;
Packit 8ea169
    if (argv[0])
Packit 8ea169
        xmove_fd(xopen(argv[0], O_RDONLY), STDIN_FILENO);
Packit 8ea169
Packit 8ea169
    int bt_count = 0;
Packit 8ea169
    char *line = NULL;
Packit 8ea169
    while ((line = xmalloc_fgetline(stdin)) != NULL)
Packit 8ea169
    {
Packit 8ea169
        char *p = skip_pfx(line);
Packit 8ea169
        if (strcmp(p, "Backtrace:") == 0)
Packit 8ea169
        {
Packit 8ea169
            struct xorg_crash_info *crash_info = process_xorg_bt(&xorg_get_next_line_from_fd, stdin);
Packit 8ea169
            if (crash_info)
Packit 8ea169
            {
Packit 8ea169
                if (opts & OPT_o)
Packit 8ea169
                    xorg_crash_info_print_crash(crash_info);
Packit 8ea169
                if (opts & (OPT_d|OPT_D))
Packit 8ea169
                    if (bt_count++ <= ABRT_OOPS_MAX_DUMPED_COUNT)
Packit 8ea169
                        xorg_crash_info_create_dump_dir(crash_info, dump_location, (opts & OPT_x));
Packit 8ea169
                xorg_crash_info_free(crash_info);
Packit 8ea169
            }
Packit 8ea169
            else
Packit 8ea169
                log_warning(_("Failed to parse Backtrace from log file"));
Packit 8ea169
        }
Packit 8ea169
        free(line);
Packit 8ea169
    }
Packit 8ea169
Packit 8ea169
    return 0;
Packit 8ea169
}