Merge lp:~laney/whoopsie-preferences/hack-update-rc-d into lp:whoopsie-preferences

Proposed by Iain Lane
Status: Merged
Merged at revision: 71
Proposed branch: lp:~laney/whoopsie-preferences/hack-update-rc-d
Merge into: lp:whoopsie-preferences
Diff against target: 151 lines (+61/-12)
3 files modified
debian/changelog (+7/-0)
src/Makefile.am (+6/-2)
src/whoopsie-preferences.c (+48/-10)
To merge this branch: bzr merge lp:~laney/whoopsie-preferences/hack-update-rc-d
Reviewer Review Type Date Requested Status
Oliver Grawert (community) Approve
Daisy Pluckers Pending
Review via email: mp+270682@code.launchpad.net

Commit message

If we can't use update-rc.d to clear the upstart .override file (to enable whoopsie), try to do it ourselves.

Description of the change

update-rc.d uses renames to update the file atomically. This doesn't work on our read only Ubuntu touch setup - it's a well known deficiency.

Fortunately we just need to clear the override file here. We can do that without needing to rename.

To post a comment you must log in.
Revision history for this message
Oliver Grawert (ogra) wrote :

looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-05-22 11:58:05 +0000
3+++ debian/changelog 2015-09-10 14:03:14 +0000
4@@ -1,3 +1,10 @@
5+whoopsie-preferences (0.18) wily; urgency=medium
6+
7+ * Truncate the file manually if update-rc.d fails (e.g. on an r/o phone).
8+ * Build with -Werror=implicit-function-declarations
9+
10+ -- Iain Lane <iain@orangesquash.org.uk> Thu, 10 Sep 2015 12:11:37 +0100
11+
12 whoopsie-preferences (0.17) wily; urgency=medium
13
14 * Fall back to /etc/writable for /etc/whoopsie if we need to. Thanks seb128
15
16=== modified file 'src/Makefile.am'
17--- src/Makefile.am 2013-07-19 13:38:07 +0000
18+++ src/Makefile.am 2015-09-10 14:03:14 +0000
19@@ -1,6 +1,8 @@
20 bin_PROGRAMS = whoopsie-preferences
21 lib_LTLIBRARIES = libwhoopsie-preferences.la
22
23+AM_CFLAGS = -Werror=implicit-function-declaration
24+
25 pkgconfigdir = $(libdir)/pkgconfig
26 policykitdir = $(datadir)/polkit-1/actions/
27 dbussystemdir = $(sysconfdir)/dbus-1/system.d/
28@@ -16,7 +18,8 @@
29 -Wall \
30 -g \
31 $(POLKIT_CFLAGS) $(GIO_UNIX_CFLAGS) \
32- $(LIBWHOOPSIE_CFLAGS)
33+ $(LIBWHOOPSIE_CFLAGS) \
34+ $(AM_CFLAGS)
35
36 libwhoopsie_preferences_la_SOURCES = \
37 libwhoopsie-preferences.c \
38@@ -33,7 +36,8 @@
39 -Wall \
40 -g \
41 $(POLKIT_CFLAGS) $(GIO_UNIX_CFLAGS) \
42- $(LIBWHOOPSIE_CFLAGS)
43+ $(LIBWHOOPSIE_CFLAGS) \
44+ $(AM_CFLAGS)
45
46 whoopsie_preferences_SOURCES = \
47 whoopsie-preferences.c
48
49=== modified file 'src/whoopsie-preferences.c'
50--- src/whoopsie-preferences.c 2015-05-22 11:57:16 +0000
51+++ src/whoopsie-preferences.c 2015-09-10 14:03:14 +0000
52@@ -17,15 +17,18 @@
53 * along with this program. If not, see <http://www.gnu.org/licenses/>.
54 */
55
56-#define _XOPEN_SOURCE
57+#define _XOPEN_SOURCE 500
58
59-#include <stdio.h>
60+#include <errno.h>
61 #include <gio/gio.h>
62+#include <glib/gstdio.h>
63+#include <polkit/polkit.h>
64+#include <stdio.h>
65+#include <stdio.h>
66 #include <stdlib.h>
67-#include <polkit/polkit.h>
68+#include <string.h>
69+#include <sys/stat.h>
70 #include <sys/types.h>
71-#include <sys/stat.h>
72-#include <stdio.h>
73 #include <unistd.h>
74
75 #include <libwhoopsie/identifier.h>
76@@ -130,6 +133,11 @@
77 }
78
79 static gboolean
80+is_systemd() {
81+ return g_file_test ("/run/systemd/system", G_FILE_TEST_IS_DIR);
82+}
83+
84+static gboolean
85 whoopsie_preferences_whoopsie_enabled (GError **error) {
86 char* systemd_check_command[] = { "/bin/systemctl", "-q", "is-enabled", "whoopsie.service", NULL };
87 gchar* upstart_override_content = NULL;
88@@ -137,7 +145,7 @@
89 int exit_code = 0;
90
91 /* systemd running */
92- if (g_file_test ("/run/systemd/system", G_FILE_TEST_IS_DIR)) {
93+ if (is_systemd()) {
94 if (g_spawn_sync (NULL, systemd_check_command, NULL, 0, NULL, NULL, NULL, NULL, &exit_code, error))
95 report_crashes = (exit_code == 0);
96 }
97@@ -304,9 +312,14 @@
98 gboolean saved_value, new_value;
99 GError* error = NULL;
100 char* data;
101+ char* errstr;
102 gsize data_size;
103 gboolean crashes = !g_strcmp0(user_data, "report_crashes");
104 char* crash_enable_command[] = { "/usr/sbin/update-rc.d", "whoopsie", NULL, NULL };
105+ char* initctl_reload_command[] = { "/sbin/initctl", "reload-configuration", NULL };
106+ gboolean spawn_ok;
107+ gint exit_status;
108+ FILE* f = NULL;
109
110 increase_shutdown_timeout ();
111
112@@ -330,10 +343,35 @@
113 error = NULL;
114
115 if (crashes) {
116- if (!g_spawn_sync (NULL, crash_enable_command, NULL, 0, NULL, NULL, NULL, NULL, NULL, &error)) {
117- g_print ("Could not run invoke-rc.d: %s\n", error->message);
118- g_error_free (error);
119- return FALSE;
120+ spawn_ok = g_spawn_sync (NULL, crash_enable_command, NULL, 0, NULL,
121+ NULL, NULL, NULL, &exit_status, &error);
122+ if (!spawn_ok || exit_status != 0) {
123+ if (error) {
124+ errstr = g_strdup (error->message);
125+ g_error_free (error);
126+ } else
127+ errstr = g_strdup_printf ("exited with code %d", exit_status);
128+ g_print ("Could not run update-rc.d: %s\n", errstr);
129+ g_free (errstr);
130+
131+ /* It's a real error for systemd */
132+ if (is_systemd())
133+ return FALSE;
134+
135+ /* Works for enabling (truncating) on upstart only atm */
136+ if (new_value) {
137+ g_debug ("Truncating the override file manually");
138+ f = fopen ("/etc/init/whoopsie.override", "w");
139+ if (f) {
140+ fclose (f);
141+ if (!g_spawn_sync (NULL, initctl_reload_command, NULL, 0, NULL,
142+ NULL, NULL, NULL, &exit_status, &error))
143+ g_print ("Could not run initctl reload-configuration: %s\n", errstr);
144+ } else {
145+ g_warning ("Couldn't open override file: %s", strerror(errno));
146+ return FALSE;
147+ }
148+ }
149 }
150 } else {
151 g_key_file_set_boolean (key_file, "General", user_data, new_value);

Subscribers

People subscribed via source and target branches

to all changes: