~mterry/ubuntu-app-launch/fix-ftbfs

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/click-exec.c

Merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <gio/gio.h>
21
21
#include <click.h>
22
22
#include "helpers.h"
23
 
#include "click-exec-trace.h"
 
23
#include "ubuntu-app-launch-trace.h"
 
24
#include "ual-tracepoint.h"
24
25
 
25
26
/*
26
27
 
39
40
 
40
41
*/
41
42
 
42
 
int
43
 
main (int argc, char * argv[])
 
43
gboolean
 
44
click_task_setup (GDBusConnection * bus, const gchar * app_id, EnvHandle * handle)
44
45
{
45
 
        if (argc != 1 && argc != 3) {
46
 
                g_error("Should be called as: %s", argv[0]);
47
 
                return 1;
48
 
        }
49
 
 
50
 
        const gchar * app_id = g_getenv("APP_ID");
51
 
 
52
 
        if (app_id == NULL) {
53
 
                g_error("No APP ID defined");
54
 
                return 1;
55
 
        }
56
 
 
57
 
        tracepoint(upstart_app_launch, click_start);
58
 
 
59
 
        /* Ensure we keep one connection open to the bus for the entire
60
 
           script even though different people need it throughout */
 
46
        g_return_val_if_fail(bus != NULL, FALSE);
 
47
        g_return_val_if_fail(app_id != NULL, FALSE);
 
48
        g_return_val_if_fail(handle != NULL, FALSE);
 
49
 
 
50
        ual_tracepoint(click_start, app_id);
 
51
 
61
52
        GError * error = NULL;
62
 
        GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
63
 
        if (error != NULL) {
64
 
                g_error("Unable to get session bus: %s", error->message);
65
 
                g_error_free(error);
66
 
                return 1;
67
 
        }
68
53
 
69
54
        handshake_t * handshake = starting_handshake_start(app_id);
70
55
        if (handshake == NULL) {
71
56
                g_warning("Unable to setup starting handshake");
72
57
        }
73
58
 
74
 
        tracepoint(upstart_app_launch, click_starting_sent);
 
59
        ual_tracepoint(click_starting_sent, app_id);
75
60
 
76
61
        gchar * package = NULL;
77
62
        /* 'Parse' the App ID */
78
63
        if (!app_id_to_triplet(app_id, &package, NULL, NULL)) {
79
64
                g_warning("Unable to parse App ID: '%s'", app_id);
80
 
                return 1;
 
65
                return FALSE;
81
66
        }
82
67
 
83
68
        /* Check click to find out where the files are */
88
73
                g_warning("Unable to read Click database: %s", error->message);
89
74
                g_error_free(error);
90
75
                g_free(package);
91
 
                return 1;
 
76
                return FALSE;
92
77
        }
93
78
        /* If TEST_CLICK_USER is unset, this uses the current user name. */
94
79
        ClickUser * user = click_user_new_for_user(db, g_getenv("TEST_CLICK_USER"), &error);
97
82
                g_error_free(error);
98
83
                g_free(package);
99
84
                g_object_unref(db);
100
 
                return 1;
 
85
                return FALSE;
101
86
        }
102
87
        gchar * pkgdir = click_user_get_path(user, package, &error);
103
88
        if (error != NULL) {
106
91
                g_free(package);
107
92
                g_object_unref(user);
108
93
                g_object_unref(db);
109
 
                return 1;
 
94
                return FALSE;
110
95
        }
111
96
        g_object_unref(user);
112
97
        g_object_unref(db);
113
98
 
114
 
        tracepoint(upstart_app_launch, click_found_pkgdir);
 
99
        ual_tracepoint(click_found_pkgdir, app_id);
115
100
 
