~ubuntu-branches/ubuntu/utopic/upstart-app-launch/utopic-proposed

« back to all changes in this revision

Viewing changes to click-exec.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Ted Gould, Ubuntu daily release
  • Date: 2014-02-06 16:54:55 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20140206165455-ybv8tumonbcw4ag5
Tags: 0.3+14.04.20140206-0ubuntu1
[ Ted Gould ]
* Basic merge and review requirements.
* On error print the exec line
* Make the last environment variable set synchronous to make Upstart
  respond that it received it. (LP: #1275017)

[ Ubuntu daily release ]
* New rebuild forced

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *     Ted Gould <ted.gould@canonical.com>
18
18
 */
19
19
 
20
 
#include <glib.h>
 
20
#include <gio/gio.h>
21
21
#include "helpers.h"
22
22
#include "click-exec-trace.h"
23
23
 
55
55
 
56
56
        tracepoint(upstart_app_launch, click_start);
57
57
 
 
58
        /* Ensure we keep one connection open to the bus for the entire
 
59
           script even though different people need it throughout */
 
60
        GError * error = NULL;
 
61
        GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
 
62
        if (error != NULL) {
 
63
                g_error("Unable to get session bus: %s", error->message);
 
64
                g_error_free(error);
 
65
                return 1;
 
66
        }
 
67
 
58
68
        handshake_t * handshake = starting_handshake_start(app_id);
59
69
        if (handshake == NULL) {
60
70
                g_warning("Unable to setup starting handshake");
62
72
 
63
73
        tracepoint(upstart_app_launch, click_starting_sent);
64
74
 
65
 
        GError * error = NULL;
66
75
        gchar * package = NULL;
67
76
        /* 'Parse' the App ID */
68
77
        if (!app_id_to_triplet(app_id, &package, NULL, NULL)) {
101
110
        }
102
111
 
103
112
        g_debug("Setting 'APP_DIR' to '%s'", output);
104
 
        set_upstart_variable("APP_DIR", output);
 
113
        set_upstart_variable("APP_DIR", output, FALSE);
105
114
 
106
115
        set_confined_envvars(package, output);
107
116
 
121
130
 
122
131
        GKeyFile * keyfile = g_key_file_new();
123
132
 
 
133
        set_upstart_variable("APP_DESKTOP_FILE_PATH", desktopfile, FALSE);
124
134
        g_key_file_load_from_file(keyfile, desktopfile, 0, &error);
125
135
        if (error != NULL) {
126
136
                g_warning("Unable to load desktop file '%s': %s", desktopfile, error->message);
127
137
                g_error_free(error);
 
138
                g_key_file_free(keyfile);
 
139
                g_free(desktopfile);
128
140
                return 1;
129
141
        }
130
142
 
137
149
 
138
150
        tracepoint(upstart_app_launch, click_read_desktop);
139
151
 
140
 
        g_debug("Setting 'APP_EXEC' to '%s'", exec);
141
 
        set_upstart_variable("APP_EXEC", exec);
142
 
 
143
 
        g_free(exec);
144
 
        g_key_file_unref(keyfile);
145
 
        g_free(desktopfile);
146
 
 
147
152
        /* TODO: This is for Surface Flinger, when we drop support we can drop this */
148
153
        gchar * userdesktopfile = g_strdup_printf("%s.desktop", app_id);
149
154
        gchar * userdesktoppath = g_build_filename(g_get_home_dir(), ".local", "share", "applications", userdesktopfile, NULL);
150
 
        set_upstart_variable("APP_DESKTOP_FILE", userdesktoppath);
 
155
        set_upstart_variable("APP_DESKTOP_FILE", userdesktoppath, FALSE);
151
156
        g_free(userdesktopfile);
152
157
        g_free(userdesktoppath);
153
158
 
 
159
        g_debug("Setting 'APP_EXEC' to '%s'", exec);
 
160
        /* NOTE: This should be the last upstart variable set as it is sync
 
161
           so it will wait for a reply from Upstart implying that Upstart
 
162
           has seen all the other variable requests we made */
 
163
        set_upstart_variable("APP_EXEC", exec, TRUE);
 
164
 
 
165
        g_free(exec);
 
166
        g_key_file_unref(keyfile);
 
167
        g_free(desktopfile);
 
168
 
154
169
        tracepoint(upstart_app_launch, click_handshake_wait);
155
170
 
156
171
        starting_handshake_wait(handshake);
157
172
 
158
173
        tracepoint(upstart_app_launch, click_handshake_complete);
159
174
 
 
175
        g_object_unref(bus);
 
176
 
160
177
        return 0;
161
178
}