summaryrefslogtreecommitdiffstats
path: root/src/lib/report.c
blob: a3ba6e9619fc233df186bc41821b23a3efa76dff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
    Copyright (C) 2011  ABRT Team
    Copyright (C) 2011  RedHat inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "abrtlib.h"

int analyze_and_report_dir(const char* dirname)
{
    /*
    if is isatty -> run cli reporter
    */
    pid_t pid = vfork();
    if (pid == 0)
    {
        /* Some callers set SIGCHLD to SIG_IGN.
         * However, reporting spawns chils processes.
         * Suppressing chil death notification terribly confuses some of them.
         * Just in case, undo it.
         * Note that we do it in the child, so the parent is never affected.
         */
        signal(SIGCHLD, SIG_DFL); // applet still set it to SIG_IGN
        VERB1 log("Executing: %s %s", "bug-reporting-wizard", dirname);
        execl(BIN_DIR"/bug-reporting-wizard", "bug-reporting-wizard", "--", dirname, NULL);
        // note the -o in options which means --report-only
        /* Did not find abrt-gui in installation directory. Oh well */
        /* Trying to find it in PATH */
        execlp("bug-reporting-wizard", "bug-reporting-wizard", "--", dirname, NULL);
        perror_msg_and_die("Can't execute %s", "bug-reporting-wizard");
    }
    return 0;
}

/* analyzes AND reports a problem saved on disk
 * - takes user through all the steps in reporting wizard
 */
int analyze_and_report(problem_data_t *pd)
{
    struct dump_dir *dd = create_dump_dir_from_problem_data(pd, "/tmp"/* /var/tmp ?? */);
    if (!dd)
        return -1;
    char *dir_name = strdup(dd->dd_dirname);
    dd_close(dd);
    VERB2 log("Temp problem dir: '%s'\n", dir_name);
    analyze_and_report_dir(dir_name);
    free(dir_name);
    return 0;
}

/* reports a problem saved on disk
 * - shows only reporter selector and progress
*/
int report_dir(const char* dirname)
{
    pid_t pid = vfork();
    if (pid == 0)
    {
        /* Some callers set SIGCHLD to SIG_IGN.
         * However, reporting spawns chils processes.
         * Suppressing chil death notification terribly confuses some of them.
         * Just in case, undo it.
         * Note that we do it in the child, so the parent is never affected.
         */
        signal(SIGCHLD, SIG_DFL); // applet still set it to SIG_IGN
        VERB1 log("Executing: %s %s", "bug-reporting-wizard", dirname);
        execl(BIN_DIR"/bug-reporting-wizard", "bug-reporting-wizard",
                  "-o", "--", dirname, NULL);
        // note the -o in options which means --report-only
        /* Did not find abrt-gui in installation directory. Oh well */
        /* Trying to find it in PATH */
        execlp("bug-reporting-wizard", "bug-reporting-wizard",
                "-o", "--", dirname, NULL);
        perror_msg_and_die("Can't execute %s", "bug-reporting-wizard");
    }
    return 0;
}

int report(problem_data_t *pd)
{
    struct dump_dir *dd = create_dump_dir_from_problem_data(pd, "/tmp"/* /var/tmp ?? */);
    if (!dd)
        return -1;
    char *dir_name = xstrdup(dd->dd_dirname);
    dd_close(dd);
    VERB2 log("Temp problem dir: '%s'\n", dir_name);
    report_dir(dir_name);
    free(dir_name);

    return 0;
}