Merge lp:~xnox/upstart/lp1303891 into lp:upstart

Proposed by Dimitri John Ledkov on 2014-04-09
Status: Merged
Merged at revision: 1612
Proposed branch: lp:~xnox/upstart/lp1303891
Merge into: lp:upstart
Diff against target: 295 lines (+258/-3)
2 files modified
util/initctl.c (+27/-3)
util/tests/test_initctl.c (+231/-0)
To merge this branch: bzr merge lp:~xnox/upstart/lp1303891
Reviewer Review Type Date Requested Status
James Hunt 2014-04-09 Approve on 2014-04-09
Review via email: mp+214908@code.launchpad.net

Commit message

Reintroduce previous reload semantics that simply sent SIGHUP to the main process, thus allowing to reload services during precise -> trusty upgrades.

Description of the change

Reintroduce previous reload semantics that simply sent SIGHUP to the main process, thus allowing to reload services during precise -> trusty upgrades.

To post a comment you must log in.
lp:~xnox/upstart/lp1303891 updated on 2014-04-09
1613. By Dimitri John Ledkov on 2014-04-09

* Use fallback path, and only if we received unknown dbus method error
* Rework tests to test fallback path in such a case

James Hunt (jamesodhunt) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'util/initctl.c'
--- util/initctl.c 2013-10-25 13:49:49 +0000
+++ util/initctl.c 2014-04-09 12:59:58 +0000
@@ -1033,9 +1033,33 @@
10331033
1034 job->auto_start = FALSE;1034 job->auto_start = FALSE;
10351035
1036 if (job_reload_sync (NULL, job) < 0)1036 if (job_reload_sync (NULL, job) < 0) {
1037 goto error;1037 /* well reload_sync call should always work... unless we
10381038 * didn't reboot since upgrade and pid1 is still old
1039 * upstart that does not have reload_sync call, fallback
1040 * to sending SIGHUP to main process
1041 */
1042 err = nih_error_get ();
1043 if (strcmp(((NihDBusError *)err)->name, DBUS_ERROR_UNKNOWN_METHOD)) {
1044 nih_error ("%s", err->message);
1045 nih_free (err);
1046 return 1;
1047 }
1048 nih_free (err);
1049
1050 if (job_get_processes_sync (NULL, job, &processes) < 0)
1051 goto error;
1052
1053 if ((! processes[0]) || strcmp (processes[0]->item0, "main")) {
1054 nih_error (_("Not running"));
1055 return 1;
1056 }
1057
1058 if (kill (processes[0]->item1, SIGHUP) < 0) {
1059 nih_error_raise_system ();
1060 goto error;
1061 }
1062 }
1039 return 0;1063 return 0;
10401064
1041error:1065error:
10421066
=== modified file 'util/tests/test_initctl.c'
--- util/tests/test_initctl.c 2014-03-06 15:21:54 +0000
+++ util/tests/test_initctl.c 2014-04-09 12:59:58 +0000
@@ -8462,12 +8462,20 @@
8462 FILE * output;8462 FILE * output;
8463 FILE * errors;8463 FILE * errors;
8464 pid_t server_pid;8464 pid_t server_pid;
8465 pid_t proc_pid;
8465 DBusMessage * method_call;8466 DBusMessage * method_call;
8466 DBusMessage * reply = NULL;8467 DBusMessage * reply = NULL;
8467 const char * name_value;8468 const char * name_value;
8468 char ** args_value;8469 char ** args_value;
8469 int args_elements;8470 int args_elements;
8470 const char * str_value;8471 const char * str_value;
8472 const char * interface;
8473 const char * property;
8474 DBusMessageIter iter;
8475 DBusMessageIter subiter;
8476 DBusMessageIter arrayiter;
8477 DBusMessageIter structiter;
8478 int32_t int32_value;
8471 NihCommand command;8479 NihCommand command;
8472 char * args[4];8480 char * args[4];
8473 int ret = 0;8481 int ret = 0;
@@ -9139,6 +9147,229 @@
9139 }9147 }
91409148
91419149
9150 /* Check that if an error is received from the Reload call,
9151 * the fallback path is used to query main pid and SIGHUP
9152 * that.
9153 */
9154 TEST_FEATURE ("with error reply to Reload");
9155 TEST_ALLOC_FAIL {
9156 TEST_CHILD (proc_pid) {
9157 pause ();
9158 }
9159
9160 TEST_CHILD (server_pid) {
9161 /* Expect the GetJobByName method call on the
9162 * manager object, make sure the job name is passed
9163 * and reply with a path.
9164 */
9165 TEST_DBUS_MESSAGE (server_conn, method_call);
9166
9167 TEST_TRUE (dbus_message_is_method_call (method_call,
9168 DBUS_INTERFACE_UPSTART,
9169 "GetJobByName"));
9170
9171 TEST_EQ_STR (dbus_message_get_path (method_call),
9172 DBUS_PATH_UPSTART);
9173
9174 TEST_TRUE (dbus_message_get_args (method_call, NULL,
9175 DBUS_TYPE_STRING, &name_value,
9176 DBUS_TYPE_INVALID));
9177
9178 TEST_EQ_STR (name_value, "test");
9179
9180 TEST_ALLOC_SAFE {
9181 reply = dbus_message_new_method_return (method_call);
9182
9183 str_value = DBUS_PATH_UPSTART "/jobs/test";
9184
9185 dbus_message_append_args (reply,
9186 DBUS_TYPE_OBJECT_PATH, &str_value,
9187 DBUS_TYPE_INVALID);
9188 }
9189
9190 dbus_connection_send (server_conn, reply, NULL);
9191 dbus_connection_flush (server_conn);
9192
9193 dbus_message_unref (method_call);
9194 dbus_message_unref (reply);
9195
9196 /* Expect the GetInstance method call on the
9197 * job object, make sure the environment args are
9198 * passed and reply with a path.
9199 */
9200 TEST_DBUS_MESSAGE (server_conn, method_call);
9201
9202 TEST_TRUE (dbus_message_is_method_call (method_call,
9203 DBUS_INTERFACE_UPSTART_JOB,
9204 "GetInstance"));
9205
9206 TEST_EQ_STR (dbus_message_get_path (method_call),
9207 DBUS_PATH_UPSTART "/jobs/test");
9208
9209 TEST_TRUE (dbus_message_get_args (method_call, NULL,
9210 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &args_value, &args_elements,
9211 DBUS_TYPE_INVALID));
9212
9213 TEST_EQ (args_elements, 0);
9214 dbus_free_string_array (args_value);
9215
9216 TEST_ALLOC_SAFE {
9217 reply = dbus_message_new_method_return (method_call);
9218
9219 str_value = DBUS_PATH_UPSTART "/jobs/test/_";
9220
9221 dbus_message_append_args (reply,
9222 DBUS_TYPE_OBJECT_PATH, &str_value,
9223 DBUS_TYPE_INVALID);
9224 }
9225
9226 dbus_connection_send (server_conn, reply, NULL);
9227 dbus_connection_flush (server_conn);
9228
9229 dbus_message_unref (method_call);
9230 dbus_message_unref (reply);
9231
9232 /* Expect the Reload method call against job
9233 * instance and reply with an error.
9234 */
9235 TEST_DBUS_MESSAGE (server_conn, method_call);
9236
9237 TEST_TRUE (dbus_message_is_method_call (method_call,
9238 DBUS_INTERFACE_UPSTART_INSTANCE,
9239 "Reload"));
9240
9241 TEST_EQ_STR (dbus_message_get_path (method_call),
9242 DBUS_PATH_UPSTART "/jobs/test/_");
9243
9244 TEST_TRUE (dbus_message_get_args (method_call, NULL,
9245 DBUS_TYPE_INVALID));
9246
9247 TEST_ALLOC_SAFE {
9248 reply = dbus_message_new_error (method_call,
9249 DBUS_ERROR_UNKNOWN_METHOD,
9250 "Unknown method");
9251 }
9252
9253 dbus_connection_send (server_conn, reply, NULL);
9254 dbus_connection_flush (server_conn);
9255
9256 dbus_message_unref (method_call);
9257 dbus_message_unref (reply);
9258
9259 /* Expect the Get call for the processes, reply with
9260 * a main process pid.
9261 */
9262 TEST_DBUS_MESSAGE (server_conn, method_call);
9263
9264 TEST_TRUE (dbus_message_is_method_call (method_call,
9265 DBUS_INTERFACE_PROPERTIES,
9266 "Get"));
9267 TEST_EQ_STR (dbus_message_get_path (method_call),
9268 DBUS_PATH_UPSTART "/jobs/test/_");
9269
9270 TEST_TRUE (dbus_message_get_args (method_call, NULL,
9271 DBUS_TYPE_STRING, &interface,
9272 DBUS_TYPE_STRING, &property,
9273 DBUS_TYPE_INVALID));
9274
9275 TEST_ALLOC_SAFE {
9276 reply = dbus_message_new_method_return (method_call);
9277
9278 dbus_message_iter_init_append (reply, &iter);
9279
9280 dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT,
9281 (DBUS_TYPE_ARRAY_AS_STRING
9282 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
9283 DBUS_TYPE_STRING_AS_STRING
9284 DBUS_TYPE_INT32_AS_STRING
9285 DBUS_STRUCT_END_CHAR_AS_STRING),
9286 &subiter);
9287
9288 dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY,
9289 (DBUS_STRUCT_BEGIN_CHAR_AS_STRING
9290 DBUS_TYPE_STRING_AS_STRING
9291 DBUS_TYPE_INT32_AS_STRING
9292 DBUS_STRUCT_END_CHAR_AS_STRING),
9293 &arrayiter);
9294
9295 dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT,
9296 NULL,
9297 &structiter);
9298
9299 str_value = "main";
9300 dbus_message_iter_append_basic (&structiter, DBUS_TYPE_STRING,
9301 &str_value);
9302
9303 int32_value = proc_pid;
9304 dbus_message_iter_append_basic (&structiter, DBUS_TYPE_INT32,
9305 &int32_value);
9306
9307 dbus_message_iter_close_container (&arrayiter, &structiter);
9308
9309 dbus_message_iter_close_container (&subiter, &arrayiter);
9310
9311 dbus_message_iter_close_container (&iter, &subiter);
9312 }
9313
9314 dbus_connection_send (server_conn, reply, NULL);
9315 dbus_connection_flush (server_conn);
9316
9317 dbus_message_unref (method_call);
9318 dbus_message_unref (reply);
9319
9320 TEST_DBUS_CLOSE (server_conn);
9321
9322 dbus_shutdown ();
9323
9324 exit (0);
9325 }
9326
9327 memset (&command, 0, sizeof command);
9328
9329 args[0] = "test";
9330 args[1] = NULL;
9331
9332 TEST_DIVERT_STDOUT (output) {
9333 TEST_DIVERT_STDERR (errors) {
9334 ret = reload_action (&command, args);
9335 }
9336 }
9337 rewind (output);
9338 rewind (errors);
9339
9340 if (test_alloc_failed
9341 && (ret != 0)) {
9342 TEST_FILE_END (output);
9343 TEST_FILE_RESET (output);
9344
9345 TEST_FILE_EQ (errors, "test: Cannot allocate memory\n");
9346 TEST_FILE_END (errors);
9347 TEST_FILE_RESET (errors);
9348
9349 kill (server_pid, SIGTERM);
9350 waitpid (server_pid, NULL, 0);
9351 continue;
9352 }
9353
9354 TEST_EQ (ret, 0);
9355
9356 TEST_FILE_END (output);
9357 TEST_FILE_RESET (output);
9358
9359 TEST_FILE_END (errors);
9360 TEST_FILE_RESET (errors);
9361
9362 waitpid (server_pid, &status, 0);
9363 TEST_TRUE (WIFEXITED (status));
9364 TEST_EQ (WEXITSTATUS (status), 0);
9365
9366 kill (proc_pid, SIGTERM);
9367 waitpid (proc_pid, NULL, 0);
9368 continue;
9369
9370 }
9371
9372
9142 /* Check that a missing argument results in an error being output9373 /* Check that a missing argument results in an error being output
9143 * to stderr along with a suggestion of help.9374 * to stderr along with a suggestion of help.
9144 */9375 */

Subscribers

People subscribed via source and target branches