~ted/ubuntu-app-launch/snap-icon-unbreak

« back to all changes in this revision

Viewing changes to application-failed.c

Updated to failure-is-an-option

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Copyright 2013 Canonical Ltd.
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify it
 
6
 * under the terms of the GNU General Public License version 3, as published
 
7
 * by the Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
 * PURPOSE.  See the GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authors:
 
18
 *     Ted Gould <ted.gould@canonical.com>
 
19
 */
 
20
 
 
21
#include <gio/gio.h>
 
22
 
 
23
int
 
24
main (int argc, char * argv[])
 
25
{
 
26
        const gchar * job = g_getenv("JOB");
 
27
        g_return_val_if_fail(job != NULL, -1);
 
28
 
 
29
        const gchar * instance = g_getenv("INSTANCE");
 
30
        g_return_val_if_fail(instance != NULL, -1);
 
31
 
 
32
        gboolean crashed = FALSE;
 
33
        if (g_getenv("EXIT_STATUS") != NULL || g_getenv("EXIT_SIGNAL") != NULL) {
 
34
                crashed = TRUE;
 
35
        }
 
36
 
 
37
        gchar * appid = g_strdup(instance);
 
38
        if (g_strcmp0(job, "application-legacy") == 0) {
 
39
                gchar * lasthyphenstanding = g_strrstr(appid, "-");
 
40
                if (lasthyphenstanding != NULL) {
 
41
                        lasthyphenstanding[0] = '\0';
 
42
                } else {
 
43
                        g_warning("Legacy job instance '%s' is missing a hyphen", appid);
 
44
                }
 
45
        }
 
46
 
 
47
        GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
 
48
        g_return_val_if_fail(bus != NULL, -1);
 
49
 
 
50
        GError * error = NULL;
 
51
        g_dbus_connection_emit_signal(bus,
 
52
                NULL, /* destination */
 
53
                "/", /* path */
 
54
                "com.canonical.UpstartAppLaunch",
 
55
                "ApplicationFailed",
 
56
                g_variant_new("(ss)", appid, crashed ? "crash" : "start-failure"),
 
57
                &error);
 
58
 
 
59
        g_debug("Emitting failed event '%s' for app '%s'", crashed ? "crash" : "start-failure", appid);
 
60
 
 
61
        if (error != NULL) {
 
62
                g_warning("Unable to emit signal: %s", error->message);
 
63
                g_error_free(error);
 
64
                return -1;
 
65
        }
 
66
 
 
67
        g_dbus_connection_flush_sync(bus, NULL, NULL);
 
68
        g_object_unref(bus);
 
69
        g_free(appid);
 
70
 
 
71
        return 0;
 
72
}