Merge lp:~xnox/upstart/cgroup-states into lp:~jamesodhunt/upstart/cgroups

Proposed by Dimitri John Ledkov
Status: Work in progress
Proposed branch: lp:~xnox/upstart/cgroup-states
Merge into: lp:~jamesodhunt/upstart/cgroups
Diff against target: 1234 lines (+343/-197)
10 files modified
init/job.c (+1/-11)
init/job_process.c (+17/-82)
init/tests/test_event.c (+6/-6)
init/tests/test_job.c (+72/-34)
scripts/Makefile.am (+9/-9)
scripts/pyupstart.py (+102/-4)
scripts/tests/test_pyupstart_cgmanager.py (+63/-0)
scripts/tests/test_pyupstart_session_init.py (+0/-26)
scripts/tests/test_pyupstart_system_cgroups.py (+73/-0)
scripts/tests/test_pyupstart_system_init.py (+0/-25)
To merge this branch: bzr merge lp:~xnox/upstart/cgroup-states
Reviewer Review Type Date Requested Status
James Hunt Pending
Review via email: mp+214514@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

This fixes a bunch of test_job and test_job_process test suite failures. Mostly it's adjusting state expectations in the test-suite, but also fixes JOB_PRE_STOP_SETUP -> JOB_PRE_STOP transition and updates the asserts in the job_process (once we are in the process failure handler, the relevant process has completed the setup and thus is in the "full" state, as far as I understand it)

lp:~xnox/upstart/cgroup-states updated
1605. By Dimitri John Ledkov

Actually, it looks like the tests might be broken.

1606. By Dimitri John Ledkov

Extend asserts to setup stages

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

