static void report_to_bugzilla(const char *dump_dir_name, map_string_h *settings) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) xfunc_die(); /* dd_opendir already emitted error msg */ problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); const char *env; const char *login; const char *password; const char *bugzilla_xmlrpc; const char *bugzilla_url; bool ssl_verify; env = getenv("Bugzilla_Login"); login = env ? env : get_map_string_item_or_empty(settings, "Login"); env = getenv("Bugzilla_Password"); password = env ? env : get_map_string_item_or_empty(settings, "Password"); if (!login[0] || !password[0]) error_msg_and_die(_("Empty login or password, please check your configuration")); env = getenv("Bugzilla_BugzillaURL"); bugzilla_url = env ? env : get_map_string_item_or_empty(settings, "BugzillaURL"); if (!bugzilla_url[0]) bugzilla_url = "https://bugzilla.redhat.com"; bugzilla_xmlrpc = xasprintf("%s"XML_RPC_SUFFIX, bugzilla_url); env = getenv("Bugzilla_SSLVerify"); ssl_verify = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SSLVerify")); const char *component = get_problem_item_content_or_NULL(problem_data, FILENAME_COMPONENT); const char *duphash = get_problem_item_content_or_NULL(problem_data, FILENAME_DUPHASH); if (!duphash) error_msg_and_die(_("Essential file '%s' is missing, can't continue.."), FILENAME_DUPHASH); if (!*duphash) error_msg_and_die(_("Essential file '%s' is empty, can't continue.."), FILENAME_DUPHASH); const char *release = get_problem_item_content_or_NULL(problem_data, FILENAME_OS_RELEASE); if (!release) /* Old dump dir format compat. Remove in abrt-2.1 */ release = get_problem_item_content_or_NULL(problem_data, "release"); struct abrt_xmlrpc *client = abrt_xmlrpc_new_client(bugzilla_xmlrpc, ssl_verify); log(_("Logging into Bugzilla at %s"), bugzilla_url); rhbz_login(client, login, password); log(_("Checking for duplicates")); char *product = NULL; char *version = NULL; parse_release_for_bz(release, &product, &version); free(version); xmlrpc_value *result; if (strcmp(product, "Fedora") == 0) result = rhbz_search_duphash(client, component, product, duphash); else result = rhbz_search_duphash(client, component, NULL, duphash); xmlrpc_value *all_bugs = rhbz_get_member("bugs", result); xmlrpc_DECREF(result); if (!all_bugs) error_msg_and_die(_("Missing mandatory member 'bugs'")); int all_bugs_size = rhbz_array_size(all_bugs); // When someone clones bug it has same duphash, so we can find more than 1. // Need to be checked if component is same. VERB3 log("Bugzilla has %i reports with same duphash '%s'", all_bugs_size, duphash); int bug_id = -1, dependent_bug = -1; struct bug_info *bz = NULL; if (all_bugs_size > 0) { bug_id = rhbz_bug_id(all_bugs); xmlrpc_DECREF(all_bugs); bz = rhbz_bug_info(client, bug_id); if (strcmp(bz->bi_product, product) != 0) { dependent_bug = bug_id; /* found something, but its a different product */ free_bug_info(bz); xmlrpc_value *result = rhbz_search_duphash(client, component, product, duphash); xmlrpc_value *all_bugs = rhbz_get_member("bugs", result); xmlrpc_DECREF(result); all_bugs_size = rhbz_array_size(all_bugs); if (all_bugs_size > 0) { bug_id = rhbz_bug_id(all_bugs); bz = rhbz_bug_info(client, bug_id); } xmlrpc_DECREF(all_bugs); } } free(product); if (all_bugs_size == 0) // Create new bug { log(_("Creating a new bug")); bug_id = rhbz_new_bug(client, problem_data, bug_id); log("Adding attachments to bug %i", bug_id); char bug_id_str[sizeof(int)*3 + 2]; sprintf(bug_id_str, "%i", bug_id); rhbz_attachments(client, bug_id_str, problem_data); log(_("Logging out")); rhbz_logout(client); log("Status: NEW %s/show_bug.cgi?id=%u", bugzilla_url, bug_id); abrt_xmlrpc_free_client(client); return; } // decision based on state log(_("Bug is already reported: %i"), bz->bi_id); if ((strcmp(bz->bi_status, "CLOSED") == 0) && (strcmp(bz->bi_resolution, "DUPLICATE") == 0)) { struct bug_info *origin; origin = rhbz_find_origin_bug_closed_duplicate(client, bz); if (origin) { free_bug_info(bz); bz = origin; } } if (strcmp(bz->bi_status, "CLOSED") != 0) { if ((strcmp(bz->bi_reporter, login) != 0) && (!g_list_find_custom(bz->bi_cc_list, login, (GCompareFunc)g_strcmp0))) { log(_("Add %s to CC list"), login); rhbz_mail_to_cc(client, bz->bi_id, login); } char *dsc = make_description_comment(problem_data); if (dsc) { const char *package = get_problem_item_content_or_NULL(problem_data, FILENAME_PACKAGE); const char *release = get_problem_item_content_or_NULL(problem_data, FILENAME_OS_RELEASE); if (!release) /* Old dump dir format compat. Remove in abrt-2.1 */ release = get_problem_item_content_or_NULL(problem_data, "release"); const char *arch = get_problem_item_content_or_NULL(problem_data, FILENAME_ARCHITECTURE); const char *is_private = get_problem_item_content_or_NULL(problem_data, "is_private"); char *full_dsc = xasprintf("Package: %s\n" "Architecture: %s\n" "OS Release: %s\n" "%s", package, arch, release, dsc); log(_("Adding new comment to bug %d"), bz->bi_id); free(dsc); int is_priv = is_private && string_to_bool(is_private); rhbz_add_comment(client, bz->bi_id, full_dsc, is_priv); free(full_dsc); } } log(_("Logging out")); rhbz_logout(client); log("Status: %s%s%s %s/show_bug.cgi?id=%u", bz->bi_status, bz->bi_resolution ? " " : "", bz->bi_resolution ? bz->bi_resolution : "", bugzilla_url, bz->bi_id); dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (dd) { char *msg = xasprintf("Bugzilla: URL=%s/show_bug.cgi?id=%u", bugzilla_url, bz->bi_id); add_reported_to(dd, msg); free(msg); dd_close(dd); } free_problem_data(problem_data); free_bug_info(bz); abrt_xmlrpc_free_client(client); }
int l1_logreg_train(dmatrix *X, double *b, double lambda, train_opts to, double *initial_x, double *initial_t, double *sol, int *total_ntiter, int *total_pcgiter) { /* problem data */ problem_data_t prob; variables_t vars; dmatrix *matX1; /* matX1 = diag(b)*X_std */ dmatrix *matX2; /* matX2 = X_std.^2 (only for pcg) */ double *ac, *ar; double *avg_x, *std_x; int m, n, ntiter, pcgiter, status; double pobj, dobj, gap; double t, s, maxAnu; double *g, *h, *z, *expz, *expmz; double *x, *v, *w, *u; double *dx, *dv, *dw, *du; double *gv, *gw, *gu, *gx; double *d1, *d2, *Aw; /* pcg variables */ pcg_status_t pcgstat; adata_t adata; mdata_t mdata; double *precond; /* temporary variables */ double *tm1, *tn1, *tn2, *tn3, *tn4, *tx1; /* temporary variables for dense case (cholesky) */ dmatrix *B; /* m x n (or m x n) */ dmatrix *BB; /* n x n (or m x m) */ char format_buf[PRINT_BUF_SIZE]; #if INTERNAL_PLOT dmatrix *internal_plot; dmat_new_dense(&internal_plot, 3, MAX_NT_ITER); memset(internal_plot->val,0,sizeof(double)*3*MAX_NT_ITER); /* row 1: cum_nt_iter, row 2: cum_pcg_iter, row 3: duality gap */ #endif p2func_progress print_progress = NULL; /* * INITIALIZATION */ s = 1.0; pobj = DBL_MAX; dobj = -DBL_MAX; pcgiter = 0; matX1 = NULL; matX2 = NULL; init_pcg_status(&pcgstat); dmat_duplicate(X, &matX1); dmat_copy(X, matX1); m = matX1->m; n = matX1->n; if (to.sflag == TRUE) { /* standardize_data not only standardizes the data, but also multiplies diag(b). */ standardize_data(matX1, b, &avg_x, &std_x, &ac, &ar); } else { /* matX1 = diag(b)*X */ dmat_diagscale(matX1, b, FALSE, NULL, TRUE); avg_x = std_x = ac = ar = NULL; } if (matX1->nz >= 0) /* only for pcg */ { dmat_elemAA(matX1, &matX2); } else { matX2 = NULL; } set_problem_data(&prob, matX1, matX2, ac, ar, b, lambda, avg_x, std_x); create_variables(&vars, m, n); get_variables(&vars, &x, &v, &w, &u, &dx, &dv, &dw, &du, &gx, &gv, &gw, &gu, &g, &h, &z, &expz, &expmz, &d1, &d2, &Aw); allocate_temporaries(m, n, (matX1->nz >= 0), &tm1, &tn1, &tn2, &tn3, &tn4, &tx1, &precond, &B, &BB); if (initial_x == NULL) { dmat_vset(1, 0.0, v); dmat_vset(n, 0.0, w); dmat_vset(n, 1.0, u); dmat_vset(n+n+1, 0, dx); t = min(max(1.0, 1.0 / lambda), 2.0 * n / ABSTOL); } else { dmat_vcopy(n+n+1, initial_x, x); dmat_vset(n+n+1, 0, dx); t = *initial_t; } set_adata(&adata, matX1, ac, ar, b, h, d1, d2); set_mdata(&mdata, m, n, precond); /* select printing function and format according to verbose level and method type (pcg/direct) */ if (to.verbose_level>=2) init_progress((matX1->nz >= 0), to.verbose_level, format_buf, &print_progress); /*** MAIN LOOP ************************************************************/ for (ntiter = 0; ntiter < MAX_NT_ITER; ntiter++) { /* * Sets v as the optimal value of the intercept. */ dmat_yAmpqx(matX1, ac, ar, w, Aw); optimize_intercept(v, z, expz, expmz, tm1, b, Aw, m); /* * Constructs dual feasible point nu. */ fprimes(m, expz, expmz, g, h); /* partially computes the gradient of phi. the rest part of the gradient will be completed while computing the search direction. */ gv[0] = dmat_dot(m, b, g); /* gv = b'*g */ dmat_yAmpqTx(matX1, ac, ar, g, gw); /* gw = A'*g */ dmat_waxpby(m, -1, g, 0, NULL, tm1); /* nu = -g */ maxAnu = dmat_norminf(n, gw); /* max(A'*nu) */ if (maxAnu > lambda) dmat_waxpby(m, lambda / maxAnu, tm1, 0.0, NULL, tm1); /* * Evaluates duality gap. */ pobj = logistic_loss2(m,z,expz,expmz)/m + lambda*dmat_norm1(n,w); dobj = max(nentropy(m, tm1) / m, dobj); gap = pobj - dobj; #if INTERNAL_PLOT internal_plot->val[0*MAX_NT_ITER+ntiter] = (double)ntiter; internal_plot->val[1*MAX_NT_ITER+ntiter] = (double)pcgiter; internal_plot->val[2*MAX_NT_ITER+ntiter] = gap; #endif if (to.verbose_level>=2) { (*print_progress)(format_buf, ntiter, gap, pobj, dobj, s, t, pcgstat.flag, pcgstat.relres, pcgstat.iter); } /* * Quits if gap < tolerance. */ if (gap < to.tolerance ) /***********************************************/ { if (sol != NULL) { /* trim solution */ int i; double lambda_threshold; lambda_threshold = to.ktolerance*lambda; sol[0] = x[0]; for (i = 0; i < n; i++) { sol[i+1] = (fabs(gw[i])>lambda_threshold)? x[i+1] : 0.0; } /* if standardized, sol = coeff/std */ if (to.sflag == TRUE && to.cflag == FALSE) { dmat_elemdivi(n, sol+1, std_x, sol+1); sol[0] -= dmat_dot(n, avg_x, sol+1); } } if (initial_x != NULL) { dmat_vcopy(n+n+1, x, initial_x); *initial_t = t; } if (total_pcgiter) *total_pcgiter = pcgiter; if (total_ntiter ) *total_ntiter = ntiter; /* free memory */ free_variables(&vars); free_temporaries(tm1, tn1, tn2, tn3, tn4, tx1, precond, B, BB); free_problem_data(&prob); #if INTERNAL_PLOT write_mm_matrix("internal_plot",internal_plot,"",TYPE_G); #endif return STATUS_SOLUTION_FOUND; } /********************************************************************/ /* * Updates t */ if (s >= 0.5) { t = max(min(2.0 * n * MU / gap, MU * t), t); } else if (s < 1e-5) { t = 1.1*t; } /* * Computes search direction. */ if (matX1->nz >= 0) { /* pcg */ compute_searchdir_pcg(&prob, &vars, t, s, gap, &pcgstat, &adata, &mdata, precond, tm1, tn1, tx1); pcgiter += pcgstat.iter; } else { /* direct */ if (n > m) { /* direct method for n > m, SMW */ compute_searchdir_chol_fat(&prob, &vars, t, B, BB, tm1, tn1, tn2, tn3, tn4); } else { /* direct method for n <= m */ compute_searchdir_chol_thin(&prob, &vars, t, B, BB, tm1, tn1, tn2); } } /* * Backtracking linesearch & update x = (v,w,u) and z. */ s = backtracking_linesearch(&prob, &vars, t, tm1, tx1); if (s < 0) break; /* BLS error */ } /*** END OF MAIN LOOP *****************************************************/ /* Abnormal termination */ if (s < 0) { status = STATUS_MAX_LS_ITER_EXCEEDED; } else /* if (ntiter == MAX_NT_ITER) */ { status = STATUS_MAX_NT_ITER_EXCEEDED; } if (sol != NULL) { /* trim solution */ int i; double lambda_threshold; lambda_threshold = to.ktolerance*lambda; sol[0] = x[0]; for (i = 0; i < n; i++) { sol[i+1] = (fabs(gw[i])>lambda_threshold)? x[i+1] : 0.0; } /* if standardized, sol = coeff/std */ if (to.sflag == TRUE && to.cflag == FALSE) { dmat_elemdivi(n, sol+1, std_x, sol+1); sol[0] -= dmat_dot(n, avg_x, sol+1); } } if (initial_x != NULL) { dmat_vcopy(n+n+1, x, initial_x); *initial_t = t; } if (total_pcgiter) *total_pcgiter = pcgiter; if (total_ntiter ) *total_ntiter = ntiter; /* free memory */ free_variables(&vars); free_temporaries(tm1, tn1, tn2, tn3, tn4, tx1, precond, B, BB); free_problem_data(&prob); #if INTERNAL_PLOT write_mm_matrix("internal_plot",internal_plot,"",TYPE_G); #endif return status; }
static void create_and_send_email( const char *dump_dir_name, map_string_h *settings) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) exit(1); /* error msg is already logged by dd_opendir */ problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); char* env; env = getenv("Mailx_Subject"); const char *subject = (env ? env : get_map_string_item_or_NULL(settings, "Subject") ? : "[abrt] full crash report"); env = getenv("Mailx_EmailFrom"); const char *email_from = (env ? env : get_map_string_item_or_NULL(settings, "EmailFrom") ? : "user@localhost"); env = getenv("Mailx_EmailTo"); const char *email_to = (env ? env : get_map_string_item_or_NULL(settings, "EmailTo") ? : "root@localhost"); env = getenv("Mailx_SendBinaryData"); bool send_binary_data = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SendBinaryData")); char **args = NULL; unsigned arg_size = 0; args = append_str_to_vector(args, &arg_size, "/bin/mailx"); char *dsc = make_description_mailx(problem_data); if (send_binary_data) { GHashTableIter iter; char *name; struct problem_item *value; g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { if (value->flags & CD_FLAG_BIN) { args = append_str_to_vector(args, &arg_size, "-a"); args = append_str_to_vector(args, &arg_size, value->content); } } } args = append_str_to_vector(args, &arg_size, "-s"); args = append_str_to_vector(args, &arg_size, subject); args = append_str_to_vector(args, &arg_size, "-r"); args = append_str_to_vector(args, &arg_size, email_from); args = append_str_to_vector(args, &arg_size, email_to); log(_("Sending an email...")); exec_and_feed_input(dsc, args); free(dsc); while (*args) free(*args++); args -= arg_size; free(args); free_problem_data(problem_data); dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (dd) { char *msg = xasprintf("email: %s", email_to); add_reported_to(dd, msg); free(msg); dd_close(dd); } log("Email was sent to: %s", email_to); }
int main(int argc, char **argv) { abrt_init(argv); /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( "\b [-v] -d DIR [-o FILE] [-a yes/no] [-r]\n" "\n" "Prints problem information to standard output or FILE" ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, OPT_o = 1 << 2, OPT_a = 1 << 3, OPT_r = 1 << 4, }; /* 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" , _("Dump directory")), OPT_STRING('o', NULL, &output_file , "FILE" , _("Output file")), OPT_STRING('a', NULL, &append , "yes/no", _("Append to, or overwrite FILE")), OPT_BOOL( 'r', NULL, NULL , _("Create reported_to in DIR")), OPT_END() }; unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); export_abrt_envvars(0); if (output_file) { if (string_to_bool(append)) open_mode = "a"; if (!freopen(output_file, open_mode, stdout)) perror_msg_and_die("Can't open '%s'", output_file); } struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; /* error message is already logged */ problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); char *dsc = make_description_logger(problem_data); fputs(dsc, stdout); if (open_mode[0] == 'a') fputs("\nEND:\n\n", stdout); free(dsc); free_problem_data(problem_data); if (output_file) { if (opts & OPT_r) { dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (dd) { char *msg = xasprintf("file: %s", output_file); add_reported_to(dd, msg); free(msg); dd_close(dd); } } const char *format = (open_mode[0] == 'a' ? _("The report was appended to %s") : _("The report was stored to %s")); log(format, output_file); } return 0; }