[CRIU] [PATCH 10/10] zdtm: test pgid is restored fine in nested pidnses
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Tue Jul 4 12:08:09 MSK 2017
1) On restore pgid 29 is first added as shortcut variant through
lookup_replaceable_item for process 27 and then replaced adding
pgid for process 30 which is in aditional pidns.
2) Processes 33..35 first as leaders wait their pgid is received
by 32..34 respectively and only after change the group to their
real pgid.
(pid, sid, pgid, namespaces...)
session04(6, 6, 6,pid)-+-session04(8, 8, 8)---session04(9, 7, 7)
|-session04(10, 6, 6)---session04(11, 11, 11)
|-session04(13, 13, 13)---session04(14, 11, 11)
|-session04(15, 15, 15)
|-session04(17, 17, 17)-+-session04(18, 15, 15)
| `-session04(19, 17, 17,pid)---session04(22, 20, 20)
|-session04(20, 20, 20)
|-session04(23, 6, 6,pid)---session04(25, 20, 20)
|-session04(26, 26, 26)---session04(27, 26, 29)---session04(28, 26, 26,pid)---session04(30, 26, 29)
`-session04(31, 31, 31)-+-session04(32, 31, 33)
|-session04(33, 31, 34)
|-session04(34, 31, 35)
`-session04(35, 31, 36)
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
test/zdtm/static/session04.c | 76 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 73 insertions(+), 3 deletions(-)
diff --git a/test/zdtm/static/session04.c b/test/zdtm/static/session04.c
index 155480f..0ccb982 100644
--- a/test/zdtm/static/session04.c
+++ b/test/zdtm/static/session04.c
@@ -22,12 +22,13 @@ struct process
{
pid_t pid;
pid_t sid;
+ pid_t pgid;
int sks[2];
int dead;
};
struct process *processes;
-int nr_processes = 21;
+int nr_processes = 32;
int current = 0;
static void cleanup()
@@ -46,6 +47,8 @@ enum commands
TEST_DIE,
TEST_GETSID,
TEST_SETNS,
+ TEST_SETPGID,
+ TEST_GETPGID,
};
struct command
@@ -229,6 +232,19 @@ static void handle_command()
if(status == -1)
pr_perror("getsid");
break;
+ case TEST_SETPGID:
+ test_msg("%3d: setpgid(%d, %d)\n", current, cmd.arg1, cmd.arg2);
+ if(setpgid(processes[cmd.arg1].pid, processes[cmd.arg2].pid) == -1) {
+ pr_perror("setpgid");
+ status = -1;
+ }
+ break;
+ case TEST_GETPGID:
+ test_msg("%3d: getpgid()\n", current);
+ status = getpgid(0);
+ if(status == -1)
+ pr_perror("getpgid");
+ break;
case TEST_SETNS:
test_msg("%3d: setns(%d, %d) = %d\n", current,
cmd.arg1, cmd.arg2, processes[cmd.arg1].pid);
@@ -282,7 +298,7 @@ static int send_command(int id, enum commands op, int arg1, int arg2)
goto err;
}
- if (status != -1 && op == TEST_GETSID)
+ if (status != -1 && (op == TEST_GETSID || op == TEST_GETPGID))
return status;
if (status) {
@@ -382,6 +398,42 @@ int main(int argc, char ** argv)
send_command(19, TEST_DIE, 0, 0);
send_command(15, TEST_WAIT, 19, 0);
+ /*
+ * Test replaceable pgid and pgid helper is in right pidns
+ */
+ send_command(1, TEST_FORK, 21, 0);
+ send_command(21, TEST_SETSID, 0, 0);
+ send_command(21, TEST_FORK, 22, 0);
+ send_command(22, TEST_FORK, 23, CLONE_NEWPID);
+ send_command(22, TEST_SETNS, 23, CLONE_NEWPID);
+ send_command(22, TEST_FORK, 24, 0);
+ send_command(22, TEST_SETPGID, 24, 24);
+ send_command(22, TEST_SETPGID, 22, 24);
+ send_command(24, TEST_FORK, 25, 0);
+ send_command(24, TEST_DIE, 0, 0);
+ send_command(22, TEST_WAIT, 24, 0);
+
+ /*
+ * Test leaders wait their group before changing pgid
+ */
+ send_command(1, TEST_FORK, 26, 0);
+ send_command(26, TEST_SETSID, 0, 0);
+ send_command(26, TEST_FORK, 27, 0);
+ send_command(26, TEST_FORK, 28, 0);
+ send_command(26, TEST_FORK, 29, 0);
+ send_command(26, TEST_FORK, 30, 0);
+ send_command(26, TEST_FORK, 31, 0);
+ send_command(26, TEST_SETPGID, 28, 28);
+ send_command(26, TEST_SETPGID, 29, 29);
+ send_command(26, TEST_SETPGID, 30, 30);
+ send_command(26, TEST_SETPGID, 31, 31);
+ send_command(26, TEST_SETPGID, 27, 28);
+ send_command(26, TEST_SETPGID, 28, 29);
+ send_command(26, TEST_SETPGID, 29, 30);
+ send_command(26, TEST_SETPGID, 30, 31);
+ send_command(31, TEST_DIE, 0, 0);
+ send_command(26, TEST_WAIT, 31, 0);
+
for (i = 0; i < nr_processes; i++) {
if (processes[i].dead)
continue;
@@ -393,6 +445,12 @@ int main(int argc, char ** argv)
pr_perror("getsid(%d)", i);
goto err;
}
+
+ processes[i].pgid = send_command(i, TEST_GETPGID, 0, 0);
+ if (processes[i].pgid == -1) {
+ pr_perror("getpgid(%d)", i);
+ goto err;
+ }
}
test_daemon();
@@ -400,7 +458,7 @@ int main(int argc, char ** argv)
test_waitsig();
for (i = 0; i < nr_processes; i++) {
- pid_t sid;
+ pid_t sid, pgid;
if (processes[i].dead)
continue;
@@ -418,6 +476,18 @@ int main(int argc, char ** argv)
i, processes[i].pid, sid, processes[i].sid);
fail_cnt++;
}
+
+ pgid = send_command(i, TEST_GETPGID, 0, 0);
+ if (pgid == -1) {
+ pr_perror("getpgid(%d)", i);
+ goto err;
+ }
+
+ if (pgid != processes[i].pgid) {
+ fail("%d, %d: wrong pgid %d (expected %d)",
+ i, processes[i].pid, pgid, processes[i].pgid);
+ fail_cnt++;
+ }
}
if (fail_cnt)
--
2.9.4
More information about the CRIU
mailing list