Merge lp:~jamesodhunt/upstart/bug-1258098 into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1606
Proposed branch: lp:~jamesodhunt/upstart/bug-1258098
Merge into: lp:upstart
Diff against target: 251 lines (+140/-8) (has conflicts)
5 files modified
ChangeLog (+15/-0)
init/control.c (+63/-0)
init/control.h (+10/-8)
init/state.c (+31/-0)
util/tests/test_initctl.c (+21/-0)
Text conflict in ChangeLog
To merge this branch: bzr merge lp:~jamesodhunt/upstart/bug-1258098
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Needs Information
Review via email: mp+202458@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

The code looks ok, the test is not passing for me:

not ok 5 - ensure Session Init retains D-Bus address across a re-exec
 wrong value for running, expected 1 got 0
 at test_util_common.c:132 (wait_for_upstart).
Aborted (core dumped)

Also note: https://bugs.launchpad.net/upstart/+bug/1288243

review: Needs Information

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2014-01-17 15:39:55 +0000
3+++ ChangeLog 2014-01-21 13:39:11 +0000
4@@ -1,3 +1,4 @@
5+<<<<<<< TREE
6 2014-01-17 James Hunt <james.hunt@ubuntu.com>
7
8 * init/conf.c:
9@@ -64,6 +65,20 @@
10 * init/man/init.5: Provide more detail on setuid and setgid stanzas
11 (debian bug#732127).
12
13+=======
14+2013-12-12 James Hunt <james.hunt@ubuntu.com>
15+
16+ * init/control.c:
17+ - control_serialise_bus_address(), control_deserialise_bus_address():
18+ New functions to handle carrying the control bus address across a
19+ re-exec (LP: #1258098).
20+ * init/state.c:
21+ - state_to_string(): Handle control bus address serialisation.
22+ - state_from_string(): Handle control bus address deserialisation.
23+ * util/tests/test_initctl.c: test_dbus_connection(): New test:
24+ - "ensure Session Init retains D-Bus address across a re-exec"
25+
26+>>>>>>> MERGE-SOURCE
27 2013-11-23 Steve Langasek <steve.langasek@ubuntu.com>
28
29 * init/tests/test_state.c: fix test case to not assume SIGUSR1 == 10;
30
31=== modified file 'init/control.c'
32--- init/control.c 2013-11-05 16:15:19 +0000
33+++ init/control.c 2014-01-21 13:39:11 +0000
34@@ -1887,3 +1887,66 @@
35
36 return 0;
37 }
38+
39+/**
40+ * control_serialise_bus_address:
41+ *
42+ * Convert control_bus_address into JSON representation.
43+ *
44+ * Returns: JSON string representing control_bus_address or NULL if
45+ * control_bus_address not set or on error.
46+ *
47+ * Note: If NULL is returned, check the value of control_bus_address
48+ * itself to determine if the error is real.
49+ **/
50+json_object *
51+control_serialise_bus_address (void)
52+{
53+ control_init ();
54+
55+ /* A NULL return represents a JSON null */
56+ return control_bus_address
57+ ? json_object_new_string (control_bus_address)
58+ : NULL;
59+}
60+
61+/**
62+ * control_deserialise_bus_address:
63+ *
64+ * @json: root of JSON-serialised state.
65+ *
66+ * Convert JSON representation of control_bus_address back into a native
67+ * string.
68+ *
69+ * Returns: 0 on success, -1 on error.
70+ **/
71+int
72+control_deserialise_bus_address (json_object *json)
73+{
74+ const char *address;
75+
76+ nih_assert (json);
77+ nih_assert (! control_bus_address);
78+
79+ control_init ();
80+
81+ /* control_bus_address was never set */
82+ if (state_check_json_type (json, null))
83+ return 0;
84+
85+ if (! state_check_json_type (json, string))
86+ goto error;
87+
88+ address = json_object_get_string (json);
89+ if (! address)
90+ goto error;
91+
92+ control_bus_address = nih_strdup (NULL, address);
93+ if (! control_bus_address)
94+ goto error;
95+
96+ return 0;
97+
98+error:
99+ return -1;
100+}
101
102=== modified file 'init/control.h'
103--- init/control.h 2013-10-25 13:49:49 +0000
104+++ init/control.h 2014-01-21 13:39:11 +0000
105@@ -142,8 +142,7 @@
106 int control_conn_to_index (const DBusConnection *connection)
107 __attribute__ ((warn_unused_result));
108
109-DBusConnection *
110-control_conn_from_index (int conn_index)
111+DBusConnection *control_conn_from_index (int conn_index)
112 __attribute__ ((warn_unused_result));
113
114 int control_bus_release_name (void)
115@@ -184,26 +183,29 @@
116 char **value)
117 __attribute__ ((warn_unused_result));
118
119-int
120-control_list_env (void *data,
121+int control_list_env (void *data,
122 NihDBusMessage *message,
123 char * const *job_details,
124 char ***env)
125 __attribute__ ((warn_unused_result));
126
127-int
128-control_reset_env (void *data,
129+int control_reset_env (void *data,
130 NihDBusMessage *message,
131 char * const *job_details)
132 __attribute__ ((warn_unused_result));
133
134-int
135-control_unset_env (void *data,
136+int control_unset_env (void *data,
137 NihDBusMessage *message,
138 char * const *job_details,
139 const char *name)
140 __attribute__ ((warn_unused_result));
141
142+json_object *control_serialise_bus_address (void)
143+ __attribute__ ((warn_unused_result));
144+
145+int control_deserialise_bus_address (json_object *json)
146+ __attribute__ ((warn_unused_result));
147+
148 NIH_END_EXTERN
149
150 #endif /* INIT_CONTROL_H */
151
152=== modified file 'init/state.c'
153--- init/state.c 2013-10-11 13:35:51 +0000
154+++ init/state.c 2014-01-21 13:39:11 +0000
155@@ -54,6 +54,7 @@
156 json_object *json_conf_sources = NULL;
157
158 extern char *log_dir;
159+extern char *control_bus_address;
160
161 /**
162 * args_copy:
163@@ -340,6 +341,7 @@
164 {
165 json_object *json;
166 json_object *json_job_environ;
167+ json_object *json_control_bus_address;
168 const char *value;
169
170 nih_assert (json_string);
171@@ -366,6 +368,20 @@
172
173 json_object_object_add (json, "events", json_events);
174
175+ json_control_bus_address = control_serialise_bus_address ();
176+
177+ /* Take care to distinguish between memory failure and an
178+ * as-yet-not-set control bus address.
179+ */
180+ if (! json_control_bus_address && control_bus_address) {
181+ nih_error ("%s %s",
182+ _("Failed to serialise"),
183+ _("control bus address"));
184+ goto error;
185+ }
186+
187+ json_object_object_add (json, "control_bus_address", json_control_bus_address);
188+
189 json_job_environ = job_class_serialise_job_environ ();
190
191 if (! json_job_environ) {
192@@ -427,6 +443,7 @@
193 int ret = -1;
194 json_object *json;
195 json_object *json_job_environ;
196+ json_object *json_control_bus_address;
197 enum json_tokener_error error;
198
199 nih_assert (state);
200@@ -458,6 +475,20 @@
201 goto out;
202 }
203
204+ ret = json_object_object_get_ex (json, "control_bus_address", &json_control_bus_address);
205+
206+ if (json_control_bus_address) {
207+ if (control_deserialise_bus_address (json_control_bus_address) < 0) {
208+ nih_error ("%s control details", _("Failed to deserialise"));
209+ goto out;
210+ }
211+ } else if (! ret) {
212+ /* Probably deserialising from older format that doesn't
213+ * encode control details.
214+ */
215+ nih_warn ("%s", _("No control details present in state data"));
216+ }
217+
218 /* Again, we cannot error here since older JSON state data did
219 * not encode ConfSource or ConfFile objects.
220 */
221
222=== modified file 'util/tests/test_initctl.c'
223--- util/tests/test_initctl.c 2013-11-13 02:50:36 +0000
224+++ util/tests/test_initctl.c 2014-01-21 13:39:11 +0000
225@@ -17052,6 +17052,27 @@
226 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
227 nih_free (output);
228
229+ /*********************************************************************/
230+ TEST_FEATURE ("ensure Session Init retains D-Bus address across a re-exec");
231+
232+ assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS"));
233+
234+ REEXEC_UPSTART (upstart_pid, TRUE);
235+
236+ /* Re-apply in the test environment */
237+ assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1));
238+
239+ /* It should still be possible to query the running version via
240+ * the D-Bus session bus since Upstart should have reconnected
241+ * since it was previously notified of the D-Bus address.
242+ */
243+ cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
244+ TEST_NE_P (cmd, NULL);
245+ RUN_COMMAND (NULL, cmd, &output, &lines);
246+ TEST_EQ (lines, 1);
247+ TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
248+ nih_free (output);
249+
250 STOP_UPSTART (upstart_pid);
251 TEST_DBUS_END (dbus_pid);
252

Subscribers

People subscribed via source and target branches