116
101
        if (!g_file_test(pkgdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
117
102
                g_warning("Application directory '%s' doesn't exist", pkgdir);
118
103
                g_free(pkgdir);
119
104
                g_free(package);
120
 
                return 1;
 
105
                return FALSE;
121
106
        }
122
107
 
123
108
        g_debug("Setting 'APP_DIR' to '%s'", pkgdir);
124
 
        set_upstart_variable("APP_DIR", pkgdir, FALSE);
125
 
 
126
 
        set_confined_envvars(package, pkgdir);
127
 
 
128
 
        tracepoint(upstart_app_launch, click_configured_env);
 
109
        env_handle_add(handle, "APP_DIR", pkgdir);
 
110
 
 
111
        set_confined_envvars(handle, package, pkgdir);
 
112
 
 
113
        ual_tracepoint(click_configured_env, app_id);
129
114
 
130
115
        gchar * desktopfile = manifest_to_desktop(pkgdir, app_id);
131
116
 
134
119
 
135
120
        if (desktopfile == NULL) {
136
121
                g_warning("Desktop file unable to be found");
137
 
                return 1;
 
122
                return FALSE;
138
123
        }
139
124
 
140
 
        tracepoint(upstart_app_launch, click_read_manifest);
 
125
        ual_tracepoint(click_read_manifest, app_id);
141
126
 
142
127
        GKeyFile * keyfile = g_key_file_new();
143
128
 
144
 
        set_upstart_variable("APP_DESKTOP_FILE_PATH", desktopfile, FALSE);
 
129
        env_handle_add(handle, "APP_DESKTOP_FILE_PATH", desktopfile);
145
130
        g_key_file_load_from_file(keyfile, desktopfile, 0, &error);
146
131
        if (error != NULL) {
147
132
                g_warning("Unable to load desktop file '%s': %s", desktopfile, error->message);
148
133
                g_error_free(error);
149
134
                g_key_file_free(keyfile);
150
135
                g_free(desktopfile);
151
 
                return 1;
 
136
                return FALSE;
152
137
        }
153
138
 
154
139
        if (g_key_file_has_key(keyfile, "Desktop Entry", "X-Ubuntu-XMir-Enable", NULL)) {
155
140
                if (g_key_file_get_boolean(keyfile, "Desktop Entry", "X-Ubuntu-XMir-Enable", NULL)) {
156
 
                        set_upstart_variable("APP_XMIR_ENABLE", "1", FALSE);
 
141
                        env_handle_add(handle, "APP_XMIR_ENABLE", "1");
157
142
                } else {
158
 
                        set_upstart_variable("APP_XMIR_ENABLE", "0", FALSE);
 
143
                        env_handle_add(handle, "APP_XMIR_ENABLE", "0");
159
144
                }
160
145
        }
161
146
 
163
148
           http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables */
164
149
        gchar * exec = desktop_to_exec(keyfile, desktopfile);
165
150
        if (exec == NULL) {
166
 
                return 1;
 
151
                return FALSE;
167
152
        }
168
153
 
169
 
        tracepoint(upstart_app_launch, click_read_desktop);
 
154
        ual_tracepoint(click_read_desktop, app_id);
170
155
 
171
156
        g_debug("Setting 'APP_EXEC' to '%s'", exec);
172
 
        /* NOTE: This should be the last upstart variable set as it is sync
173
 
           so it will wait for a reply from Upstart implying that Upstart
174
 
           has seen all the other variable requests we made */
175
 
        set_upstart_variable("APP_EXEC", exec, TRUE);
 
157
        env_handle_add(handle, "APP_EXEC", exec);
176
158
 
177
159
        g_free(exec);
178
160
        g_key_file_unref(keyfile);
179
161
        g_free(desktopfile);
180
162
 
181
 
        tracepoint(upstart_app_launch, click_handshake_wait);
 
163
        ual_tracepoint(handshake_wait, app_id);
182
164
 
183
165
        starting_handshake_wait(handshake);
184
166
 
185
 
        tracepoint(upstart_app_launch, click_handshake_complete);
186
 
 
187
 
        g_object_unref(bus);
188
 
 
189
 
        return 0;
 
167
        ual_tracepoint(handshake_complete, app_id);
 
168
 
 
169
        return TRUE;
190
170
}