Merge lp:~seb128/whoopsie-preferences/touch-writable-image into lp:whoopsie-preferences

Proposed by Sebastien Bacher on 2015-05-19
Status: Merged
Approved by: Iain Lane on 2015-05-21
Approved revision: 57
Merged at revision: 57
Proposed branch: lp:~seb128/whoopsie-preferences/touch-writable-image
Merge into: lp:whoopsie-preferences
Diff against target: 79 lines (+46/-2)
1 file modified
src/whoopsie-preferences.c (+46/-2)
To merge this branch: bzr merge lp:~seb128/whoopsie-preferences/touch-writable-image
Reviewer Review Type Date Requested Status
Iain Lane 2015-05-19 Approve on 2015-05-21
Review via email: mp+259531@code.launchpad.net

Commit Message

Hack to support system-image read-only /etc, and modify files in
/etc/writable/ instead (similar to what is used in systemd in Ubuntu)
(lp: #1437633)

Description of the Change

Hack to support system-image read-only /etc, and modify files in
/etc/writable/ instead (similar to what is used in systemd in Ubuntu)
(lp: #1437633)

To post a comment you must log in.
57. By Sebastien Bacher on 2015-05-19

Hack to support system-image read-only /etc, and modify files in
/etc/writable/ instead (similar to what is used in systemd in Ubuntu)
(lp: #1437633)

Iain Lane (laney) wrote :

I think this is fine. I was confused about why you use a static string for the return variable, but I suppose it's so you don't have to free it?

I have one small comment but I'll fix it when merging. Will test and upload.

review: Approve
Sebastien Bacher (seb128) wrote :

thanks for the review

> I was confused about why you use a static string for the return variable, but I suppose it's so you don't have to free it?

right, that's what is done in the systemd patch and I though it was a good idea and that we could do the same here

Iain Lane (laney) wrote :

btw I had to add code to resolve the symlink to an absolute path (systemd has a helper to do this), because we create relative symlinks in livecd-rootfs but the code expects an absolute path

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/whoopsie-preferences.c'
2--- src/whoopsie-preferences.c 2015-04-02 20:07:45 +0000
3+++ src/whoopsie-preferences.c 2015-05-19 18:26:50 +0000
4@@ -23,6 +23,11 @@
5 #include <gio/gio.h>
6 #include <stdlib.h>
7 #include <polkit/polkit.h>
8+#include <sys/types.h>
9+#include <sys/stat.h>
10+#include <stdio.h>
11+#include <unistd.h>
12+
13 #include <libwhoopsie/identifier.h>
14
15 #include "libwhoopsie-preferences.h"
16@@ -34,6 +39,45 @@
17 static GKeyFile* key_file = NULL;
18 static PolkitAuthority* authority = NULL;
19
20+/* Hack for Ubuntu phone: check if path is an existing symlink to
21+ * /etc/writable; if it is, update that instead */
22+static const char* writable_filename(const char *config) {
23+ const char *result = config;
24+ struct stat sb;
25+ char *linkname = NULL;
26+ ssize_t r;
27+ static char realfile_buf[PATH_MAX];
28+
29+ if (lstat(config, &sb) == -1) {
30+ return config;
31+ }
32+
33+ linkname = g_malloc(sb.st_size + 1);
34+ if (linkname == NULL) {
35+ return result;
36+ }
37+
38+ r = readlink(config, linkname, sb.st_size + 1);
39+
40+ if (r < 0) {
41+ g_free (linkname);
42+ return result;
43+ }
44+ if (r > sb.st_size) {
45+ g_free (linkname);
46+ return result;
47+ }
48+ linkname[sb.st_size] = '\0';
49+
50+ if (g_str_has_prefix (linkname, "/etc/writable")) {
51+ g_snprintf(realfile_buf, sizeof(realfile_buf), "%s", linkname);
52+ result = realfile_buf;
53+ }
54+
55+ g_free (linkname);
56+ return result;
57+}
58+
59 gboolean
60 whoopsie_preferences_load_configuration (void)
61 {
62@@ -54,7 +98,7 @@
63 ret = FALSE;
64 goto out;
65 }
66- if (!g_file_set_contents (CONFIG_PATH, data, data_size, &error)) {
67+ if (!g_file_set_contents (writable_filename(CONFIG_PATH), data, data_size, &error)) {
68 g_print ("Could not write configuration: %s\n", error->message);
69 ret = FALSE;
70 goto out;
71@@ -281,7 +325,7 @@
72 g_print ("Could not process configuration: %s\n", error->message);
73 return FALSE;
74 }
75- if (!g_file_set_contents (CONFIG_PATH, data, data_size, &error)) {
76+ if (!g_file_set_contents (writable_filename(CONFIG_PATH), data, data_size, &error)) {
77 g_print ("Could not write configuration: %s\n", error->message);
78 return FALSE;
79 }

Subscribers

People subscribed via source and target branches