43
main (int argc, char * argv[])
44
click_task_setup (GDBusConnection * bus, const gchar * app_id, EnvHandle * handle)
45
if (argc != 1 && argc != 3) {
46
g_error("Should be called as: %s", argv[0]);
50
const gchar * app_id = g_getenv("APP_ID");
53
g_error("No APP ID defined");
57
tracepoint(upstart_app_launch, click_start);
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);
50
ual_tracepoint(click_start, app_id);
61
52
GError * error = NULL;
62
GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
64
g_error("Unable to get session bus: %s", error->message);
69
54
handshake_t * handshake = starting_handshake_start(app_id);
70
55
if (handshake == NULL) {
71
56
g_warning("Unable to setup starting handshake");
74
tracepoint(upstart_app_launch, click_starting_sent);
59
ual_tracepoint(click_starting_sent, app_id);
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);
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);
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);
107
92
g_object_unref(user);
108
93
g_object_unref(db);
111
96
g_object_unref(user);
112
97
g_object_unref(db);
114
tracepoint(upstart_app_launch, click_found_pkgdir);
99
ual_tracepoint(click_found_pkgdir, app_id);
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);
123
108
g_debug("Setting 'APP_DIR' to '%s'", pkgdir);
124
set_upstart_variable("APP_DIR", pkgdir, FALSE);
126
set_confined_envvars(package, pkgdir);
128
tracepoint(upstart_app_launch, click_configured_env);
109
env_handle_add(handle, "APP_DIR", pkgdir);
111
set_confined_envvars(handle, package, pkgdir);
113
ual_tracepoint(click_configured_env, app_id);
130
115
gchar * desktopfile = manifest_to_desktop(pkgdir, app_id);
135
120
if (desktopfile == NULL) {
136
121
g_warning("Desktop file unable to be found");
140
tracepoint(upstart_app_launch, click_read_manifest);
125
ual_tracepoint(click_read_manifest, app_id);
142
127
GKeyFile * keyfile = g_key_file_new();
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);
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");
158
set_upstart_variable("APP_XMIR_ENABLE", "0", FALSE);
143
env_handle_add(handle, "APP_XMIR_ENABLE", "0");
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) {
169
tracepoint(upstart_app_launch, click_read_desktop);
154
ual_tracepoint(click_read_desktop, app_id);
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);
178
160
g_key_file_unref(keyfile);
179
161
g_free(desktopfile);
181
tracepoint(upstart_app_launch, click_handshake_wait);
163
ual_tracepoint(handshake_wait, app_id);
183
165
starting_handshake_wait(handshake);
185
tracepoint(upstart_app_launch, click_handshake_complete);
167
ual_tracepoint(handshake_complete, app_id);