so running under cgmanager in a container i notice that jobs do not progress from *_SETUP -> * states.
Also process tracking with e.g. expect stop did not work it seems (well, i've kill -s CONT a few processes to get the container booting)

I am now leaning to believe that stats in job_process.c (e.g. PROCESS_PRE_STOP) should assert state JOB_PRE_STOP. And that it's buggy behavior for jobs to get stuck in _SETUP state and not transition to the full one. (when cgroups stanza is specified that is)

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

I've tested all but "security" and "pre-stop" processes and they all get cgroups containment now.

lp:~xnox/upstart/cgroup-states updated
1607. By Dimitri John Ledkov

We need to both SIGCONT & switch to next state for 'expect stop' and setup states.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

With -r1607 i get correct transitions from *_SETUP -> * states.

However, expect stop jobs are still stuck in "setup" and do not transition to running. Investigating.

lp:~xnox/upstart/cgroup-states updated
1608. By Dimitri John Ledkov

SIGCONT in setup as well.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Now the states progress to quickly, e.g. we jump to spawning the main process and running, ahead of pre-start process completing, if and only if cgroups stanza is specified in the job.

lp:~xnox/upstart/cgroup-states updated
1609. By Dimitri John Ledkov

Merge pythonic CGManager

1610. By Dimitri John Ledkov

Add pyupstart CGManager tests

1611. By Dimitri John Ledkov

And kaboom!

Unmerged revisions

1611. By Dimitri John Ledkov

And kaboom!

1610. By Dimitri John Ledkov

Add pyupstart CGManager tests

1609. By Dimitri John Ledkov

Merge pythonic CGManager

1608. By Dimitri John Ledkov

SIGCONT in setup as well.

1607. By Dimitri John Ledkov

We need to both SIGCONT & switch to next state for 'expect stop' and setup states.

1606. By Dimitri John Ledkov

Extend asserts to setup stages

1605. By Dimitri John Ledkov

Actually, it looks like the tests might be broken.

1604. By Dimitri John Ledkov

Fix up cgroup-states.

1603. By Dimitri John Ledkov

Remove debug

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'init/job.c'
--- init/job.c 2014-04-04 18:42:18 +0000
+++ init/job.c 2014-04-08 20:51:56 +0000
@@ -278,8 +278,6 @@
278{278{
279 nih_assert (job != NULL);279 nih_assert (job != NULL);
280280
281 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
282
283 if (job->goal == goal)281 if (job->goal == goal)
284 return;282 return;
285283
@@ -348,9 +346,6 @@
348{346{
349 nih_assert (job != NULL);347 nih_assert (job != NULL);
350348
351 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, new state=%s", __func__, __LINE__,
352 job_name (job), job_goal_name (job->goal), job_state_name (job->state), job_state_name (state));
353
354 while (job->state != state) {349 while (job->state != state) {
355 JobState old_state;350 JobState old_state;
356 int unused;351 int unused;
@@ -363,9 +358,6 @@
363 old_state = job->state;358 old_state = job->state;
364 job->state = state;359 job->state = state;
365360
366 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, old state=%s", __func__, __LINE__,
367 job_name (job), job_goal_name (job->goal), job_state_name (job->state), job_state_name (old_state));
368
369 NIH_LIST_FOREACH (control_conns, iter) {361 NIH_LIST_FOREACH (control_conns, iter) {
370 NihListEntry *entry = (NihListEntry *)iter;362 NihListEntry *entry = (NihListEntry *)iter;
371 DBusConnection *conn = (DBusConnection *)entry->data;363 DBusConnection *conn = (DBusConnection *)entry->data;
@@ -673,8 +665,6 @@
673{665{
674 nih_assert (job != NULL);666 nih_assert (job != NULL);
675667
676 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
677
678 switch (job->state) {668 switch (job->state) {
679 case JOB_WAITING:669 case JOB_WAITING:
680 switch (job->goal) {670 switch (job->goal) {
@@ -789,7 +779,7 @@
789 case JOB_PRE_STOP_SETUP:779 case JOB_PRE_STOP_SETUP:
790 switch (job->goal) {780 switch (job->goal) {
791 case JOB_STOP:781 case JOB_STOP:
792 return JOB_STOPPING;782 return JOB_PRE_STOP;
793 case JOB_START:783 case JOB_START:
794 return JOB_PRE_STOP;784 return JOB_PRE_STOP;
795 case JOB_RESPAWN:785 case JOB_RESPAWN:
796786
=== modified file 'init/job_process.c'
--- init/job_process.c 2014-04-04 18:42:18 +0000
+++ init/job_process.c 2014-04-08 20:51:56 +0000
@@ -199,8 +199,6 @@
199199
200 nih_assert (job != NULL);200 nih_assert (job != NULL);
201201
202 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
203
204 proc = job->class->process[process];202 proc = job->class->process[process];
205 nih_assert (proc != NULL);203 nih_assert (proc != NULL);
206 nih_assert (proc->command != NULL);204 nih_assert (proc->command != NULL);
@@ -449,8 +447,6 @@
449 int cgroups_needed = FALSE;447 int cgroups_needed = FALSE;
450#endif /* ENABLE_CGROUPS */448#endif /* ENABLE_CGROUPS */
451449
452 //nih_message ("XXX:%s:%d: ", __func__, __LINE__);
453
454 nih_assert (job != NULL);450 nih_assert (job != NULL);
455 nih_assert (job->class != NULL);451 nih_assert (job->class != NULL);
456 nih_assert (job->log != NULL);452 nih_assert (job->log != NULL);
@@ -950,11 +946,8 @@
950 /* Signal to parent that the (final) setup phase946 /* Signal to parent that the (final) setup phase
951 * is complete.947 * is complete.
952 */948 */
953 nih_message ("XXX:%s:%d: raising SIGSTOP to %s process %s pid %d (state=%s)", __func__, __LINE__,
954 job_name (job), process_name (process), getpid(), job_state_name (job->state));fflush (NULL);
955 raise (SIGSTOP);949 raise (SIGSTOP);
956 }950 }
957 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
958 951
959#endif /* ENABLE_CGROUPS */952#endif /* ENABLE_CGROUPS */
960953
@@ -964,14 +957,11 @@
964 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETGID, 0);957 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETGID, 0);
965 }958 }
966959
967 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
968 if (job_setuid != (uid_t)-1 && setuid (job_setuid) < 0) {960 if (job_setuid != (uid_t)-1 && setuid (job_setuid) < 0) {
969 nih_error_raise_system ();961 nih_error_raise_system ();
970 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETUID, 0);962 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_SETUID, 0);
971 }963 }
972 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
973 }964 }
974 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
975965
976 /* Reset all the signal handlers back to their default handling so966 /* Reset all the signal handlers back to their default handling so
977 * the child isn't unexpectedly ignoring any, and so we won't967 * the child isn't unexpectedly ignoring any, and so we won't
@@ -980,7 +970,6 @@
980 nih_signal_reset ();970 nih_signal_reset ();
981 sigprocmask (SIG_SETMASK, &orig_set, NULL);971 sigprocmask (SIG_SETMASK, &orig_set, NULL);
982972
983 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
984 /* Notes:973 /* Notes:
985 *974 *
986 * - we can't use pause() here since there would then be no way to975 * - we can't use pause() here since there would then be no way to
@@ -1003,7 +992,6 @@
1003 close (fds[1]);992 close (fds[1]);
1004 raise (SIGSTOP);993 raise (SIGSTOP);
1005 }994 }
1006 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
1007995
1008#ifdef ENABLE_CGROUPS996#ifdef ENABLE_CGROUPS
1009 /* Move the pid into the appropriate cgroups now that 997 /* Move the pid into the appropriate cgroups now that
@@ -1022,17 +1010,14 @@
1022 }1010 }
1023#endif /* ENABLE_CGROUPS */1011#endif /* ENABLE_CGROUPS */
10241012
1025 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
1026 /* Set up a process trace if we need to trace forks */1013 /* Set up a process trace if we need to trace forks */
1027 if (trace) {1014 if (trace) {
1028 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
1029 if (ptrace (PTRACE_TRACEME, 0, NULL, 0) < 0) {1015 if (ptrace (PTRACE_TRACEME, 0, NULL, 0) < 0) {
1030 nih_error_raise_system();1016 nih_error_raise_system();
1031 job_process_error_abort (fds[1],1017 job_process_error_abort (fds[1],
1032 JOB_PROCESS_ERROR_PTRACE, 0);1018 JOB_PROCESS_ERROR_PTRACE, 0);
1033 }1019 }
1034 }1020 }
1035 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
10361021
1037 /* Execute the process, if we escape from here it failed */1022 /* Execute the process, if we escape from here it failed */
1038 if (execvp (argv[0], argv) < 0) {1023 if (execvp (argv[0], argv) < 0) {
@@ -1526,9 +1511,6 @@
15261511
1527 nih_assert (pid > 0);1512 nih_assert (pid > 0);
15281513
1529 nih_message ("XXX:%s:%d:pid=%d, event=%x, status=%d", __func__, __LINE__,
1530 pid, event, status);
1531
1532 /* Find the job that an event ocurred for, and identify which of the1514 /* Find the job that an event ocurred for, and identify which of the
1533 * job's process it was. If we don't know about it, then we simply1515 * job's process it was. If we don't know about it, then we simply
1534 * ignore the event.1516 * ignore the event.
@@ -1537,9 +1519,6 @@
1537 if (! job)1519 if (! job)
1538 return;1520 return;
15391521
1540 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s", __func__, __LINE__,
1541 job_name (job), job_goal_name (job->goal), job_state_name (job->state));
1542
1543 /* Check the job's normal exit clauses to see whether this is a failure1522 /* Check the job's normal exit clauses to see whether this is a failure
1544 * worth warning about.1523 * worth warning about.
1545 */1524 */
@@ -1553,7 +1532,6 @@
15531532
1554 switch (event) {1533 switch (event) {
1555 case NIH_CHILD_EXITED:1534 case NIH_CHILD_EXITED:
1556 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1557 /* Child exited; check status to see whether it exited1535 /* Child exited; check status to see whether it exited
1558 * normally (zero) or with a non-zero status.1536 * normally (zero) or with a non-zero status.
1559 */1537 */
@@ -1571,7 +1549,6 @@
1571 break;1549 break;
1572 case NIH_CHILD_KILLED:1550 case NIH_CHILD_KILLED:
1573 case NIH_CHILD_DUMPED:1551 case NIH_CHILD_DUMPED:
1574 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1575 /* Child was killed by a signal, and maybe dumped core. We1552 /* Child was killed by a signal, and maybe dumped core. We
1576 * store the signal value in the higher byte of status (it's1553 * store the signal value in the higher byte of status (it's
1577 * safe to do that) to distinguish it from a normal exit1554 * safe to do that) to distinguish it from a normal exit
@@ -1592,7 +1569,6 @@
1592 job_process_terminated (job, process, status);1569 job_process_terminated (job, process, status);
1593 break;1570 break;
1594 case NIH_CHILD_STOPPED:1571 case NIH_CHILD_STOPPED:
1595 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1596 /* Child was stopped by a signal, make sure it was SIGSTOP1572 /* Child was stopped by a signal, make sure it was SIGSTOP
1597 * and not a tty-related signal.1573 * and not a tty-related signal.
1598 */1574 */
@@ -1608,13 +1584,11 @@
1608 }1584 }
16091585
1610 if (status == SIGSTOP) {1586 if (status == SIGSTOP) {
1611 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1612 job_process_stopped (job, process);1587 job_process_stopped (job, process);
1613 }1588 }
16141589
1615 break;1590 break;
1616 case NIH_CHILD_CONTINUED:1591 case NIH_CHILD_CONTINUED:
1617 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1618 /* Child was continued by a signal.1592 /* Child was continued by a signal.
1619 */1593 */
1620 sig = nih_signal_to_name (status);1594 sig = nih_signal_to_name (status);
@@ -1629,7 +1603,6 @@
1629 }1603 }
1630 break;1604 break;
1631 case NIH_CHILD_TRAPPED:1605 case NIH_CHILD_TRAPPED:
1632 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1633 /* Child received a signal while we were tracing it. This1606 /* Child received a signal while we were tracing it. This
1634 * can be a signal raised inside the kernel as a side-effect1607 * can be a signal raised inside the kernel as a side-effect
1635 * of the trace because the child called fork() or exec();1608 * of the trace because the child called fork() or exec();
@@ -1637,29 +1610,23 @@
1637 */1610 */
1638 if ((job->trace_state == TRACE_NEW)1611 if ((job->trace_state == TRACE_NEW)
1639 && (status == SIGTRAP)) {1612 && (status == SIGTRAP)) {
1640 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1641 job_process_trace_new (job, process);1613 job_process_trace_new (job, process);
1642 } else if ((job->trace_state == TRACE_NEW_CHILD)1614 } else if ((job->trace_state == TRACE_NEW_CHILD)
1643 && (status == SIGSTOP)) {1615 && (status == SIGSTOP)) {
1644 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1645 job_process_trace_new_child (job, process);1616 job_process_trace_new_child (job, process);
1646 } else {1617 } else {
1647 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1648 job_process_trace_signal (job, process, status);1618 job_process_trace_signal (job, process, status);
1649 }1619 }
1650 break;1620 break;
1651 case NIH_CHILD_PTRACE:1621 case NIH_CHILD_PTRACE:
1652 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1653 /* Child called an important syscall that can modify the1622 /* Child called an important syscall that can modify the
1654 * state of the process trace we hold.1623 * state of the process trace we hold.
1655 */1624 */
1656 switch (status) {1625 switch (status) {
1657 case PTRACE_EVENT_FORK:1626 case PTRACE_EVENT_FORK:
1658 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1659 job_process_trace_fork (job, process);1627 job_process_trace_fork (job, process);
1660 break;1628 break;
1661 case PTRACE_EVENT_EXEC:1629 case PTRACE_EVENT_EXEC:
1662 nih_message ("XXX:%s:%d:", __func__, __LINE__);
1663 job_process_trace_exec (job, process);1630 job_process_trace_exec (job, process);
1664 break;1631 break;
1665 default:1632 default:
@@ -1697,10 +1664,6 @@
16971664
1698 nih_assert (job != NULL);1665 nih_assert (job != NULL);
16991666
1700 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, process=%s, status=%d", __func__, __LINE__,
1701 job_name (job), job_goal_name (job->goal), job_state_name (job->state),
1702 process_name (process), status);
1703
1704 switch (process) {1667 switch (process) {
1705 case PROCESS_MAIN:1668 case PROCESS_MAIN:
1706 nih_assert ((job->state == JOB_RUNNING)1669 nih_assert ((job->state == JOB_RUNNING)
@@ -1708,7 +1671,9 @@
1708 || (job->state == JOB_KILLED)1671 || (job->state == JOB_KILLED)
1709 || (job->state == JOB_STOPPING)1672 || (job->state == JOB_STOPPING)
1710 || (job->state == JOB_POST_START)1673 || (job->state == JOB_POST_START)
1674 || (job->state == JOB_POST_START_SETUP)
1711 || (job->state == JOB_PRE_STOP)1675 || (job->state == JOB_PRE_STOP)
1676 || (job->state == JOB_PRE_STOP_SETUP)
1712 || (job->state == JOB_SETUP));1677 || (job->state == JOB_SETUP));
17131678
1714 /* We don't change the state if we're in post-start and there's1679 /* We don't change the state if we're in post-start and there's
@@ -1800,7 +1765,8 @@
1800 stop = TRUE;1765 stop = TRUE;
1801 break;1766 break;
1802 case PROCESS_SECURITY:1767 case PROCESS_SECURITY:
1803 nih_assert (job->state == JOB_SECURITY_SETUP);1768 nih_assert ((job->state == JOB_SECURITY)
1769 || (job->state == JOB_SECURITY_SETUP));
18041770
1805 /* We should always fail the job if the security profile1771 /* We should always fail the job if the security profile
1806 * failed to load1772 * failed to load
@@ -1811,7 +1777,8 @@
1811 }1777 }
1812 break;1778 break;
1813 case PROCESS_PRE_START:1779 case PROCESS_PRE_START:
1814 nih_assert (job->state == JOB_PRE_START_SETUP);1780 nih_assert ((job->state == JOB_PRE_START)
1781 || (job->state == JOB_PRE_START_SETUP));
18151782
1816 /* If the pre-start script is killed or exits with a status1783 /* If the pre-start script is killed or exits with a status
1817 * other than zero, it's always considered a failure since1784 * other than zero, it's always considered a failure since
@@ -1823,7 +1790,8 @@
1823 }1790 }
1824 break;1791 break;
1825 case PROCESS_POST_START:1792 case PROCESS_POST_START:
1826 nih_assert (job->state == JOB_POST_START_SETUP);1793 nih_assert ((job->state == JOB_POST_START)
1794 || (job->state == JOB_POST_START_SETUP));
18271795
1828 /* We always want to change the state when the post-start1796 /* We always want to change the state when the post-start
1829 * script terminates; if the main process is running, we'll1797 * script terminates; if the main process is running, we'll
@@ -1834,7 +1802,8 @@
1834 */1802 */
1835 break;1803 break;
1836 case PROCESS_PRE_STOP:1804 case PROCESS_PRE_STOP:
1837 nih_assert (job->state == JOB_PRE_STOP_SETUP);1805 nih_assert ((job->state == JOB_PRE_STOP)
1806 || (job->state == JOB_PRE_STOP_SETUP));
18381807
1839 /* We always want to change the state when the pre-stop1808 /* We always want to change the state when the pre-stop
1840 * script terminates, we either want to go back into running1809 * script terminates, we either want to go back into running
@@ -1845,7 +1814,8 @@
1845 */1814 */
1846 break;1815 break;
1847 case PROCESS_POST_STOP:1816 case PROCESS_POST_STOP:
1848 nih_assert (job->state == JOB_POST_STOP_SETUP);1817 nih_assert ((job->state == JOB_POST_STOP)
1818 || (job->state == JOB_POST_STOP_SETUP));
18491819
1850 /* If the post-stop script is killed or exits with a status1820 /* If the post-stop script is killed or exits with a status
1851 * other than zero, it's always considered a failure since1821 * other than zero, it's always considered a failure since
@@ -2022,34 +1992,19 @@
2022 break;1992 break;
2023 }1993 }
20241994
2025 nih_message ("XXX:%s:%d: job=%s, process=%s, pid %d (state=%s, goal=%s)", __func__, __LINE__,
2026 job_name (job), process_name (process), job->pid[process], job_state_name (job->state), job_goal_name (job->goal));
2027
2028 /* Any process can stop on a signal, but we only care about the1995 /* Any process can stop on a signal, but we only care about the
2029 * main process when the state is still spawned and any jobs1996 * main process when the state is still spawned and any jobs
2030 * which require (cgroup) setup.1997 * which require (cgroup) setup.
2031 */1998 *
2032 if (! ((process == PROCESS_MAIN && job->state == JOB_SPAWNED) || setup))1999 * Send SIGCONT back and change the state to the next one for
2033 return;
2034
2035 /* Send SIGCONT back and change the state to the next one for
2036 * 'expect stop' jobs and those that require cgroup setup.2000 * 'expect stop' jobs and those that require cgroup setup.
2037 */2001 */
2038 if (job->class->expect == EXPECT_STOP || (job_needs_cgroups (job) && setup)) {2002 if (job->class->expect == EXPECT_STOP && process == PROCESS_MAIN
2039 nih_message ("XXX:%s:%d: sending SIGCONT to %s process %s pid %d (state=%s)", __func__, __LINE__,2003 && (job->state == JOB_SETUP || job->state == JOB_SPAWNED)
2040 job_name (job), process_name (process), job->pid[process], job_state_name (job->state));2004 || (job_needs_cgroups (job) && setup)) {
2041
2042 kill (job->pid[process], SIGCONT);2005 kill (job->pid[process], SIGCONT);
2043 }
2044
2045 if (job->class->expect == EXPECT_STOP && process == PROCESS_MAIN && job->state == JOB_SPAWNED) {
2046 nih_message ("XXX:%s:%d: changing state for job %s process %s pid %d (state=%s)", __func__, __LINE__,
2047 job_name (job), process_name (process), job->pid[process], job_state_name (job->state));
2048
2049 job_change_state (job, job_next_state (job));2006 job_change_state (job, job_next_state (job));
2050 }2007 }
2051
2052 nih_message ("XXX:%s:%d: ", __func__, __LINE__);
2053}2008}
20542009
20552010
@@ -2072,10 +2027,6 @@
2072 nih_assert ((job->trace_state == TRACE_NEW)2027 nih_assert ((job->trace_state == TRACE_NEW)
2073 || (job->trace_state == TRACE_NEW_CHILD));2028 || (job->trace_state == TRACE_NEW_CHILD));
20742029
2075 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, process=%s", __func__, __LINE__,
2076 job_name (job), job_goal_name (job->goal), job_state_name (job->state),
2077 process_name (process));
2078
2079 /* Any process can get us to trace them, but we only care about the2030 /* Any process can get us to trace them, but we only care about the
2080 * main process when the state is still spawned.2031 * main process when the state is still spawned.
2081 */2032 */
@@ -2127,10 +2078,6 @@
2127 nih_assert (job != NULL);2078 nih_assert (job != NULL);
2128 nih_assert (job->trace_state == TRACE_NEW_CHILD);2079 nih_assert (job->trace_state == TRACE_NEW_CHILD);
21292080
2130 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, process=%s", __func__, __LINE__,
2131 job_name (job), job_goal_name (job->goal), job_state_name (job->state),
2132 process_name (process));
2133
2134 /* Any process can get us to trace them, but we only care about the2081 /* Any process can get us to trace them, but we only care about the
2135 * main process when the state is still spawned.2082 * main process when the state is still spawned.
2136 */2083 */
@@ -2176,10 +2123,6 @@
2176{2123{
2177 nih_assert (job != NULL);2124 nih_assert (job != NULL);
21782125
2179 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, process=%s, signum=%d", __func__, __LINE__,
2180 job_name (job), job_goal_name (job->goal), job_state_name (job->state),
2181 process_name (process), signum);
2182
2183 /* Any process can get us to trace them, but we only care about the2126 /* Any process can get us to trace them, but we only care about the
2184 * main process when the state is still spawned.2127 * main process when the state is still spawned.
2185 */2128 */
@@ -2215,10 +2158,6 @@
22152158
2216 nih_assert (job != NULL);2159 nih_assert (job != NULL);
22172160
2218 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, process=%s", __func__, __LINE__,
2219 job_name (job), job_goal_name (job->goal), job_state_name (job->state),
2220 process_name (process));
2221
2222 /* Any process can get us to trace them, but we only care about the2161 /* Any process can get us to trace them, but we only care about the
2223 * main process when the state is still spawned.2162 * main process when the state is still spawned.
2224 */2163 */
@@ -2287,10 +2226,6 @@
2287{2226{
2288 nih_assert (job != NULL);2227 nih_assert (job != NULL);
22892228
2290 nih_message ("XXX:%s:%d:job '%s': goal=%s, state=%s, process=%s", __func__, __LINE__,
2291 job_name (job), job_goal_name (job->goal), job_state_name (job->state),
2292 process_name (process));
2293
2294 /* Any process can get us to trace them, but we only care about the2229 /* Any process can get us to trace them, but we only care about the
2295 * main process when the state is still spawned and we're tracing it.2230 * main process when the state is still spawned and we're tracing it.
2296 */2231 */
22972232
=== modified file 'init/tests/test_event.c'
--- init/tests/test_event.c 2013-01-31 17:23:55 +0000
+++ init/tests/test_event.c 2014-04-08 20:51:56 +0000
@@ -1259,7 +1259,7 @@
1259 job = (Job *)nih_hash_lookup (class->instances, "");1259 job = (Job *)nih_hash_lookup (class->instances, "");
12601260
1261 TEST_EQ (job->goal, JOB_STOP);1261 TEST_EQ (job->goal, JOB_STOP);
1262 TEST_EQ (job->state, JOB_POST_STOP);1262 TEST_EQ (job->state, JOB_POST_STOP_SETUP);
12631263
1264 TEST_GT (job->pid[PROCESS_POST_STOP], 0);1264 TEST_GT (job->pid[PROCESS_POST_STOP], 0);
1265 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);1265 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);
@@ -1335,7 +1335,7 @@
1335 job = (Job *)nih_hash_lookup (class->instances, "");1335 job = (Job *)nih_hash_lookup (class->instances, "");
13361336
1337 TEST_EQ (job->goal, JOB_STOP);1337 TEST_EQ (job->goal, JOB_STOP);
1338 TEST_EQ (job->state, JOB_POST_STOP);1338 TEST_EQ (job->state, JOB_POST_STOP_SETUP);
13391339
1340 TEST_GT (job->pid[PROCESS_POST_STOP], 0);1340 TEST_GT (job->pid[PROCESS_POST_STOP], 0);
1341 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);1341 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);
@@ -1439,7 +1439,7 @@
1439 job = (Job *)nih_hash_lookup (class->instances, "");1439 job = (Job *)nih_hash_lookup (class->instances, "");
14401440
1441 TEST_EQ (job->goal, JOB_STOP);1441 TEST_EQ (job->goal, JOB_STOP);
1442 TEST_EQ (job->state, JOB_POST_STOP);1442 TEST_EQ (job->state, JOB_POST_STOP_SETUP);
14431443
1444 TEST_GT (job->pid[PROCESS_POST_STOP], 0);1444 TEST_GT (job->pid[PROCESS_POST_STOP], 0);
1445 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);1445 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);
@@ -1621,7 +1621,7 @@
1621 job = (Job *)nih_hash_lookup (class->instances, "");1621 job = (Job *)nih_hash_lookup (class->instances, "");
16221622
1623 TEST_EQ (job->goal, JOB_STOP);1623 TEST_EQ (job->goal, JOB_STOP);
1624 TEST_EQ (job->state, JOB_POST_STOP);1624 TEST_EQ (job->state, JOB_POST_STOP_SETUP);
16251625
1626 TEST_GT (job->pid[PROCESS_POST_STOP], 0);1626 TEST_GT (job->pid[PROCESS_POST_STOP], 0);
1627 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);1627 waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);
@@ -1980,7 +1980,7 @@
1980 event_poll ();1980 event_poll ();
19811981
1982 TEST_EQ (job->goal, JOB_STOP);1982 TEST_EQ (job->goal, JOB_STOP);
1983 TEST_EQ (job->state, JOB_POST_STOP);1983 TEST_EQ (job->state, JOB_POST_STOP_SETUP);
1984 TEST_GT (job->pid[PROCESS_POST_STOP], 0);1984 TEST_GT (job->pid[PROCESS_POST_STOP], 0);
1985 TEST_EQ_P (job->blocker, NULL);1985 TEST_EQ_P (job->blocker, NULL);
19861986
@@ -2026,7 +2026,7 @@
2026 event_poll ();2026 event_poll ();
20272027
2028 TEST_EQ (job->goal, JOB_START);2028 TEST_EQ (job->goal, JOB_START);
2029 TEST_EQ (job->state, JOB_PRE_START);2029 TEST_EQ (job->state, JOB_PRE_START_SETUP);
2030 TEST_GT (job->pid[PROCESS_PRE_START], 0);2030 TEST_GT (job->pid[PROCESS_PRE_START], 0);
2031 TEST_EQ_P (job->blocker, NULL);2031 TEST_EQ_P (job->blocker, NULL);
20322032
20332033
=== modified file 'init/tests/test_job.c'
--- init/tests/test_job.c 2013-11-18 16:38:32 +0000
+++ init/tests/test_job.c 2014-04-08 20:51:56 +0000
@@ -1059,10 +1059,10 @@
1059 job->failed_process = PROCESS_INVALID;1059 job->failed_process = PROCESS_INVALID;
1060 job->exit_status = 0;1060 job->exit_status = 0;
10611061
1062 job_change_state (job, JOB_PRE_START);1062 job_change_state (job, JOB_PRE_START_SETUP);
10631063
1064 TEST_EQ (job->goal, JOB_START);1064 TEST_EQ (job->goal, JOB_START);
1065 TEST_EQ (job->state, JOB_PRE_START);1065 TEST_EQ (job->state, JOB_PRE_START_SETUP);
1066 TEST_NE (job->pid[PROCESS_PRE_START], 0);1066 TEST_NE (job->pid[PROCESS_PRE_START], 0);
10671067
1068 waitpid (job->pid[PROCESS_PRE_START], &status, 0);1068 waitpid (job->pid[PROCESS_PRE_START], &status, 0);
@@ -1125,7 +1125,7 @@
1125 job->failed_process = PROCESS_INVALID;1125 job->failed_process = PROCESS_INVALID;
1126 job->exit_status = 0;1126 job->exit_status = 0;
11271127
1128 job_change_state (job, JOB_PRE_START);1128 job_change_state (job, JOB_PRE_START_SETUP);
11291129
1130 TEST_EQ (job->goal, JOB_START);1130 TEST_EQ (job->goal, JOB_START);
1131 TEST_EQ (job->state, JOB_RUNNING);1131 TEST_EQ (job->state, JOB_RUNNING);
@@ -1200,7 +1200,7 @@
1200 job->exit_status = 0;1200 job->exit_status = 0;
12011201
1202 TEST_DIVERT_STDERR (output) {1202 TEST_DIVERT_STDERR (output) {
1203 job_change_state (job, JOB_PRE_START);1203 job_change_state (job, JOB_PRE_START_SETUP);
1204 }1204 }
1205 rewind (output);1205 rewind (output);
12061206
@@ -1284,7 +1284,7 @@
1284 job->failed_process = PROCESS_INVALID;1284 job->failed_process = PROCESS_INVALID;
1285 job->exit_status = 0;1285 job->exit_status = 0;
12861286
1287 job_change_state (job, JOB_SPAWNED);1287 job_change_state (job, JOB_SETUP);
12881288
1289 TEST_EQ (job->goal, JOB_START);1289 TEST_EQ (job->goal, JOB_START);
1290 TEST_EQ (job->state, JOB_RUNNING);1290 TEST_EQ (job->state, JOB_RUNNING);
@@ -1352,7 +1352,7 @@
1352 job->failed_process = PROCESS_INVALID;1352 job->failed_process = PROCESS_INVALID;
1353 job->exit_status = 0;1353 job->exit_status = 0;
13541354
1355 job_change_state (job, JOB_SPAWNED);1355 job_change_state (job, JOB_SETUP);
13561356
1357 TEST_EQ (job->goal, JOB_START);1357 TEST_EQ (job->goal, JOB_START);
1358 TEST_EQ (job->state, JOB_RUNNING);1358 TEST_EQ (job->state, JOB_RUNNING);
@@ -1432,7 +1432,7 @@
1432 job->failed_process = PROCESS_INVALID;1432 job->failed_process = PROCESS_INVALID;
1433 job->exit_status = 0;1433 job->exit_status = 0;
14341434
1435 job_change_state (job, JOB_SPAWNED);1435 job_change_state (job, JOB_SETUP);
14361436
1437 TEST_EQ (job->goal, JOB_START);1437 TEST_EQ (job->goal, JOB_START);
1438 TEST_EQ (job->state, JOB_RUNNING);1438 TEST_EQ (job->state, JOB_RUNNING);
@@ -1507,7 +1507,7 @@
1507 job->failed_process = PROCESS_INVALID;1507 job->failed_process = PROCESS_INVALID;
1508 job->exit_status = 0;1508 job->exit_status = 0;
15091509
1510 job_change_state (job, JOB_SPAWNED);1510 job_change_state (job, JOB_SETUP);
15111511
1512 TEST_EQ (job->goal, JOB_START);1512 TEST_EQ (job->goal, JOB_START);
1513 TEST_EQ (job->state, JOB_RUNNING);1513 TEST_EQ (job->state, JOB_RUNNING);
@@ -1572,7 +1572,7 @@
1572 job->exit_status = 0;1572 job->exit_status = 0;
15731573
1574 TEST_DIVERT_STDERR (output) {1574 TEST_DIVERT_STDERR (output) {
1575 job_change_state (job, JOB_SPAWNED);1575 job_change_state (job, JOB_SETUP);
1576 }1576 }
1577 rewind (output);1577 rewind (output);
15781578
@@ -1658,10 +1658,10 @@
1658 job->failed_process = PROCESS_INVALID;1658 job->failed_process = PROCESS_INVALID;
1659 job->exit_status = 0;1659 job->exit_status = 0;
16601660
1661 job_change_state (job, JOB_SPAWNED);1661 job_change_state (job, JOB_SETUP);
16621662
1663 TEST_EQ (job->goal, JOB_START);1663 TEST_EQ (job->goal, JOB_START);
1664 TEST_EQ (job->state, JOB_SPAWNED);1664 TEST_EQ (job->state, JOB_SETUP);
1665 TEST_NE (job->pid[PROCESS_MAIN], 0);1665 TEST_NE (job->pid[PROCESS_MAIN], 0);
16661666
1667 waitpid (job->pid[PROCESS_MAIN], &status, 0);1667 waitpid (job->pid[PROCESS_MAIN], &status, 0);
@@ -1727,10 +1727,10 @@
1727 job->failed_process = PROCESS_INVALID;1727 job->failed_process = PROCESS_INVALID;
1728 job->exit_status = 0;1728 job->exit_status = 0;
17291729
1730 job_change_state (job, JOB_POST_START);1730 job_change_state (job, JOB_POST_START_SETUP);
17311731
1732 TEST_EQ (job->goal, JOB_START);1732 TEST_EQ (job->goal, JOB_START);
1733 TEST_EQ (job->state, JOB_POST_START);1733 TEST_EQ (job->state, JOB_POST_START_SETUP);
1734 TEST_EQ (job->pid[PROCESS_MAIN], 1);1734 TEST_EQ (job->pid[PROCESS_MAIN], 1);
1735 TEST_NE (job->pid[PROCESS_POST_START], 0);1735 TEST_NE (job->pid[PROCESS_POST_START], 0);
17361736
@@ -1794,7 +1794,7 @@
1794 job->failed_process = PROCESS_INVALID;1794 job->failed_process = PROCESS_INVALID;
1795 job->exit_status = 0;1795 job->exit_status = 0;
17961796
1797 job_change_state (job, JOB_POST_START);1797 job_change_state (job, JOB_POST_START_SETUP);
17981798
1799 TEST_EQ (job->goal, JOB_START);1799 TEST_EQ (job->goal, JOB_START);
1800 TEST_EQ (job->state, JOB_RUNNING);1800 TEST_EQ (job->state, JOB_RUNNING);
@@ -1858,7 +1858,7 @@
1858 job->exit_status = 0;1858 job->exit_status = 0;
18591859
1860 TEST_DIVERT_STDERR (output) {1860 TEST_DIVERT_STDERR (output) {
1861 job_change_state (job, JOB_POST_START);1861 job_change_state (job, JOB_POST_START_SETUP);
1862 }1862 }
1863 rewind (output);1863 rewind (output);
18641864
@@ -2058,10 +2058,10 @@
2058 job->failed_process = PROCESS_INVALID;2058 job->failed_process = PROCESS_INVALID;
2059 job->exit_status = 0;2059 job->exit_status = 0;
20602060
2061 job_change_state (job, JOB_PRE_STOP);2061 job_change_state (job, JOB_PRE_STOP_SETUP);
20622062
2063 TEST_EQ (job->goal, JOB_STOP);2063 TEST_EQ (job->goal, JOB_STOP);
2064 TEST_EQ (job->state, JOB_PRE_STOP);2064 TEST_EQ (job->state, JOB_PRE_STOP_SETUP);
2065 TEST_EQ (job->pid[PROCESS_MAIN], 1);2065 TEST_EQ (job->pid[PROCESS_MAIN], 1);
2066 TEST_NE (job->pid[PROCESS_PRE_STOP], 0);2066 TEST_NE (job->pid[PROCESS_PRE_STOP], 0);
20672067
@@ -2125,7 +2125,7 @@
2125 job->failed_process = PROCESS_INVALID;2125 job->failed_process = PROCESS_INVALID;
2126 job->exit_status = 0;2126 job->exit_status = 0;
21272127
2128 job_change_state (job, JOB_PRE_STOP);2128 job_change_state (job, JOB_PRE_STOP_SETUP);
21292129
2130 TEST_EQ (job->goal, JOB_STOP);2130 TEST_EQ (job->goal, JOB_STOP);
2131 TEST_EQ (job->state, JOB_STOPPING);2131 TEST_EQ (job->state, JOB_STOPPING);
@@ -2198,7 +2198,7 @@
2198 job->failed_process = PROCESS_INVALID;2198 job->failed_process = PROCESS_INVALID;
2199 job->exit_status = 0;2199 job->exit_status = 0;
22002200
2201 job_change_state (job, JOB_PRE_STOP);2201 job_change_state (job, JOB_PRE_STOP_SETUP);
22022202
2203 TEST_EQ (job->goal, JOB_STOP);2203 TEST_EQ (job->goal, JOB_STOP);
2204 TEST_EQ (job->state, JOB_STOPPING);2204 TEST_EQ (job->state, JOB_STOPPING);
@@ -2283,7 +2283,7 @@
2283 job->failed_process = PROCESS_INVALID;2283 job->failed_process = PROCESS_INVALID;
2284 job->exit_status = 0;2284 job->exit_status = 0;
22852285
2286 job_change_state (job, JOB_PRE_STOP);2286 job_change_state (job, JOB_PRE_STOP_SETUP);
22872287
2288 TEST_EQ (job->goal, JOB_STOP);2288 TEST_EQ (job->goal, JOB_STOP);
2289 TEST_EQ (job->state, JOB_STOPPING);2289 TEST_EQ (job->state, JOB_STOPPING);
@@ -2364,7 +2364,7 @@
2364 job->exit_status = 0;2364 job->exit_status = 0;
23652365
2366 TEST_DIVERT_STDERR (output) {2366 TEST_DIVERT_STDERR (output) {
2367 job_change_state (job, JOB_PRE_STOP);2367 job_change_state (job, JOB_PRE_STOP_SETUP);
2368 }2368 }
2369 rewind (output);2369 rewind (output);
23702370
@@ -3039,7 +3039,7 @@
3039 job_change_state (job, JOB_KILLED);3039 job_change_state (job, JOB_KILLED);
30403040
3041 TEST_EQ (job->goal, JOB_STOP);3041 TEST_EQ (job->goal, JOB_STOP);
3042 TEST_EQ (job->state, JOB_POST_STOP);3042 TEST_EQ (job->state, JOB_POST_STOP_SETUP);
3043 TEST_NE (job->pid[PROCESS_POST_STOP], 0);3043 TEST_NE (job->pid[PROCESS_POST_STOP], 0);
30443044
3045 waitpid (job->pid[PROCESS_POST_STOP], &status, 0);3045 waitpid (job->pid[PROCESS_POST_STOP], &status, 0);
@@ -3100,10 +3100,10 @@
3100 job->failed_process = PROCESS_INVALID;3100 job->failed_process = PROCESS_INVALID;
3101 job->exit_status = 0;3101 job->exit_status = 0;
31023102
3103 job_change_state (job, JOB_POST_STOP);3103 job_change_state (job, JOB_POST_STOP_SETUP);
31043104
3105 TEST_EQ (job->goal, JOB_STOP);3105 TEST_EQ (job->goal, JOB_STOP);
3106 TEST_EQ (job->state, JOB_POST_STOP);3106 TEST_EQ (job->state, JOB_POST_STOP_SETUP);
3107 TEST_NE (job->pid[PROCESS_POST_STOP], 0);3107 TEST_NE (job->pid[PROCESS_POST_STOP], 0);
31083108
3109 waitpid (job->pid[PROCESS_POST_STOP], &status, 0);3109 waitpid (job->pid[PROCESS_POST_STOP], &status, 0);
@@ -3168,7 +3168,7 @@
31683168
3169 TEST_FREE_TAG (job);3169 TEST_FREE_TAG (job);
31703170
3171 job_change_state (job, JOB_POST_STOP);3171 job_change_state (job, JOB_POST_STOP_SETUP);
31723172
3173 TEST_FREE (job);3173 TEST_FREE (job);
31743174
@@ -3228,7 +3228,7 @@
3228 TEST_FREE_TAG (job);3228 TEST_FREE_TAG (job);
32293229
3230 TEST_DIVERT_STDERR (output) {3230 TEST_DIVERT_STDERR (output) {
3231 job_change_state (job, JOB_POST_STOP);3231 job_change_state (job, JOB_POST_STOP_SETUP);
3232 }3232 }
3233 rewind (output);3233 rewind (output);
32343234
@@ -4000,11 +4000,20 @@
40004000
40014001
4002 /* Check that the next state if we're starting a starting job is4002 /* Check that the next state if we're starting a starting job is
4003 * security setup.
4004 */
4005 TEST_FEATURE ("with starting job and a goal of start");
4006 job->goal = JOB_START;
4007 job->state = JOB_STARTING;
4008
4009 TEST_EQ (job_next_state (job), JOB_SECURITY_SETUP);
4010
4011 /* Check that the next state if we're starting a security job is
4003 * security.4012 * security.
4004 */4013 */
4005 TEST_FEATURE ("with starting job and a goal of start");4014 TEST_FEATURE ("with security job and a goal of start");
4006 job->goal = JOB_START;4015 job->goal = JOB_START;
4007 job->state = JOB_STARTING;4016 job->state = JOB_SECURITY_SETUP;
40084017
4009 TEST_EQ (job_next_state (job), JOB_SECURITY);4018 TEST_EQ (job_next_state (job), JOB_SECURITY);
40104019
@@ -4015,7 +4024,7 @@
4015 job->goal = JOB_START;4024 job->goal = JOB_START;
4016 job->state = JOB_SECURITY;4025 job->state = JOB_SECURITY;
40174026
4018 TEST_EQ (job_next_state (job), JOB_PRE_START);4027 TEST_EQ (job_next_state (job), JOB_PRE_START_SETUP);
40194028
4020 /* Check that the next state if we're stopping an security job is4029 /* Check that the next state if we're stopping an security job is
4021 * stopping.4030 * stopping.
@@ -4037,11 +4046,20 @@
40374046
40384047
4039 /* Check that the next state if we're starting a pre-start job is4048 /* Check that the next state if we're starting a pre-start job is
4049 * setup.
4050 */
4051 TEST_FEATURE ("with pre-start job and a goal of start");
4052 job->goal = JOB_START;
4053 job->state = JOB_PRE_START;
4054
4055 TEST_EQ (job_next_state (job), JOB_SETUP);
4056
4057 /* Check that the next state if we're starting a pre-start job is
4040 * spawned.4058 * spawned.
4041 */4059 */
4042 TEST_FEATURE ("with pre-start job and a goal of start");4060 TEST_FEATURE ("with pre-start job and a goal of start");
4043 job->goal = JOB_START;4061 job->goal = JOB_START;
4044 job->state = JOB_PRE_START;4062 job->state = JOB_SETUP;
40454063
4046 TEST_EQ (job_next_state (job), JOB_SPAWNED);4064 TEST_EQ (job_next_state (job), JOB_SPAWNED);
40474065
@@ -4057,11 +4075,20 @@
40574075
40584076
4059 /* Check that the next state if we're starting a spawned job is4077 /* Check that the next state if we're starting a spawned job is
4078 * post-start setup.
4079 */
4080 TEST_FEATURE ("with spawned job and a goal of start");
4081 job->goal = JOB_START;
4082 job->state = JOB_SPAWNED;
4083
4084 TEST_EQ (job_next_state (job), JOB_POST_START_SETUP);
4085
4086 /* Check that the next state if we're starting a spawned job is
4060 * post-start.4087 * post-start.
4061 */4088 */
4062 TEST_FEATURE ("with spawned job and a goal of start");4089 TEST_FEATURE ("with spawned job and a goal of start");
4063 job->goal = JOB_START;4090 job->goal = JOB_START;
4064 job->state = JOB_SPAWNED;4091 job->state = JOB_POST_START_SETUP;
40654092
4066 TEST_EQ (job_next_state (job), JOB_POST_START);4093 TEST_EQ (job_next_state (job), JOB_POST_START);
40674094
@@ -4098,7 +4125,7 @@
40984125
40994126
4100 /* Check that the next state if we're stopping a running job is4127 /* Check that the next state if we're stopping a running job is
4101 * pre-stop. This is the "normal" stop process, as called from the4128 * pre-stop setup. This is the "normal" stop process, as called from the
4102 * goal change event.4129 * goal change event.
4103 */4130 */
4104 TEST_FEATURE ("with running job and a goal of stop");4131 TEST_FEATURE ("with running job and a goal of stop");
@@ -4106,6 +4133,17 @@
4106 job->state = JOB_RUNNING;4133 job->state = JOB_RUNNING;
4107 job->pid[PROCESS_MAIN] = 1;4134 job->pid[PROCESS_MAIN] = 1;
41084135
4136 TEST_EQ (job_next_state (job), JOB_PRE_STOP_SETUP);
4137
4138 /* Check that the next state if we're stopping a running job is
4139 * pre-stop.
4140 */
4141 TEST_FEATURE ("with running job and a goal of stop");
4142 job->goal = JOB_STOP;
4143 job->state = JOB_PRE_STOP_SETUP;
4144 job->pid[PROCESS_MAIN] = 1;
4145 job->pid[PROCESS_PRE_STOP] = 2;
4146
4109 TEST_EQ (job_next_state (job), JOB_PRE_STOP);4147 TEST_EQ (job_next_state (job), JOB_PRE_STOP);
41104148
41114149
@@ -4193,7 +4231,7 @@
4193 job->goal = JOB_START;4231 job->goal = JOB_START;
4194 job->state = JOB_KILLED;4232 job->state = JOB_KILLED;
41954233
4196 TEST_EQ (job_next_state (job), JOB_POST_STOP);4234 TEST_EQ (job_next_state (job), JOB_POST_STOP_SETUP);
41974235
41984236
4199 /* Check that the next state if we're stopping a killed job is4237 /* Check that the next state if we're stopping a killed job is
@@ -4203,7 +4241,7 @@
4203 job->goal = JOB_STOP;4241 job->goal = JOB_STOP;
4204 job->state = JOB_KILLED;4242 job->state = JOB_KILLED;
42054243
4206 TEST_EQ (job_next_state (job), JOB_POST_STOP);4244 TEST_EQ (job_next_state (job), JOB_POST_STOP_SETUP);
42074245
42084246
4209 /* Check that the next state if we're starting a post-stop job is4247 /* Check that the next state if we're starting a post-stop job is
42104248
=== modified file 'scripts/Makefile.am'
--- scripts/Makefile.am 2013-11-14 11:42:05 +0000
+++ scripts/Makefile.am 2014-04-08 20:51:56 +0000
@@ -12,24 +12,24 @@
12 upstart-monitor.py12 upstart-monitor.py
1313
14noinst_SCRIPTS = \14noinst_SCRIPTS = \
15 pyupstart.py15 pyupstart.py \
16 pyupstartvars.py
1617
17CLEANFILES = \18CLEANFILES = \
18 pyupstart.py19 pyupstartvars.py pyupstartvars.py.tmp
1920
20EXTRA_DIST = \21EXTRA_DIST = \
21 $(install_scripts) \22 $(install_scripts) \
22 pyupstart.py.in \23 pyupstart.py \
23 tests/__init__.py \24 tests/__init__.py \
24 tests/test_pyupstart_session_init.py \25 tests/test_pyupstart_session_init.py \
25 tests/test_pyupstart_system_init.py26 tests/test_pyupstart_system_init.py
2627
27pyupstart.py: pyupstart.py.in Makefile28pyupstartvars.py: Makefile
28 sed -e 's|[@]built_init_binary[@]|$(UPSTART_BINARY)|g' \29 echo "BUILT_UPSTART = '$(UPSTART_BINARY)'" > pyupstartvars.py.tmp
29 -e 's|[@]built_initctl_binary[@]|$(INITCTL_BINARY)|g' \30 echo "BUILT_INITCTL = '$(INITCTL_BINARY)'" >> pyupstartvars.py.tmp
30 -e 's|[@]built_file_bridge_binary[@]|$(FILE_BRIDGE_BINARY)|g' \31 echo "BUILT_FILE_BRIDGE = '$(FILE_BRIDGE_BINARY)'" >> pyupstartvars.py.tmp
31 $< > $@32 mv pyupstartvars.py.tmp pyupstartvars.py
32 chmod +x $@
3333
34dist_man_MANS = \34dist_man_MANS = \
35 man/initctl2dot.8 \35 man/initctl2dot.8 \
3636
=== renamed file 'scripts/pyupstart.py.in' => 'scripts/pyupstart.py'
--- scripts/pyupstart.py.in 2014-03-05 10:41:18 +0000
+++ scripts/pyupstart.py 2014-04-08 20:51:56 +0000
@@ -20,6 +20,8 @@
20import pyinotify20import pyinotify
21import subprocess21import subprocess
22import shutil22import shutil
23import sys
24import unittest
23import dbus25import dbus
24import dbus.service26import dbus.service
25import dbus.mainloop.glib27import dbus.mainloop.glib
@@ -28,6 +30,11 @@
28from datetime import datetime, timedelta30from datetime import datetime, timedelta
29from gi.repository import GLib31from gi.repository import GLib
3032
33try:
34 from pyupstartvars import *
35except:
36 pass
37
31VERSION = '0.1'38VERSION = '0.1'
32NAME = 'TestUpstart'39NAME = 'TestUpstart'
3340
@@ -36,10 +43,6 @@
36SYSTEM_INITCTL = '/sbin/initctl'43SYSTEM_INITCTL = '/sbin/initctl'
37SYSTEM_FILE_BRIDGE = '/sbin/upstart-file-bridge'44SYSTEM_FILE_BRIDGE = '/sbin/upstart-file-bridge'
3845
39BUILT_UPSTART = '@built_init_binary@'
40BUILT_INITCTL = '@built_initctl_binary@'
41BUILT_FILE_BRIDGE = '@built_file_bridge_binary@'
42
43UPSTART_SESSION_ENV = 'UPSTART_SESSION'46UPSTART_SESSION_ENV = 'UPSTART_SESSION'
44USE_SYSTEM_BINARIES_ENV = 'UPSTART_TEST_USE_SYSTEM_BINARIES'47USE_SYSTEM_BINARIES_ENV = 'UPSTART_TEST_USE_SYSTEM_BINARIES'
4548
@@ -64,6 +67,10 @@
64OBJECT_PATH = '/com/ubuntu/Upstart'67OBJECT_PATH = '/com/ubuntu/Upstart'
65FREEDESKTOP_PROPERTIES = 'org.freedesktop.DBus.Properties'68FREEDESKTOP_PROPERTIES = 'org.freedesktop.DBus.Properties'
6669
70CGM_SOCKET = 'unix:path=/sys/fs/cgroup/cgmanager/sock'
71CGM_INTERFACE_NAME = 'org.linuxcontainers.cgmanager0_0'
72CGM_OBJECT_PATH = '/org/linuxcontainers/cgmanager'
73
67# Maximum number of seconds to wait for Upstart to detect a new job74# Maximum number of seconds to wait for Upstart to detect a new job
68# has been created75# has been created
69JOB_WAIT_SECS = 576JOB_WAIT_SECS = 5
@@ -83,6 +90,7 @@
8390
84#---------------------------------------------------------------------91#---------------------------------------------------------------------
8592
93
86def get_init():94def get_init():
87 """95 """
88 Return full path to an appropriate init daemon binary.96 Return full path to an appropriate init daemon binary.
@@ -95,6 +103,7 @@
95 assert (os.path.exists(binary))103 assert (os.path.exists(binary))
96 return binary104 return binary
97105
106
98def get_initctl():107def get_initctl():
99 """108 """
100 Return full path to an appropriate initctl binary.109 Return full path to an appropriate initctl binary.
@@ -107,6 +116,7 @@
107 assert (os.path.exists(binary))116 assert (os.path.exists(binary))
108 return binary117 return binary
109118
119
110def get_file_bridge():120def get_file_bridge():
111 """121 """
112 Return full path to an appropriate upstart-file-bridge binary.122 Return full path to an appropriate upstart-file-bridge binary.
@@ -119,6 +129,7 @@
119 assert (os.path.exists(binary))129 assert (os.path.exists(binary))
120 return binary130 return binary
121131
132
122def dbus_encode(str):133def dbus_encode(str):
123 """134 """
124 Simulate nih_dbus_path() which Upstart uses to convert135 Simulate nih_dbus_path() which Upstart uses to convert
@@ -195,6 +206,13 @@
195 pass206 pass
196207
197208
209class CGMException(Exception):
210 """
211 An Upstart Exception.
212 """
213 pass
214
215
198class Upstart:216class Upstart:
199 """217 """
200 Upstart Class.218 Upstart Class.
@@ -972,6 +990,7 @@
972 self.stop()990 self.stop()
973 self.logfile.destroy()991 self.logfile.destroy()
974992
993
975class SystemInit(Upstart):994class SystemInit(Upstart):
976995
977 def __init__(self):996 def __init__(self):
@@ -991,6 +1010,59 @@
991 os.system('telinit u')1010 os.system('telinit u')
9921011
9931012
1013class CGManager():
1014
1015 def __init__(self, socket=CGM_SOCKET):
1016 self.socket = socket
1017 self.connection = None
1018 self.remote_object = None
1019 self.proxy = None
1020 self.connect()
1021 with open('/proc/cgroups') as f:
1022 self.all_cgroups = [l.split('\t')[0] for l in
1023 f.readlines() if not l.startswith('#')]
1024
1025 def connect(self, force=False):
1026 """
1027 Connect to CGManager.
1028
1029 @force: if True, connect regardless of whether already
1030 connected.
1031
1032 Notes:
1033 - Raises an CGMException() if already connected.
1034 """
1035 if self.connection and not force:
1036 raise CGMException('Already connected')
1037
1038 # Create appropriate D-Bus connection
1039 self.connection = dbus.connection.Connection(self.socket)
1040 self.remote_object = self.connection.get_object(
1041 object_path=CGM_OBJECT_PATH)
1042 self.proxy = dbus.Interface(self.remote_object, CGM_INTERFACE_NAME)
1043 self.Ping(0)
1044
1045 def api_version(self):
1046 """
1047 Determine api-version of running CGManager.
1048
1049 Returns: API Version as a string.
1050
1051 """
1052 properties = dbus.Interface(self.remote_object, FREEDESKTOP_PROPERTIES)
1053 return int(properties.Get(CGM_INTERFACE_NAME, 'api_version'))
1054
1055 def setup_sandbox(self, sandbox, pid):
1056 for controller in self.all_cgroups:
1057 if sandbox:
1058 self.Create(controller, sandbox)
1059 self.RemoveOnEmpty(controller, sandbox)
1060 self.MovePid(controller, sandbox, pid)
1061
1062 def __getattr__(self, name):
1063 return getattr(self.proxy, name)
1064
1065
994class SessionInit(Upstart):1066class SessionInit(Upstart):
995 """1067 """
996 Create a new Upstart Session or join an existing one.1068 Create a new Upstart Session or join an existing one.
@@ -1164,3 +1236,29 @@
11641236
1165 self.logger.debug("Restarting Session Init")1237 self.logger.debug("Restarting Session Init")
1166 self.proxy.Restart()1238 self.proxy.Restart()
1239
1240def main():
1241 kwargs = {}
1242 format = \
1243 '%(asctime)s:' \
1244 '%(filename)s:' \
1245 '%(name)s:' \
1246 '%(funcName)s:' \
1247 '%(levelname)s:' \
1248 '%(message)s'
1249
1250 kwargs['format'] = format
1251
1252 # We want to see what's happening
1253 kwargs['level'] = logging.DEBUG
1254
1255 logging.basicConfig(**kwargs)
1256
1257 unittest.main(
1258 testRunner=unittest.TextTestRunner(
1259 stream=sys.stdout,
1260 verbosity=2
1261 )
1262 )
1263
1264 sys.exit(0)
11671265
=== added file 'scripts/tests/test_pyupstart_cgmanager.py'
--- scripts/tests/test_pyupstart_cgmanager.py 1970-01-01 00:00:00 +0000
+++ scripts/tests/test_pyupstart_cgmanager.py 2014-04-08 20:51:56 +0000
@@ -0,0 +1,63 @@
1#!/usr/bin/python3
2# -*- coding: utf-8 -*-
3#---------------------------------------------------------------------
4# Copyright © 2014 Canonical Ltd.
5#
6# Author: Dimitri John Ledkov <xnox@ubuntu.com>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2, as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#---------------------------------------------------------------------
21
22#---------------------------------------------------------------------
23# Description: unit-tests for the CGManager() object
24#
25#---------------------------------------------------------------------
26
27import os
28import sys
29import tempfile
30import unittest
31
32base_dir = os.path.abspath(os.path.dirname(__file__))
33module_dir = os.path.normpath(os.path.realpath(base_dir + os.sep + '..'))
34
35# top-level unpacked source directory
36top_srcdir = os.path.normpath(os.path.realpath(module_dir + os.sep + '..'))
37
38# Tell Python where the uninstalled module lives in the source tree
39sys.path.append(module_dir)
40from pyupstart import *
41
42class TestCGManager(unittest.TestCase):
43 def setUp(self):
44 self.cg = CGManager()
45 self.tempfile = tempfile.NamedTemporaryFile(prefix='TestCGManager')
46 self.tempname = os.path.split(self.tempfile.name)[-1]
47
48 def test_init(self):
49 self.assertRaises(CGMException, self.cg.connect, ())
50
51 def test_api_version(self):
52 self.assertEqual(self.cg.api_version(), 2)
53
54 def test_setup_sandbox(self):
55 pid = os.getpid()
56 self.cg.setup_sandbox(self.tempname, pid)
57 with open('/proc/self/cgroup') as f:
58 missing = [l for l in f.readlines() if self.tempname not in l]
59 self.assertEqual(len(missing), 1)
60 self.assertTrue("name=systemd" in missing[0])
61
62if __name__ == '__main__':
63 main()
064
=== modified file 'scripts/tests/test_pyupstart_session_init.py'
--- scripts/tests/test_pyupstart_session_init.py 2014-03-05 10:41:18 +0000
+++ scripts/tests/test_pyupstart_session_init.py 2014-04-08 20:51:56 +0000
@@ -539,31 +539,5 @@
539 self.assertEqual(path, full_job_path)539 self.assertEqual(path, full_job_path)
540 self.stop_session_init()540 self.stop_session_init()
541541
542def main():
543 kwargs = {}
544 format = \
545 '%(asctime)s:' \
546 '%(filename)s:' \
547 '%(name)s:' \
548 '%(funcName)s:' \
549 '%(levelname)s:' \
550 '%(message)s'
551
552 kwargs['format'] = format
553
554 # We want to see what's happening
555 kwargs['level'] = logging.DEBUG
556
557 logging.basicConfig(**kwargs)
558
559 unittest.main(
560 testRunner=unittest.TextTestRunner(
561 stream=sys.stdout,
562 verbosity=2
563 )
564 )
565
566 sys.exit(0)
567
568if __name__ == '__main__':542if __name__ == '__main__':
569 main()543 main()
570544
=== added file 'scripts/tests/test_pyupstart_system_cgroups.py'
--- scripts/tests/test_pyupstart_system_cgroups.py 1970-01-01 00:00:00 +0000
+++ scripts/tests/test_pyupstart_system_cgroups.py 2014-04-08 20:51:56 +0000
@@ -0,0 +1,73 @@
1#!/usr/bin/python3
2# -*- coding: utf-8 -*-
3#---------------------------------------------------------------------
4# Copyright © 2014 Canonical Ltd.
5#
6# Author: Dimitri John Ledkov <xnox@ubuntu.com>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2, as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#---------------------------------------------------------------------
21
22#---------------------------------------------------------------------
23# Description: unit-tests for the CGManager() object
24#
25#---------------------------------------------------------------------
26
27import os
28import sys
29import tempfile
30import unittest
31
32base_dir = os.path.abspath(os.path.dirname(__file__))
33module_dir = os.path.normpath(os.path.realpath(base_dir + os.sep + '..'))
34
35# top-level unpacked source directory
36top_srcdir = os.path.normpath(os.path.realpath(module_dir + os.sep + '..'))
37
38# Tell Python where the uninstalled module lives in the source tree
39sys.path.append(module_dir)
40from pyupstart import *
41from tests.test_pyupstart_system_init import TestSystemUpstart
42
43class TestSystemCGManager(TestSystemUpstart):
44 def setUp(self):
45 self.cg = CGManager()
46 self.tempfile = tempfile.NamedTemporaryFile(prefix='TestSystemCGManager')
47 self.tempname = os.path.split(self.tempfile.name)[-1]
48 self.cg.setup_sandbox(self.tempname, 1)
49 self.sample_job = [ "cgroup {} {}".format(cgroup, self.tempname)
50 for cgroup in self.cg.all_cgroups ]
51 self.sample_job.append('exec upstart-udev-bridge')
52 super().setUp()
53
54 def test_main(self):
55 job = self.upstart.job_create('main', self.sample_job)
56 job.start(wait=True)
57 self._assert_all_match(job.pids()['main'])
58
59 def test_pre_start(self):
60 self.sample_job.append('pre-start exec cat /proc/self/cgroup')
61 job = self.upstart.job_create('pre-start', self.sample_job)
62 job.start()
63 print(job.logfile_name())
64 # Kaboom!
65
66 def _assert_all_match(self, pid):
67 for c in self.cg.all_cgroups:
68 self.assertEqual(
69 self.cg.GetPidCgroup(c, pid),
70 self.tempname)
71
72if __name__ == '__main__':
73 main()
074
=== modified file 'scripts/tests/test_pyupstart_system_init.py'
--- scripts/tests/test_pyupstart_system_init.py 2014-03-10 13:43:50 +0000
+++ scripts/tests/test_pyupstart_system_init.py 2014-04-08 20:51:56 +0000
@@ -167,31 +167,6 @@
167 self.upstart.polling_connect(force=True)167 self.upstart.polling_connect(force=True)
168 self.assertTrue(self.upstart.version())168 self.assertTrue(self.upstart.version())
169169
170def main():
171 kwargs = {}
172 format = \
173 '%(asctime)s:' \
174 '%(filename)s:' \
175 '%(name)s:' \
176 '%(funcName)s:' \
177 '%(levelname)s:' \
178 '%(message)s'
179
180 kwargs['format'] = format
181
182 # We want to see what's happening
183 kwargs['level'] = logging.DEBUG
184
185 logging.basicConfig(**kwargs)
186
187 unittest.main(
188 testRunner=unittest.TextTestRunner(
189 stream=sys.stdout,
190 verbosity=2
191 )
192 )
193
194 sys.exit(0)
195170
196if __name__ == '__main__':171if __name__ == '__main__':
197 main()172 main()

Subscribers

People subscribed via source and target branches