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

Proposed by James Hunt on 2014-01-21
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 2014-01-21 Needs Information on 2014-03-05
Review via email: mp+202458@code.launchpad.net
To post a comment you must log in.
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
=== modified file 'ChangeLog'
--- ChangeLog 2014-01-17 15:39:55 +0000
+++ ChangeLog 2014-01-21 13:39:11 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
12014-01-17 James Hunt <james.hunt@ubuntu.com>22014-01-17 James Hunt <james.hunt@ubuntu.com>
23
3 * init/conf.c:4 * init/conf.c:
@@ -64,6 +65,20 @@
64 * init/man/init.5: Provide more detail on setuid and setgid stanzas65 * init/man/init.5: Provide more detail on setuid and setgid stanzas
65 (debian bug#732127).66 (debian bug#732127).
6667
68=======
692013-12-12 James Hunt <james.hunt@ubuntu.com>
70
71 * init/control.c:
72 - control_serialise_bus_address(), control_deserialise_bus_address():
73 New functions to handle carrying the control bus address across a
74 re-exec (LP: #1258098).
75 * init/state.c:
76 - state_to_string(): Handle control bus address serialisation.
77 - state_from_string(): Handle control bus address deserialisation.
78 * util/tests/test_initctl.c: test_dbus_connection(): New test:
79 - "ensure Session Init retains D-Bus address across a re-exec"
80
81>>>>>>> MERGE-SOURCE
672013-11-23 Steve Langasek <steve.langasek@ubuntu.com>822013-11-23 Steve Langasek <steve.langasek@ubuntu.com>
6883
69 * init/tests/test_state.c: fix test case to not assume SIGUSR1 == 10;84 * init/tests/test_state.c: fix test case to not assume SIGUSR1 == 10;
7085
=== modified file 'init/control.c'
--- init/control.c 2013-11-05 16:15:19 +0000
+++ init/control.c 2014-01-21 13:39:11 +0000
@@ -1887,3 +1887,66 @@
18871887
1888 return 0;1888 return 0;
1889}1889}
1890
1891/**
1892 * control_serialise_bus_address:
1893 *
1894 * Convert control_bus_address into JSON representation.
1895 *
1896 * Returns: JSON string representing control_bus_address or NULL if
1897 * control_bus_address not set or on error.
1898 *
1899 * Note: If NULL is returned, check the value of control_bus_address
1900 * itself to determine if the error is real.
1901 **/
1902json_object *
1903control_serialise_bus_address (void)
1904{
1905 control_init ();
1906
1907 /* A NULL return represents a JSON null */
1908 return control_bus_address
1909 ? json_object_new_string (control_bus_address)
1910 : NULL;
1911}
1912
1913/**
1914 * control_deserialise_bus_address:
1915 *
1916 * @json: root of JSON-serialised state.
1917 *
1918 * Convert JSON representation of control_bus_address back into a native
1919 * string.
1920 *
1921 * Returns: 0 on success, -1 on error.
1922 **/
1923int
1924control_deserialise_bus_address (json_object *json)
1925{
1926 const char *address;
1927
1928 nih_assert (json);
1929 nih_assert (! control_bus_address);
1930
1931 control_init ();
1932
1933 /* control_bus_address was never set */
1934 if (state_check_json_type (json, null))
1935 return 0;
1936
1937 if (! state_check_json_type (json, string))
1938 goto error;
1939
1940 address = json_object_get_string (json);
1941 if (! address)
1942 goto error;
1943
1944 control_bus_address = nih_strdup (NULL, address);
1945 if (! control_bus_address)
1946 goto error;
1947
1948 return 0;
1949
1950error:
1951 return -1;
1952}
18901953
=== modified file 'init/control.h'
--- init/control.h 2013-10-25 13:49:49 +0000
+++ init/control.h 2014-01-21 13:39:11 +0000
@@ -142,8 +142,7 @@
142int control_conn_to_index (const DBusConnection *connection)142int control_conn_to_index (const DBusConnection *connection)
143 __attribute__ ((warn_unused_result));143 __attribute__ ((warn_unused_result));
144144
145DBusConnection *145DBusConnection *control_conn_from_index (int conn_index)
146control_conn_from_index (int conn_index)
147 __attribute__ ((warn_unused_result));146 __attribute__ ((warn_unused_result));
148147
149int control_bus_release_name (void)148int control_bus_release_name (void)
@@ -184,26 +183,29 @@
184 char **value)183 char **value)
185 __attribute__ ((warn_unused_result));184 __attribute__ ((warn_unused_result));
186185
187int186int control_list_env (void *data,
188control_list_env (void *data,
189 NihDBusMessage *message,187 NihDBusMessage *message,
190 char * const *job_details,188 char * const *job_details,
191 char ***env)189 char ***env)
192 __attribute__ ((warn_unused_result));190 __attribute__ ((warn_unused_result));
193191
194int192int control_reset_env (void *data,
195control_reset_env (void *data,
196 NihDBusMessage *message,193 NihDBusMessage *message,
197 char * const *job_details)194 char * const *job_details)
198 __attribute__ ((warn_unused_result));195 __attribute__ ((warn_unused_result));
199196
200int197int control_unset_env (void *data,
201control_unset_env (void *data,
202 NihDBusMessage *message,198 NihDBusMessage *message,
203 char * const *job_details,199 char * const *job_details,
204 const char *name)200 const char *name)
205 __attribute__ ((warn_unused_result));201 __attribute__ ((warn_unused_result));
206202
203json_object *control_serialise_bus_address (void)
204 __attribute__ ((warn_unused_result));
205
206int control_deserialise_bus_address (json_object *json)
207 __attribute__ ((warn_unused_result));
208
207NIH_END_EXTERN209NIH_END_EXTERN
208210
209#endif /* INIT_CONTROL_H */211#endif /* INIT_CONTROL_H */
210212
=== modified file 'init/state.c'
--- init/state.c 2013-10-11 13:35:51 +0000
+++ init/state.c 2014-01-21 13:39:11 +0000
@@ -54,6 +54,7 @@
54json_object *json_conf_sources = NULL;54json_object *json_conf_sources = NULL;
5555
56extern char *log_dir;56extern char *log_dir;
57extern char *control_bus_address;
5758
58/**59/**
59 * args_copy:60 * args_copy:
@@ -340,6 +341,7 @@
340{341{
341 json_object *json;342 json_object *json;
342 json_object *json_job_environ;343 json_object *json_job_environ;
344 json_object *json_control_bus_address;
343 const char *value;345 const char *value;
344346
345 nih_assert (json_string);347 nih_assert (json_string);
@@ -366,6 +368,20 @@
366368
367 json_object_object_add (json, "events", json_events);369 json_object_object_add (json, "events", json_events);
368370
371 json_control_bus_address = control_serialise_bus_address ();
372
373 /* Take care to distinguish between memory failure and an
374 * as-yet-not-set control bus address.
375 */
376 if (! json_control_bus_address && control_bus_address) {
377 nih_error ("%s %s",
378 _("Failed to serialise"),
379 _("control bus address"));
380 goto error;
381 }
382
383 json_object_object_add (json, "control_bus_address", json_control_bus_address);
384
369 json_job_environ = job_class_serialise_job_environ ();385 json_job_environ = job_class_serialise_job_environ ();
370386
371 if (! json_job_environ) {387 if (! json_job_environ) {
@@ -427,6 +443,7 @@
427 int ret = -1;443 int ret = -1;
428 json_object *json;444 json_object *json;
429 json_object *json_job_environ;445 json_object *json_job_environ;
446 json_object *json_control_bus_address;
430 enum json_tokener_error error;447 enum json_tokener_error error;
431448
432 nih_assert (state);449 nih_assert (state);
@@ -458,6 +475,20 @@
458 goto out;475 goto out;
459 }476 }
460477
478 ret = json_object_object_get_ex (json, "control_bus_address", &json_control_bus_address);
479
480 if (json_control_bus_address) {
481 if (control_deserialise_bus_address (json_control_bus_address) < 0) {
482 nih_error ("%s control details", _("Failed to deserialise"));
483 goto out;
484 }
485 } else if (! ret) {
486 /* Probably deserialising from older format that doesn't
487 * encode control details.
488 */
489 nih_warn ("%s", _("No control details present in state data"));
490 }
491
461 /* Again, we cannot error here since older JSON state data did492 /* Again, we cannot error here since older JSON state data did
462 * not encode ConfSource or ConfFile objects.493 * not encode ConfSource or ConfFile objects.
463 */494 */
464495
=== modified file 'util/tests/test_initctl.c'
--- util/tests/test_initctl.c 2013-11-13 02:50:36 +0000
+++ util/tests/test_initctl.c 2014-01-21 13:39:11 +0000
@@ -17052,6 +17052,27 @@
17052 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");17052 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
17053 nih_free (output);17053 nih_free (output);
1705417054
17055 /*********************************************************************/
17056 TEST_FEATURE ("ensure Session Init retains D-Bus address across a re-exec");
17057
17058 assert0 (unsetenv ("DBUS_SESSION_BUS_ADDRESS"));
17059
17060 REEXEC_UPSTART (upstart_pid, TRUE);
17061
17062 /* Re-apply in the test environment */
17063 assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_session_address, 1));
17064
17065 /* It should still be possible to query the running version via
17066 * the D-Bus session bus since Upstart should have reconnected
17067 * since it was previously notified of the D-Bus address.
17068 */
17069 cmd = nih_sprintf (NULL, "%s --session version 2>&1", get_initctl_binary ());
17070 TEST_NE_P (cmd, NULL);
17071 RUN_COMMAND (NULL, cmd, &output, &lines);
17072 TEST_EQ (lines, 1);
17073 TEST_STR_MATCH (output[0], "init (upstart [0-9.][0-9.]*");
17074 nih_free (output);
17075
17055 STOP_UPSTART (upstart_pid);17076 STOP_UPSTART (upstart_pid);
17056 TEST_DBUS_END (dbus_pid);17077 TEST_DBUS_END (dbus_pid);
1705717078

Subscribers

People subscribed via source and target branches