Merge lp:~jamesodhunt/upstart/test-quiesce-cleanup into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1528
Proposed branch: lp:~jamesodhunt/upstart/test-quiesce-cleanup
Merge into: lp:upstart
Diff against target: 528 lines (+245/-54)
2 files modified
ChangeLog (+14/-0)
util/tests/test_initctl.c (+231/-54)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/test-quiesce-cleanup
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Review via email: mp+182698@code.launchpad.net

Description of the change

* util/tests/test_initctl.c: test_quiesce(): Clean up any processes that
  the Session Init couldn't before it shut down.

Note that such rogues can cause issues for pbuilder.

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) wrote :

Hi James,

Some of these changes appear to be for cases where we launch a session init with a single job, and then shut down the session init. Why should the session init ever fail to kill the job's process in this case? Isn't this a bug in the session init itself, not in the test case?

If a session init can fail to kill -9 its subprocesses under test, it can also fail to do so in the real world; that sounds like a bug to me that we should fix, not work around in the test.

review: Needs Information
1528. By James Hunt

* util/tests/test_initctl.c: test_quiesce():
  - Improve kill checks on job processes.
  - Assert precisely which job processes are expected to be running
    after the Session Init has exited (particularly important for jobs
    that 'start on session-end' since they may be running in a System
    Shutdown scenario).

Revision history for this message
James Hunt (jamesodhunt) wrote :

Hi Steve,

The tests are simulating both System Shutdown and Session Shutdown.

For the Session Shutdown scenario, the Session Init will wait for the jobs, hence we expect all job processes (even those that block SIGTERM) to be dead by the time the Session Init exits since it will have sent such jobs SIGKILL.

However, in the System Shutdown scenario, when the Display Manager receives SIGTERM to denote system shutdown, it will send the same signal to all its clients, one of which is the Session Init. The Session Init will then send all job processes the job->class->kill_signal signal. However, since the Session Init should not hold up the system shutdown, although it attempts to wait for 5 seconds after sending SIGTERM before sending the final SIGKILL to each job process, it may already have been SIGKILL'd by the Display Manager: on an Ubuntu system, the DM waits 5 seconds between sending SIGTERM and SIGKILL... and the Session Init waits 5 seconds between the time it sent SIGTERM to each job process and the time it sends SIGKILL. The tests were attempting to simulate this exact behaviour but that does admittedly look "odd". I've now updated the branch to avoid such absolute mimicry but at the same time be more careful wrt checking which pids we expect to have stopped and which could still be running.

What this branch does highlight (and which the tests now comment on explicitly) is that any job that specifies "start on session-end" could still be running after the Session Init has exited but only in a System Shutdown context (since the "session-end" event is only emitted in the next iteration of the main loop - after Upstart has sent SIGTERM to all running job processes). As above, on an actual system those processes would get killed by the System Init.

Revision history for this message
Steve Langasek (vorlon) wrote :

