~indicator-applet-developers/ubuntu-app-launch/trunk.rtm-14.09

« back to all changes in this revision

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

  • Committer: CI bot
  • Author(s): Ted Gould
  • Date: 2014-09-15 19:40:02 UTC
  • mfrom: (156.3.19 prestart-reshuffle)
  • Revision ID: ps-jenkins@lists.canonical.com-20140915194002-pgvjz98lhxruxoxl
Reshuffle the pre-start jobs to save precious milliseconds 
Approved by: Charles Kerr, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <gio/gio.h>
25
25
 
26
26
#include "helpers.h"
27
 
#include "desktop-exec-trace.h"
 
27
#include "ubuntu-app-launch-trace.h"
28
28
#include "recoverable-problem.h"
29
29
#include "ual-tracepoint.h"
30
30
 
31
 
const gchar * app_id = NULL;
32
 
 
33
31
/* Reports an error on the caller of UAL so that we can track
34
32
   who is trying to launch bad AppIDs, and then fix their bug
35
33
   so that we get better reporting upstream. */
36
34
void
37
 
report_error_on_caller (void) {
 
35
report_error_on_caller (const gchar * app_id) {
38
36
        g_warning("Unable to find keyfile for application '%s'", app_id);
39
37
 
40
38
        const gchar * props[3] = {
43
41
        };
44
42
        props[1] = app_id;
45
43
 
46
 
        GPid pid = 0;
47
 
        const gchar * launcher_pid = g_getenv("APP_LAUNCHER_PID");
48
 
        if (launcher_pid != NULL) {
49
 
                pid = atoi(launcher_pid);
50
 
        }
 
44
        GPid pid = getpid();
51
45
 
52
46
        /* Checking to see if we're using the command line tool to create
53
47
           the appid. Chances are in that case it's a user error, and we
54
48
           don't need to automatically record it, the user mistyped. */
55
49
        gboolean debugtool = FALSE;
56
50
        if (pid != 0) {
57
 
                gchar * cmdpath = g_strdup_printf("/proc/%d/cmdline", pid);
 
51
                const gchar * cmdpath = "/proc/self/cmdline";
58
52
                gchar * cmdline = NULL;
59
53
 
60
54
                if (g_file_get_contents(cmdpath, &cmdline, NULL, NULL)) {
67
61
                        /* The caller has already exited, probably a debug tool */
68
62
                        debugtool = TRUE;
69
63
                }
70
 
 
71
 
                g_free(cmdpath);
72
64
        }
73
65
 
74
66
        if (!debugtool) {
78
70
        }
79
71
}
80
72
 
81
 
int
82
 
main (int argc, char * argv[])
 
73
gboolean
 
74
desktop_task_setup (GDBusConnection * bus, const gchar * app_id, EnvHandle * handle)
83
75
{
84
 
        if (argc != 1) {
85
 
                g_error("Should be called as: %s", argv[0]);
86
 
                return 1;
87
 
        }
88
 
 
89
 
        app_id = g_getenv("APP_ID");
90
 
 
91
76
        if (app_id == NULL) {
92
77
                g_error("No APP_ID environment variable defined");
93
 
                return 1;
 
78
                return FALSE;
94
79
        }
95
80
 
96
81
        ual_tracepoint(desktop_start, app_id);
97
82
 
98
 
        /* Ensure we keep one connection open to the bus for the entire
99
 
           script even though different people need it throughout */
100
 
        GError * error = NULL;
101
 
        GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
102
 
        if (error != NULL) {
103
 
                g_error("Unable to get session bus: %s", error->message);
104
 
                g_error_free(error);
105
 
                return 1;
106
 
        }
107
 
 
108
83
        handshake_t * handshake = starting_handshake_start(app_id);
109
84
        if (handshake == NULL) {
110
85
                g_warning("Unable to setup starting handshake");
116
91
        GKeyFile * keyfile = keyfile_for_appid(app_id, &desktopfilename);
117
92
 
118
93
        if (keyfile == NULL) {
119
 
                report_error_on_caller();
120
 
                return 1;
 
94
                report_error_on_caller(app_id);
 
95
                return FALSE;
121
96
        }
122
97
 
123
98
        ual_tracepoint(desktop_found, app_id);
124
99
 
125
 
        EnvHandle * handle = env_handle_start();
126
 
 
127
100
        /* Desktop file name so that libs can get other info from it */
128
101
        if (desktopfilename != NULL) {
129
102
                env_handle_add(handle, "APP_DESKTOP_FILE_PATH", desktopfilename);
154
127
 
155
128
        g_key_file_free(keyfile);
156
129
 
157
 
        ual_tracepoint(desktop_send_env_vars, app_id);
158
 
 
159
 
        /* Sync the env vars with Upstart */
160
 
        env_handle_finish(handle);
161
 
        handle = NULL; /* make errors not love */
162
 
 
163
130
        ual_tracepoint(handshake_wait, app_id);
164
131
 
165
132
        starting_handshake_wait(handshake);
166
133
 
167
134
        ual_tracepoint(handshake_complete, app_id);
168
135
 
169
 
        g_object_unref(bus);
170
 
 
171
 
        return 0;
 
136
        return TRUE;
172
137
}