char *abrt_oops_string_filter_regex(void) { map_string_t *settings = new_map_string(); load_abrt_plugin_conf_file("oops.conf", settings); int only_fatal_mce = 1; try_get_map_string_item_as_bool(settings, "OnlyFatalMCE", &only_fatal_mce); free_map_string(settings); if (only_fatal_mce) return xstrdup("^Machine .*$"); return NULL; }
int main(int argc, char **argv) { /* I18n */ setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif abrt_init(argv); char *i_opt = NULL; /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( "& [options] -d DIR\n" "\n" "Analyzes coredump in problem directory DIR, generates and saves backtrace" ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, OPT_i = 1 << 2, OPT_t = 1 << 3, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING( 'd', NULL, &dump_dir_name , "DIR" , _("Problem directory")), OPT_STRING( 'i', NULL, &i_opt , "DIR1[:DIR2]...", _("Additional debuginfo directories")), OPT_INTEGER('t', NULL, &exec_timeout_sec, _("Kill gdb if it runs for more than NUM seconds")), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); export_abrt_envvars(0); map_string_t *settings = new_map_string(); if (!load_abrt_plugin_conf_file(CCPP_CONF, settings)) error_msg("Can't load '%s'", CCPP_CONF); const char *value = get_map_string_item_or_NULL(settings, "DebuginfoLocation"); char *debuginfo_location; if (value) debuginfo_location = xstrdup(value); else debuginfo_location = xstrdup(LOCALSTATEDIR"/cache/abrt-di"); free_map_string(settings); char *debuginfo_dirs = NULL; if (i_opt) debuginfo_dirs = xasprintf("%s:%s", debuginfo_location, i_opt); /* Create gdb backtrace */ char *backtrace = get_backtrace(dump_dir_name, exec_timeout_sec, (debuginfo_dirs) ? debuginfo_dirs : debuginfo_location); free(debuginfo_location); if (!backtrace) { backtrace = xstrdup(""); log_warning("get_backtrace() returns NULL, broken core/gdb?"); } free(debuginfo_dirs); free_abrt_conf_data(); /* Store gdb backtrace */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; dd_save_text(dd, FILENAME_BACKTRACE, backtrace); dd_close(dd); /* Don't be completely silent. gdb run takes a few seconds, * it is useful to let user know it (maybe) worked. */ log_warning(_("Backtrace is generated and saved, %u bytes"), (int)strlen(backtrace)); free(backtrace); return 0; }
int main(int argc, char **argv) { abrt_init(argv); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, OPT_g = 1 << 2, OPT_b = 1 << 3, OPT_u = 1 << 4, OPT_r = 1 << 5, }; const char *bugs = NULL, *release = NULL, *dump_dir_path = "."; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT__DUMP_DIR(&dump_dir_path), OPT_GROUP(""), OPT_STRING('b', "bugs", &bugs, "ID1[,ID2,...]" , _("List of bug ids")), OPT_STRING('u', "url", &bodhi_url, "URL", _("Specify a bodhi server url")), OPT_OPTSTRING('r', "release", &release, "RELEASE", _("Specify a release")), OPT_END() }; const char *program_usage_string = _( "& [-v] [-r[RELEASE]] (-b ID1[,ID2,...] | PKG-NAME) [PKG-NAME]... \n" "\n" "Search for updates on bodhi server" ); unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); if (!bugs && !argv[optind]) show_usage_and_die(program_usage_string, program_options); struct strbuf *query = strbuf_new(); if (bugs) query = strbuf_append_strf(query, "bugs=%s&", bugs); if (opts & OPT_r) { if (release) { /* There are no bodhi updates for Rawhide */ if (strcasecmp(release, "rawhide") == 0) error_msg_and_die("Release \"%s\" is not supported",release); query = strbuf_append_strf(query, "releases=%s&", release); } else { struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY); if (!dd) xfunc_die(); problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); if (!problem_data) xfunc_die(); /* create_problem_data_for_reporting already emitted error msg */ char *product, *version; map_string_t *osinfo = new_map_string(); problem_data_get_osinfo(problem_data, osinfo); parse_osinfo_for_rhts(osinfo, &product, &version); /* There are no bodhi updates for Rawhide */ bool rawhide = strcasecmp(version, "rawhide") == 0; if (!rawhide) query = strbuf_append_strf(query, "releases=f%s&", version); free(product); free(version); free_map_string(osinfo); if (rawhide) { strbuf_free(query); error_msg_and_die("Release \"Rawhide\" is not supported"); } } } if (argv[optind]) { char *escaped = g_uri_escape_string(argv[optind], NULL, 0); query = strbuf_append_strf(query, "packages=%s&", escaped); free(escaped); } if (query->buf[query->len - 1] == '&') query->buf[query->len - 1] = '\0'; log_warning(_("Searching for updates")); GHashTable *update_hash_tbl = bodhi_query_list(query->buf, release); strbuf_free(query); if (!update_hash_tbl || !g_hash_table_size(update_hash_tbl)) { log_warning(_("No updates for this package found")); /*if (update_hash_tbl) g_hash_table_unref(update_hash_tbl);*/ return 0; } GHashTableIter iter; char *name; struct bodhi *b; struct strbuf *q = strbuf_new(); g_hash_table_iter_init(&iter, update_hash_tbl); while (g_hash_table_iter_next(&iter, (void **) &name, (void **) &b)) { char *installed_pkg_nvr = rpm_get_nvr_by_pkg_name(name); if (installed_pkg_nvr && rpmvercmp(installed_pkg_nvr, b->nvr) >= 0) { log_info("Update %s is older or same as local version %s, skipping", b->nvr, installed_pkg_nvr); free(installed_pkg_nvr); continue; } free(installed_pkg_nvr); strbuf_append_strf(q, " %s", b->nvr); } /*g_hash_table_unref(update_hash_tbl);*/ if (!q->len) { /*strbuf_free(q);*/ log_warning(_("Local version of the package is newer than available updates")); return 0; } /* Message is split into text and command in order to make * translator's job easier */ /* We suggest the command which is most likely to exist on user's system, * and which is familiar to the largest population of users. * There are other tools (pkcon et al) which might be somewhat more * convenient (for example, they might be usable from non-root), but they * might be not present on the system, may evolve or be superseded, * as it did happen to yum. */ map_string_t *settings = new_map_string(); load_abrt_plugin_conf_file("CCpp.conf", settings); const char *value; strbuf_prepend_str(q, " update --enablerepo=fedora --enablerepo=updates --enablerepo=updates-testing"); value = get_map_string_item_or_NULL(settings, "PackageManager"); if (value) strbuf_prepend_str(q, value); else strbuf_prepend_str(q, DEFAULT_PACKAGE_MANAGER); free_map_string(settings); char *msg = xasprintf(_("An update exists which might fix your problem. " "You can install it by running: %s. " "Do you want to continue with reporting the bug?"), q->buf ); /*strbuf_free(q);*/ return ask_yes_no(msg) ? 0 : EXIT_STOP_EVENT_RUN; }
int main(int argc, char *argv[]) { /* I18n */ setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif abrt_init(argv); /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string_template = _( "& [-vsoxtf] [-e]/[-c CURSOR] [-d DIR]/[-D]\n" "\n" "Extract Xorg crash from systemd-journal\n" "\n" "-c and -e options conflicts because both specifies the first read message.\n" "\n" "-e is useful only for -f because the following of journal starts by reading \n" "the entire journal if the last seen possition is not available.\n" "\n" "The last seen position is saved in %s\n" "\n" "Journal filter is required parameter and must be specified either by parameter\n" "-j or in %s conf file.\n" ); char program_usage_string[strlen(program_usage_string_template) + strlen(ABRT_JOURNAL_XORG_WATCH_STATE_FILE) + strlen(XORG_CONF_PATH)]; sprintf(program_usage_string, program_usage_string_template, ABRT_JOURNAL_XORG_WATCH_STATE_FILE, XORG_CONF_PATH); enum { OPT_v = 1 << 0, OPT_s = 1 << 1, OPT_o = 1 << 2, OPT_d = 1 << 3, OPT_D = 1 << 4, OPT_x = 1 << 5, OPT_t = 1 << 6, OPT_c = 1 << 7, OPT_e = 1 << 8, OPT_f = 1 << 9, OPT_a = 1 << 10, OPT_J = 1 << 11, OPT_j = 1 << 12, }; char *cursor = NULL; char *dump_location = NULL; char *journal_dir = NULL; GList *journal_filters = NULL; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_BOOL( 's', NULL, NULL, _("Log to syslog")), OPT_BOOL( 'o', NULL, NULL, _("Print found crashes on standard output")), OPT_STRING('d', NULL, &dump_location, "DIR", _("Create new problem directory in DIR for every crash found")), OPT_BOOL( 'D', NULL, NULL, _("Same as -d DumpLocation, DumpLocation is specified in abrt.conf")), OPT_BOOL( 'x', NULL, NULL, _("Make the problem directory world readable")), OPT_BOOL( 't', NULL, NULL, _("Throttle problem directory creation to 1 per second")), OPT_STRING('c', NULL, &cursor, "CURSOR", _("Start reading systemd-journal from the CURSOR position")), OPT_BOOL( 'e', NULL, NULL, _("Start reading systemd-journal from the end")), OPT_BOOL( 'f', NULL, NULL, _("Follow systemd-journal from the last seen position (if available)")), OPT_BOOL( 'a', NULL, NULL, _("Read journal files from all machines")), OPT_STRING('J', NULL, &journal_dir, "PATH", _("Read all journal files from directory at PATH")), OPT_LIST( 'j', NULL, &journal_filters, "FILTER", _("Journal filter e.g. '_COMM=gdm-x-session' (may be given many times)")), OPT_END() }; unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); export_abrt_envvars(0); msg_prefix = g_progname; if ((opts & OPT_s) || getenv("ABRT_SYSLOG")) { logmode = LOGMODE_JOURNAL; } if ((opts & OPT_c) && (opts & OPT_e)) error_msg_and_die(_("You need to specify either -c CURSOR or -e")); if (opts & OPT_D) { if (opts & OPT_d) show_usage_and_die(program_usage_string, program_options); load_abrt_conf(); dump_location = g_settings_dump_location; g_settings_dump_location = NULL; free_abrt_conf_data(); } int xorg_utils_flags = 0; if ((opts & OPT_x)) xorg_utils_flags |= ABRT_XORG_WORLD_READABLE; if ((opts & OPT_t)) xorg_utils_flags |= ABRT_XORG_THROTTLE_CREATION; if ((opts & OPT_o)) xorg_utils_flags |= ABRT_XORG_PRINT_STDOUT; /* get journal filters */ const char *const env_journal_filter = getenv("ABRT_DUMP_JOURNAL_XORG_DEBUG_FILTER"); bool free_filter_list_data = false; GList *xorg_journal_filter = NULL; if (env_journal_filter != NULL) { xorg_journal_filter = g_list_append(xorg_journal_filter, (gpointer)env_journal_filter); log_debug("Using journal filter from environment variable"); } else if (journal_filters != NULL) { xorg_journal_filter = journal_filters; log_debug("Using journal filter passed by parameter -j"); } else { map_string_t *settings = new_map_string(); log_notice("Loading settings from '%s'", XORG_CONF); load_abrt_plugin_conf_file(XORG_CONF, settings); log_debug("Loaded '%s'", XORG_CONF); const char *conf_journal_filters = get_map_string_item_or_NULL(settings, "JournalFilters"); xorg_journal_filter = parse_list(conf_journal_filters); /* list data will be free by g_list_free_full */ free_filter_list_data = true; free_map_string(settings); if (xorg_journal_filter) log_debug("Using journal filter from conf file %s", XORG_CONF); } if (xorg_journal_filter == NULL) error_msg_and_die(_("Journal filter must be specified either by parameter -j or stored in /etc/abrt/plugins/xorg.conf file")); abrt_journal_t *journal = NULL; if ((opts & OPT_J)) { log_debug("Using journal files from directory '%s'", journal_dir); if (abrt_journal_open_directory(&journal, journal_dir)) error_msg_and_die(_("Cannot initialize systemd-journal in directory '%s'"), journal_dir); } else { if (((opts & OPT_a) ? abrt_journal_new_merged : abrt_journal_new)(&journal)) error_msg_and_die(_("Cannot open systemd-journal")); } if (abrt_journal_set_journal_filter(journal, xorg_journal_filter) < 0) error_msg_and_die(_("Cannot filter systemd-journal to Xorg data only")); /* free filter list */ if (free_filter_list_data) g_list_free_full(xorg_journal_filter, free); else g_list_free(xorg_journal_filter); if ((opts & OPT_e) && abrt_journal_seek_tail(journal) < 0) error_msg_and_die(_("Cannot seek to the end of journal")); if ((opts & OPT_f)) { if (!cursor) abrt_journal_restore_position(journal, ABRT_JOURNAL_XORG_WATCH_STATE_FILE); else if(abrt_journal_set_cursor(journal, cursor)) error_msg_and_die(_("Failed to start watch from cursor '%s'"), cursor); watch_journald(journal, dump_location, xorg_utils_flags); abrt_journal_save_current_position(journal, ABRT_JOURNAL_XORG_WATCH_STATE_FILE); } else { if (cursor && abrt_journal_set_cursor(journal, cursor)) error_msg_and_die(_("Failed to set systemd-journal cursor '%s'"), cursor); /* Compatibility hack, a watch's callback gets the journal already moved * to a next message.*/ abrt_journal_next(journal); GList *crashes = abrt_journal_extract_xorg_crashes(journal); abrt_xorg_process_list_of_crashes(crashes, dump_location, xorg_utils_flags); g_list_free_full(crashes, (GDestroyNotify)xorg_crash_info_free); } abrt_journal_free(journal); return EXIT_SUCCESS; }