Merge lp:~ted/ubuntu-app-launch/bad-appid-recoverable-error into lp:ubuntu-app-launch/14.04

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 151
Merged at revision: 147
Proposed branch: lp:~ted/ubuntu-app-launch/bad-appid-recoverable-error
Merge into: lp:ubuntu-app-launch/14.04
Diff against target: 286 lines (+235/-2)
5 files modified
CMakeLists.txt (+1/-1)
desktop-exec.c (+42/-1)
libupstart-app-launch/upstart-app-launch.c (+1/-0)
recoverable-problem.c (+165/-0)
recoverable-problem.h (+26/-0)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/bad-appid-recoverable-error
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+216192@code.launchpad.net

Commit message

More elegant handling of bad application id errors

Description of the change

We get various bugs on this, which is good that they're being reported, but there's a bit of noise. Trying to filter out that noise and be a bit more sophisticated on the reporting.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

* cmdline is leaked.

* Not a blocker for this merge, but as a general comment: we really need to move recoverable-problem.c into some shared location

Revision history for this message
Charles Kerr (charlesk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-03-12 00:28:05 +0000
+++ CMakeLists.txt 2014-04-16 18:51:37 +0000
@@ -83,7 +83,7 @@
83####################83####################
8484
85add_lttng_gen_tp(NAME desktop-exec-trace)85add_lttng_gen_tp(NAME desktop-exec-trace)
86add_executable(desktop-exec desktop-exec.c desktop-exec-trace.c)86add_executable(desktop-exec desktop-exec.c desktop-exec-trace.c recoverable-problem.c)
87set_target_properties(desktop-exec PROPERTIES OUTPUT_NAME "desktop-exec")87set_target_properties(desktop-exec PROPERTIES OUTPUT_NAME "desktop-exec")
88target_link_libraries(desktop-exec helpers ${LTTNG_LIBRARIES})88target_link_libraries(desktop-exec helpers ${LTTNG_LIBRARIES})
89install(TARGETS desktop-exec RUNTIME DESTINATION "${pkglibexecdir}")89install(TARGETS desktop-exec RUNTIME DESTINATION "${pkglibexecdir}")
9090
=== modified file 'desktop-exec.c'
--- desktop-exec.c 2014-02-07 14:56:27 +0000
+++ desktop-exec.c 2014-04-16 18:51:37 +0000
@@ -25,6 +25,7 @@
2525
26#include "helpers.h"26#include "helpers.h"
27#include "desktop-exec-trace.h"27#include "desktop-exec-trace.h"
28#include "recoverable-problem.h"
2829
29int30int
30main (int argc, char * argv[])31main (int argc, char * argv[])
@@ -65,7 +66,47 @@
65 GKeyFile * keyfile = keyfile_for_appid(app_id, &desktopfilename);66 GKeyFile * keyfile = keyfile_for_appid(app_id, &desktopfilename);
6667
67 if (keyfile == NULL) {68 if (keyfile == NULL) {
68 g_error("Unable to find keyfile for application '%s'", app_id);69 g_warning("Unable to find keyfile for application '%s'", app_id);
70
71 const gchar * props[3] = {
72 "AppId", NULL,
73 NULL
74 };
75 props[1] = app_id;
76
77 GPid pid = 0;
78 const gchar * launcher_pid = g_getenv("APP_LAUNCHER_PID");
79 if (launcher_pid != NULL) {
80 pid = atoi(launcher_pid);
81 }
82
83 /* Checking to see if we're using the command line tool to create
84 the appid. Chances are in that case it's a user error, and we
85 don't need to automatically record it, the user mistyped. */
86 gboolean debugtool = FALSE;
87 if (pid != 0) {
88 gchar * cmdpath = g_strdup_printf("/proc/%d/cmdline", pid);
89 gchar * cmdline = NULL;
90
91 if (g_file_get_contents(cmdpath, &cmdline, NULL, NULL)) {
92 if (g_strstr_len(cmdline, -1, "upstart-app-launch") != NULL) {
93 debugtool = TRUE;
94 }
95
96 g_free(cmdline);
97 } else {
98 /* The caller has already exited, probably a debug tool */
99 debugtool = TRUE;
100 }
101
102 g_free(cmdpath);
103 }
104
105 if (!debugtool) {
106 report_recoverable_problem("upstart-app-launch-invalid-appid", pid, TRUE, props);
107 } else {
108 g_debug("Suppressing appid recoverable error for debug tool");
109 }
69 return 1;110 return 1;
70 }111 }
71112
72113
=== modified file 'libupstart-app-launch/upstart-app-launch.c'
--- libupstart-app-launch/upstart-app-launch.c 2014-03-21 17:56:15 +0000
+++ libupstart-app-launch/upstart-app-launch.c 2014-04-16 18:51:37 +0000
@@ -228,6 +228,7 @@
228 g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY);228 g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY);
229229
230 g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_ID=%s", appid)));230 g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_ID=%s", appid)));
231 g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_LAUNCHER_PID=%d", getpid())));
231232
232 if (uris != NULL) {233 if (uris != NULL) {
233 gchar * urisjoin = app_uris_string(uris);234 gchar * urisjoin = app_uris_string(uris);
234235
=== added file 'recoverable-problem.c'
--- recoverable-problem.c 1970-01-01 00:00:00 +0000
+++ recoverable-problem.c 2014-04-16 18:51:37 +0000
@@ -0,0 +1,165 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Ted Gould <ted.gould@canonical.com>
18 */
19
20#include "recoverable-problem.h"
21#include <glib/gstdio.h>
22#include <string.h>
23#include <errno.h>
24
25/* Helpers to ensure we write nicely */
26static void
27write_string (int fd,
28 const gchar *string)
29{
30 int res;
31 do
32 res = write (fd, string, strlen (string));
33 while (G_UNLIKELY (res == -1 && errno == EINTR));
34}
35
36/* Make NULLs fast and fun! */
37static void
38write_null (int fd)
39{
40 int res;
41 do
42 res = write (fd, "", 1);
43 while (G_UNLIKELY (res == -1 && errno == EINTR));
44}
45
46/* Child watcher */
47static gboolean
48apport_child_watch (GPid pid, gint status, gpointer user_data)
49{
50 g_main_loop_quit((GMainLoop *)user_data);
51 return FALSE;
52}
53
54static gboolean
55apport_child_timeout (gpointer user_data)
56{
57 g_warning("Recoverable Error Reporter Timeout");
58 g_main_loop_quit((GMainLoop *)user_data);
59 return FALSE;
60}
61
62/* Code to report an error */
63void
64report_recoverable_problem (const gchar * signature, GPid report_pid, gboolean wait, const gchar * additional_properties[])
65{
66 GError * error = NULL;
67 gint error_stdin = 0;
68 GPid pid = 0;
69 gchar * pid_str = NULL;
70 gchar ** argv = NULL;
71 gchar * argv_nopid[2] = {
72 "/usr/share/apport/recoverable_problem",
73 NULL
74 };
75 gchar * argv_pid[4] = {
76 "/usr/share/apport/recoverable_problem",
77 "-p",
78 NULL, /* put pid_str when allocated here */
79 NULL
80 };
81
82
83 argv = (gchar **)argv_nopid;
84
85 if (report_pid != 0) {
86 pid_str = g_strdup_printf("%d", report_pid);
87 argv_pid[2] = pid_str;
88 argv = (gchar**)argv_pid;
89 }
90
91 GSpawnFlags flags = G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL;
92 if (wait) {
93 flags |= G_SPAWN_DO_NOT_REAP_CHILD;
94 }
95
96 g_spawn_async_with_pipes(NULL, /* cwd */
97 argv,
98 NULL, /* envp */
99 flags,
100 NULL, NULL, /* child setup func */
101 &pid,
102 &error_stdin,
103 NULL, /* stdout */
104 NULL, /* stderr */
105 &error);
106
107 if (error != NULL) {
108 g_warning("Unable to report a recoverable error: %s", error->message);
109 g_error_free(error);
110 }
111
112 gboolean first = TRUE;
113
114 if (error_stdin != 0 && signature != NULL) {
115 write_string(error_stdin, "DuplicateSignature");
116 write_null(error_stdin);
117 write_string(error_stdin, signature);
118
119 first = FALSE;
120 }
121
122 if (error_stdin != 0 && additional_properties != NULL) {
123 gint i;
124 for (i = 0; additional_properties[i] != NULL; i++) {
125 if (!first) {
126 write_null(error_stdin);
127 } else {
128 first = FALSE;
129 }
130
131 write_string(error_stdin, additional_properties[i]);
132 }
133 }
134
135 if (error_stdin != 0) {
136 close(error_stdin);
137 }
138
139 if (wait && pid != 0) {
140 GSource * child_source, * timeout_source;
141 GMainContext * context = g_main_context_new();
142 GMainLoop * loop = g_main_loop_new(context, FALSE);
143
144 child_source = g_child_watch_source_new(pid);
145 g_source_attach(child_source, context);
146 g_source_set_callback(child_source, (GSourceFunc)apport_child_watch, loop, NULL);
147
148 timeout_source = g_timeout_source_new_seconds(5);
149 g_source_attach(timeout_source, context);
150 g_source_set_callback(timeout_source, apport_child_timeout, loop, NULL);
151
152 g_main_loop_run(loop);
153
154 g_source_destroy(timeout_source);
155 g_source_destroy(child_source);
156 g_main_loop_unref(loop);
157 g_main_context_unref(context);
158
159 g_spawn_close_pid(pid);
160 }
161
162 g_free(pid_str);
163
164 return;
165}
0166
=== added file 'recoverable-problem.h'
--- recoverable-problem.h 1970-01-01 00:00:00 +0000
+++ recoverable-problem.h 2014-04-16 18:51:37 +0000
@@ -0,0 +1,26 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Ted Gould <ted.gould@canonical.com>
18 */
19
20#include <gio/gio.h>
21
22void report_recoverable_problem (const gchar * signature,
23 GPid report_pid,
24 gboolean wait,
25 const gchar * additional_properties[]);
26

Subscribers

People subscribed via source and target branches