The updated branch looks good to me - that precisely addresses my concerns about inconsistent/unreliable tests, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-08-23 14:49:09 +0000
+++ ChangeLog 2013-09-05 16:19:52 +0000
@@ -1,3 +1,17 @@
12013-09-05 James Hunt <james.hunt@ubuntu.com>
2
3 * util/tests/test_initctl.c: test_quiesce():
4 - Improve kill checks on job processes.
5 - Assert precisely which job processes are expected to be running
6 after the Session Init has exited (particularly important for jobs
7 that 'start on session-end' since they may be running in a System
8 Shutdown scenario).
9
102013-08-28 James Hunt <james.hunt@ubuntu.com>
11
12 * util/tests/test_initctl.c: test_quiesce(): Clean up any
13 processes that the Session Init couldn't before it shut down.
14
12013-08-23 James Hunt <james.hunt@ubuntu.com>152013-08-23 James Hunt <james.hunt@ubuntu.com>
216
3 * NEWS: Release 1.1017 * NEWS: Release 1.10
418
=== modified file 'util/tests/test_initctl.c'
--- util/tests/test_initctl.c 2013-08-23 11:23:19 +0000
+++ util/tests/test_initctl.c 2013-09-05 16:19:52 +0000
@@ -11125,6 +11125,7 @@
11125{11125{
11126 char confdir[PATH_MAX];11126 char confdir[PATH_MAX];
11127 char logdir[PATH_MAX];11127 char logdir[PATH_MAX];
11128 char pid_file[PATH_MAX];
11128 char sessiondir[PATH_MAX];11129 char sessiondir[PATH_MAX];
11129 nih_local char *cmd = NULL;11130 nih_local char *cmd = NULL;
11130 pid_t upstart_pid = 0;11131 pid_t upstart_pid = 0;
@@ -11135,6 +11136,8 @@
11135 nih_local NihDBusProxy *upstart = NULL;11136 nih_local NihDBusProxy *upstart = NULL;
11136 nih_local char *orig_xdg_runtime_dir = NULL;11137 nih_local char *orig_xdg_runtime_dir = NULL;
11137 nih_local char *session_file = NULL;11138 nih_local char *session_file = NULL;
11139 nih_local char *job = NULL;
11140 pid_t job_pid;
1113811141
11139 TEST_GROUP ("Session Init quiesce");11142 TEST_GROUP ("Session Init quiesce");
1114011143
@@ -11204,21 +11207,64 @@
11204 TEST_EQ (lines, 1);11207 TEST_EQ (lines, 1);
11205 nih_free (output);11208 nih_free (output);
1120611209
11210 job_pid = job_to_pid ("long-running");
11211 TEST_NE (job_pid, -1);
11212
11207 /* Trigger shutdown */11213 /* Trigger shutdown */
11208 assert0 (kill (upstart_pid, SIGTERM));11214 assert0 (kill (upstart_pid, SIGTERM));
1120911215
11210 /* Force reset */11216 /* Force reset */
11211 test_user_mode = FALSE;11217 test_user_mode = FALSE;
1121211218
11213 TEST_EQ (timed_waitpid (upstart_pid, TEST_QUIESCE_KILL_PHASE), upstart_pid);11219 /* Wait for longer than we expect the Session Init to take to
11220 * shutdown to give it time to send SIGKILL to all job
11221 * processes. This is unrealistic, but safer for the tests since
11222 * the exact behaviour can be checked.
11223 *
11224 * In reality, the following steps either side of the markers *will*
11225 * occur and those within the markers *may* occur:
11226 *
11227 * 1) A System Shutdown is triggered.
11228 * 2) The Display Manager receives SIGTERM.
11229 * 3) The Display Manager sends SIGTERM to all its clients.
11230 * (including the Session Init).
11231 * 4) The Session Init sends SIGTERM to all running job
11232 * processes.
11233 *
11234 * --- :XXX: START MARKER :XXX: ---
11235 *
11236 * 5) The Session Init will attempt to wait for
11237 * MAX(kill_timeout) seconds.
11238 * 6) The Session Init will send all running job processes
11239 * SIGKILL.
11240 * 7) The Session Init will wait for all remaining job processes
11241 * to end.
11242 * 8) The Session Init will exit.
11243 *
11244 * --- :XXX: END MARKER :XXX: ---
11245 *
11246 * 9) The Display Manager sends SIGKILL to all its clients.
11247 * 10) If still running, the Session Init is killed and exits.
11248 *
11249 * The problem is that the Session Init cannot know when the
11250 * Display Manager will kill *it* so it may be that the Session
11251 * Init cannot send SIGKILL to each job process instead relying
11252 * on the System Init to clean up.
11253 */
11254 TEST_EQ (timed_waitpid (upstart_pid, 1+TEST_QUIESCE_KILL_PHASE), upstart_pid);
1121411255
11215 /* Should not now be running */11256 /* Should not now be running */
11216 TEST_EQ (kill (upstart_pid, 0), -1);11257 TEST_EQ (kill (upstart_pid, 0), -1);
11258 TEST_EQ (errno, ESRCH);
1121711259
11218 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",11260 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
11219 sessiondir, (int)upstart_pid));11261 sessiondir, (int)upstart_pid));
11220 unlink (session_file);11262 unlink (session_file);
1122111263
11264 /* pid should no longer exist */
11265 TEST_EQ (kill (job_pid, SIGKILL), -1);
11266 TEST_EQ (errno, ESRCH);
11267
11222 DELETE_FILE (confdir, "long-running.conf");11268 DELETE_FILE (confdir, "long-running.conf");
1122311269
11224 /*******************************************************************/11270 /*******************************************************************/
@@ -11243,33 +11289,45 @@
11243 TEST_EQ (lines, 1);11289 TEST_EQ (lines, 1);
11244 nih_free (output);11290 nih_free (output);
1124511291
11292 job_pid = job_to_pid ("long-running-term");
11293 TEST_NE (job_pid, -1);
11294
11246 /* Trigger shutdown */11295 /* Trigger shutdown */
11247 assert0 (kill (upstart_pid, SIGTERM));11296 assert0 (kill (upstart_pid, SIGTERM));
1124811297
11249 /* Force reset */11298 /* Force reset */
11250 test_user_mode = FALSE;11299 test_user_mode = FALSE;
1125111300
11252 TEST_EQ (timed_waitpid (upstart_pid, TEST_QUIESCE_KILL_PHASE), upstart_pid);11301 TEST_EQ (timed_waitpid (upstart_pid, 1+TEST_QUIESCE_KILL_PHASE), upstart_pid);
1125311302
11254 /* Should not now be running */11303 /* Should not now be running */
11255 TEST_EQ (kill (upstart_pid, 0), -1);11304 TEST_EQ (kill (upstart_pid, 0), -1);
11305 TEST_EQ (errno, ESRCH);
1125611306
11257 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",11307 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
11258 sessiondir, (int)upstart_pid));11308 sessiondir, (int)upstart_pid));
11259 unlink (session_file);11309 unlink (session_file);
1126011310
11311 /* pid should no longer exist */
11312 TEST_EQ (kill (job_pid, SIGKILL), -1);
11313 TEST_EQ (errno, ESRCH);
11314
11261 DELETE_FILE (confdir, "long-running-term.conf");11315 DELETE_FILE (confdir, "long-running-term.conf");
1126211316
11263 /*******************************************************************/11317 /*******************************************************************/
11264 TEST_FEATURE ("system shutdown: one job which starts on session-end");11318 TEST_FEATURE ("system shutdown: one job which starts on session-end");
1126511319
11266 CREATE_FILE (confdir, "session-end.conf",11320 TEST_FILENAME (pid_file);
11267 "start on session-end\n"11321
11268 "\n"11322 job = NIH_MUST (nih_sprintf (NULL, "start on session-end\n"
11269 "script\n"11323 "\n"
11270 " echo hello\n"11324 "script\n"
11271 " sleep 999\n"11325 " echo hello\n"
11272 "end script");11326 " echo $$ >\"%s\"\n"
11327 " exec sleep 999\n"
11328 "end script", pid_file));
11329
11330 CREATE_FILE (confdir, "session-end.conf", job);
1127311331
11274 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11332 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1127511333
@@ -11282,10 +11340,11 @@
11282 /* Force reset */11340 /* Force reset */
11283 test_user_mode = FALSE;11341 test_user_mode = FALSE;
1128411342
11285 TEST_EQ (timed_waitpid (upstart_pid, TEST_QUIESCE_KILL_PHASE), upstart_pid);11343 TEST_EQ (timed_waitpid (upstart_pid, 1+TEST_QUIESCE_KILL_PHASE), upstart_pid);
1128611344
11287 /* Should not now be running */11345 /* Should not now be running */
11288 TEST_EQ (kill (upstart_pid, 0), -1);11346 TEST_EQ (kill (upstart_pid, 0), -1);
11347 TEST_EQ (errno, ESRCH);
1128911348
11290 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",11349 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
11291 logdir,11350 logdir,
@@ -11302,19 +11361,36 @@
11302 sessiondir, (int)upstart_pid));11361 sessiondir, (int)upstart_pid));
11303 unlink (session_file);11362 unlink (session_file);
1130411363
11364 file = fopen (pid_file, "r");
11365 TEST_NE_P (file, NULL);
11366 TEST_EQ (fscanf (file, "%d", &job_pid), 1);
11367 fclose (file);
11368
11369 /* pid should be running since Upstart won't have signalled it
11370 * to stop (since it started as a result of session-end being
11371 * emitted _after_ the job pids were sent SIGTERM).
11372 */
11373 TEST_EQ (kill (job_pid, SIGKILL), 0);
11374
11375 assert0 (unlink (pid_file));
11376
11305 DELETE_FILE (confdir, "session-end.conf");11377 DELETE_FILE (confdir, "session-end.conf");
1130611378
11307 /*******************************************************************/11379 /*******************************************************************/
11308 TEST_FEATURE ("system shutdown: one job which starts on session-end and ignores SIGTERM");11380 TEST_FEATURE ("system shutdown: one job which starts on session-end and ignores SIGTERM");
1130911381
11310 CREATE_FILE (confdir, "session-end-term.conf",11382 TEST_FILENAME (pid_file);
11311 "start on session-end\n"11383
11312 "\n"11384 job = NIH_MUST (nih_sprintf (NULL, "start on session-end\n"
11313 "script\n"11385 "\n"
11314 " trap '' TERM\n"11386 "script\n"
11315 " echo hello\n"11387 " trap '' TERM\n"
11316 " sleep 999\n"11388 " echo hello\n"
11317 "end script");11389 " echo $$ >\"%s\"\n"
11390 " exec sleep 999\n"
11391 "end script", pid_file));
11392
11393 CREATE_FILE (confdir, "session-end-term.conf", job);
1131811394
11319 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11395 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1132011396
@@ -11327,10 +11403,11 @@
11327 /* Force reset */11403 /* Force reset */
11328 test_user_mode = FALSE;11404 test_user_mode = FALSE;
1132911405
11330 TEST_EQ (timed_waitpid (upstart_pid, TEST_QUIESCE_KILL_PHASE), upstart_pid);11406 TEST_EQ (timed_waitpid (upstart_pid, 1+TEST_QUIESCE_KILL_PHASE), upstart_pid);
1133111407
11332 /* Should not now be running */11408 /* Should not now be running */
11333 TEST_EQ (kill (upstart_pid, 0), -1);11409 TEST_EQ (kill (upstart_pid, 0), -1);
11410 TEST_EQ (errno, ESRCH);
1133411411
11335 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",11412 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
11336 logdir,11413 logdir,
@@ -11347,6 +11424,17 @@
11347 sessiondir, (int)upstart_pid));11424 sessiondir, (int)upstart_pid));
11348 unlink (session_file);11425 unlink (session_file);
1134911426
11427 /* kill job pid if not already dead */
11428 file = fopen (pid_file, "r");
11429 TEST_NE_P (file, NULL);
11430 TEST_EQ (fscanf (file, "%d", &job_pid), 1);
11431 fclose (file);
11432
11433 /* pid should still be running */
11434 TEST_EQ (kill (job_pid, SIGKILL), 0);
11435
11436 assert0 (unlink (pid_file));
11437
11350 DELETE_FILE (confdir, "session-end-term.conf");11438 DELETE_FILE (confdir, "session-end-term.conf");
1135111439
11352 /*******************************************************************/11440 /*******************************************************************/
@@ -11357,17 +11445,20 @@
11357 CREATE_FILE (confdir, "long-running-term.conf",11445 CREATE_FILE (confdir, "long-running-term.conf",
11358 "script\n"11446 "script\n"
11359 " trap '' TERM\n"11447 " trap '' TERM\n"
11360 " sleep 999\n"11448 " exec sleep 999\n"
11361 "end script");11449 "end script");
1136211450
11363 CREATE_FILE (confdir, "session-end-term.conf",11451 TEST_FILENAME (pid_file);
11364 "start on session-end\n"11452
11365 "\n"11453 job = NIH_MUST (nih_sprintf (NULL, "start on session-end\n"
11366 "script\n"11454 "\n"
11367 " trap '' TERM\n"11455 "script\n"
11368 " sleep 999\n"11456 " trap '' TERM\n"
11369 "end script");11457 " echo $$ >\"%s\"\n"
1137011458 " exec sleep 999\n"
11459 "end script", pid_file));
11460
11461 CREATE_FILE (confdir, "session-end-term.conf", job);
1137111462
11372 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11463 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1137311464
@@ -11382,21 +11473,39 @@
11382 TEST_EQ (lines, 1);11473 TEST_EQ (lines, 1);
11383 nih_free (output);11474 nih_free (output);
1138411475
11476 job_pid = job_to_pid ("long-running-term");
11477 TEST_NE (job_pid, -1);
11478
11385 /* Trigger shutdown */11479 /* Trigger shutdown */
11386 assert0 (kill (upstart_pid, SIGTERM));11480 assert0 (kill (upstart_pid, SIGTERM));
1138711481
11388 /* Force reset */11482 /* Force reset */
11389 test_user_mode = FALSE;11483 test_user_mode = FALSE;
1139011484
11391 TEST_EQ (timed_waitpid (upstart_pid, TEST_QUIESCE_KILL_PHASE), upstart_pid);11485 TEST_EQ (timed_waitpid (upstart_pid, 1+TEST_QUIESCE_KILL_PHASE), upstart_pid);
1139211486
11393 /* Should not now be running */11487 /* Should not now be running */
11394 TEST_EQ (kill (upstart_pid, 0), -1);11488 TEST_EQ (kill (upstart_pid, 0), -1);
11489 TEST_EQ (errno, ESRCH);
1139511490
11396 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",11491 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
11397 sessiondir, (int)upstart_pid));11492 sessiondir, (int)upstart_pid));
11398 unlink (session_file);11493 unlink (session_file);
1139911494
11495 /* the long-running job pid should no longer exist */
11496 kill (job_pid, SIGKILL);
11497 TEST_EQ (errno, ESRCH);
11498
11499 file = fopen (pid_file, "r");
11500 TEST_NE_P (file, NULL);
11501 TEST_EQ (fscanf (file, "%d", &job_pid), 1);
11502 fclose (file);
11503
11504 /* .... but the session-end job pid should still be running */
11505 TEST_EQ (kill (job_pid, SIGKILL), 0);
11506
11507 assert0 (unlink (pid_file));
11508
11400 DELETE_FILE (confdir, "long-running-term.conf");11509 DELETE_FILE (confdir, "long-running-term.conf");
11401 DELETE_FILE (confdir, "session-end-term.conf");11510 DELETE_FILE (confdir, "session-end-term.conf");
1140211511
@@ -11449,6 +11558,9 @@
11449 TEST_EQ (lines, 1);11558 TEST_EQ (lines, 1);
11450 nih_free (output);11559 nih_free (output);
1145111560
11561 job_pid = job_to_pid ("long-running");
11562 TEST_NE (job_pid, -1);
11563
11452 upstart = upstart_open (NULL);11564 upstart = upstart_open (NULL);
11453 TEST_NE_P (upstart, NULL);11565 TEST_NE_P (upstart, NULL);
1145411566
@@ -11465,11 +11577,16 @@
1146511577
11466 /* Should not now be running */11578 /* Should not now be running */
11467 TEST_EQ (kill (upstart_pid, 0), -1);11579 TEST_EQ (kill (upstart_pid, 0), -1);
11580 TEST_EQ (errno, ESRCH);
1146811581
11469 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",11582 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
11470 sessiondir, (int)upstart_pid));11583 sessiondir, (int)upstart_pid));
11471 unlink (session_file);11584 unlink (session_file);
1147211585
11586 /* pid should no longer exist */
11587 TEST_EQ (kill (job_pid, SIGKILL), -1);
11588 TEST_EQ (errno, ESRCH);
11589
11473 DELETE_FILE (confdir, "long-running.conf");11590 DELETE_FILE (confdir, "long-running.conf");
1147411591
11475 /*******************************************************************/11592 /*******************************************************************/
@@ -11484,13 +11601,16 @@
11484 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11601 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1148511602
11486 cmd = nih_sprintf (NULL, "%s start %s 2>&1",11603 cmd = nih_sprintf (NULL, "%s start %s 2>&1",
11487 get_initctl (), "long-running");11604 get_initctl (), "long-running-term");
11488 TEST_NE_P (cmd, NULL);11605 TEST_NE_P (cmd, NULL);
1148911606
11490 RUN_COMMAND (NULL, cmd, &output, &lines);11607 RUN_COMMAND (NULL, cmd, &output, &lines);
11491 TEST_EQ (lines, 1);11608 TEST_EQ (lines, 1);
11492 nih_free (output);11609 nih_free (output);
1149311610
11611 job_pid = job_to_pid ("long-running-term");
11612 TEST_NE (job_pid, -1);
11613
11494 upstart = upstart_open (NULL);11614 upstart = upstart_open (NULL);
11495 TEST_NE_P (upstart, NULL);11615 TEST_NE_P (upstart, NULL);
1149611616
@@ -11507,23 +11627,32 @@
1150711627
11508 /* Should not now be running */11628 /* Should not now be running */
11509 TEST_EQ (kill (upstart_pid, 0), -1);11629 TEST_EQ (kill (upstart_pid, 0), -1);
11630 TEST_EQ (errno, ESRCH);
1151011631
11511 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",11632 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
11512 sessiondir, (int)upstart_pid));11633 sessiondir, (int)upstart_pid));
11513 unlink (session_file);11634 unlink (session_file);
1151411635
11636 /* pid should no longer exist */
11637 TEST_EQ (kill (job_pid, SIGKILL), -1);
11638 TEST_EQ (errno, ESRCH);
11639
11515 DELETE_FILE (confdir, "long-running-term.conf");11640 DELETE_FILE (confdir, "long-running-term.conf");
1151611641
11517 /*******************************************************************/11642 /*******************************************************************/
11518 TEST_FEATURE ("session shutdown: one job which starts on session-end");11643 TEST_FEATURE ("session shutdown: one job which starts on session-end");
1151911644
11520 CREATE_FILE (confdir, "session-end.conf",11645 TEST_FILENAME (pid_file);
11521 "start on session-end\n"11646
11522 "\n"11647 job = NIH_MUST (nih_sprintf (NULL, "start on session-end\n"
11523 "script\n"11648 "\n"
11524 " echo hello\n"11649 "script\n"
11525 " sleep 999\n"11650 " echo hello\n"
11526 "end script");11651 " echo $$ >\"%s\"\n"
11652 " exec sleep 999\n"
11653 "end script", pid_file));
11654
11655 CREATE_FILE (confdir, "session-end.conf", job);
1152711656
11528 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11657 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1152911658
@@ -11555,6 +11684,17 @@
11555 TEST_EQ (fclose (file), 0);11684 TEST_EQ (fclose (file), 0);
11556 assert0 (unlink (logfile));11685 assert0 (unlink (logfile));
1155711686
11687 file = fopen (pid_file, "r");
11688 TEST_NE_P (file, NULL);
11689 TEST_EQ (fscanf (file, "%d", &job_pid), 1);
11690 fclose (file);
11691
11692 /* pid should no longer exist */
11693 TEST_EQ (kill (job_pid, SIGKILL), -1);
11694 TEST_EQ (errno, ESRCH);
11695
11696 assert0 (unlink (pid_file));
11697
11558 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",11698 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
11559 sessiondir, (int)upstart_pid));11699 sessiondir, (int)upstart_pid));
11560 unlink (session_file);11700 unlink (session_file);
@@ -11564,14 +11704,18 @@
11564 /*******************************************************************/11704 /*******************************************************************/
11565 TEST_FEATURE ("session shutdown: one job which starts on session-end");11705 TEST_FEATURE ("session shutdown: one job which starts on session-end");
1156611706
11567 CREATE_FILE (confdir, "session-end-term.conf",11707 TEST_FILENAME (pid_file);
11568 "start on session-end\n"11708
11569 "\n"11709 job = NIH_MUST (nih_sprintf (NULL, "start on session-end\n"
11570 "script\n"11710 "\n"
11571 " trap '' TERM\n"11711 "script\n"
11572 " echo hello\n"11712 " trap '' TERM\n"
11573 " sleep 999\n"11713 " echo hello\n"
11574 "end script");11714 " echo $$ >\"%s\"\n"
11715 " exec sleep 999\n"
11716 "end script", pid_file));
11717
11718 CREATE_FILE (confdir, "session-end-term.conf", job);
1157511719
11576 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11720 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1157711721
@@ -11603,6 +11747,17 @@
11603 TEST_EQ (fclose (file), 0);11747 TEST_EQ (fclose (file), 0);
11604 assert0 (unlink (logfile));11748 assert0 (unlink (logfile));
1160511749
11750 file = fopen (pid_file, "r");
11751 TEST_NE_P (file, NULL);
11752 TEST_EQ (fscanf (file, "%d", &job_pid), 1);
11753 fclose (file);
11754
11755 /* pid should no longer exist */
11756 TEST_EQ (kill (job_pid, SIGKILL), -1);
11757 TEST_EQ (errno, ESRCH);
11758
11759 assert0 (unlink (pid_file));
11760
11606 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",11761 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
11607 sessiondir, (int)upstart_pid));11762 sessiondir, (int)upstart_pid));
11608 unlink (session_file);11763 unlink (session_file);
@@ -11620,13 +11775,17 @@
11620 " sleep 999\n"11775 " sleep 999\n"
11621 "end script");11776 "end script");
1162211777
11623 CREATE_FILE (confdir, "session-end-term.conf",11778 TEST_FILENAME (pid_file);
11624 "start on session-end\n"11779
11625 "\n"11780 job = NIH_MUST (nih_sprintf (NULL, "start on session-end\n"
11626 "script\n"11781 "\n"
11627 " trap '' TERM\n"11782 "script\n"
11628 " sleep 999\n"11783 " trap '' TERM\n"
11629 "end script");11784 " echo $$ >\"%s\"\n"
11785 " sleep 999\n"
11786 "end script", pid_file));
11787
11788 CREATE_FILE (confdir, "session-end-term.conf", job);
1163011789
11631 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11790 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1163211791
@@ -11638,6 +11797,9 @@
11638 TEST_EQ (lines, 1);11797 TEST_EQ (lines, 1);
11639 nih_free (output);11798 nih_free (output);
1164011799
11800 job_pid = job_to_pid ("long-running-term");
11801 TEST_NE (job_pid, -1);
11802
11641 upstart = upstart_open (NULL);11803 upstart = upstart_open (NULL);
11642 TEST_NE_P (upstart, NULL);11804 TEST_NE_P (upstart, NULL);
1164311805
@@ -11659,6 +11821,21 @@
11659 sessiondir, (int)upstart_pid));11821 sessiondir, (int)upstart_pid));
11660 unlink (session_file);11822 unlink (session_file);
1166111823
11824 /* pid should no longer exist */
11825 TEST_EQ (kill (job_pid, SIGKILL), -1);
11826 TEST_EQ (errno, ESRCH);
11827
11828 file = fopen (pid_file, "r");
11829 TEST_NE_P (file, NULL);
11830 TEST_EQ (fscanf (file, "%d", &job_pid), 1);
11831 fclose (file);
11832
11833 /* pid should no longer exist */
11834 TEST_EQ (kill (job_pid, SIGKILL), -1);
11835 TEST_EQ (errno, ESRCH);
11836
11837 assert0 (unlink (pid_file));
11838
11662 DELETE_FILE (confdir, "long-running-term.conf");11839 DELETE_FILE (confdir, "long-running-term.conf");
11663 DELETE_FILE (confdir, "session-end-term.conf");11840 DELETE_FILE (confdir, "session-end-term.conf");
1166411841

Subscribers

People subscribed via source and target branches