~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to src/system-crash.c

  • Committer: Balint Reczey
  • Date: 2020-06-11 18:46:02 UTC
  • Revision ID: balint.reczey@canonical.com-20200611184602-2rv1zan3xu723x2u
Moved to git at https://git.launchpad.net/update-notifier

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef HAVE_CONFIG_H
2
 
#include "config.h"
3
 
#endif
4
 
#include <glib.h>
5
 
#include <glib-object.h>
6
 
#include <gtk/gtk.h>
7
 
 
8
 
#include <sys/types.h>
9
 
#include <sys/stat.h>
10
 
#include <unistd.h>
11
 
#include <glib/gi18n.h>
12
 
 
13
 
#include "update-notifier.h"
14
 
#include "system-crash.h"
15
 
 
16
 
static gboolean
17
 
ask_invoke_apport_with_pkexec(void)
18
 
{
19
 
   GtkDialog *dialog;
20
 
   gchar *msg = _("System program problem detected");
21
 
   gchar *descr = _("Do you want to report the problem "
22
 
                    "now?");
23
 
   dialog = (GtkDialog*)gtk_message_dialog_new (NULL,
24
 
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
25
 
                                    GTK_MESSAGE_QUESTION,
26
 
                                    GTK_BUTTONS_NONE,
27
 
                                    "%s", msg);
28
 
   gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
29
 
                                            "%s", descr);
30
 
   gtk_dialog_add_button(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
31
 
   gtk_dialog_add_button(dialog, _("Report problem…"), GTK_RESPONSE_ACCEPT);
32
 
   int res = gtk_dialog_run(dialog);
33
 
   gtk_widget_destroy(GTK_WIDGET(dialog));
34
 
   if (res == GTK_RESPONSE_ACCEPT)
35
 
      return TRUE;
36
 
   return FALSE;
37
 
}
38
 
 
39
 
void
40
 
invoke_with_pkexec(const gchar *cmd)
41
 
{
42
 
        g_debug("invoke_with_pkexec ()");
43
 
        gchar *argv[3];
44
 
        argv[0] = "/usr/bin/pkexec";
45
 
        argv[1] = (gchar*)cmd;
46
 
        argv[2] = NULL;
47
 
        g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, NULL, NULL);
48
 
}
49
 
 
50
 
int
51
 
main (int argc, char **argv)
52
 
{
53
 
   bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
54
 
   bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
55
 
   textdomain(GETTEXT_PACKAGE);
56
 
 
57
 
   gtk_init (&argc, &argv);
58
 
   // be nice and always ask first before firing up pkexec
59
 
   if (ask_invoke_apport_with_pkexec()) {
60
 
      invoke_with_pkexec(CRASHREPORT_REPORT_APP);
61
 
   } else {
62
 
      return g_spawn_command_line_async(CRASHREPORT_REPORT_APP, NULL);
63
 
   }
64
 
   return 0;
65
 
}