]> git.proxmox.com Git - mirror_lxc.git/commitdiff
tests: expand lxc_raw_clone() tests
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 Dec 2017 16:03:09 +0000 (17:03 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 21 Dec 2017 22:00:20 +0000 (23:00 +0100)
- test CLONE_VFORK
- test CLONE_FILES

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/tests/lxc_raw_clone.c

index 2eadf98e7ef7d91cdb75bcfb5af5fa027c26810d..77902314112911f4652d8a7272de3ee3a160abca 100644 (file)
@@ -116,9 +116,16 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       pid = lxc_raw_clone(CLONE_NEWUSER | CLONE_NEWCGROUP | CLONE_NEWNS |
-                           CLONE_NEWIPC | CLONE_NEWNET | CLONE_NEWIPC |
-                           CLONE_NEWPID | CLONE_NEWUTS);
+       flags |= CLONE_NEWUSER;
+       if (cgns_supported())
+               flags |= CLONE_NEWCGROUP;
+       flags |= CLONE_NEWNS;
+       flags |= CLONE_NEWIPC;
+       flags |= CLONE_NEWNET;
+       flags |= CLONE_NEWIPC;
+       flags |= CLONE_NEWPID;
+       flags |= CLONE_NEWUTS;
+       pid = lxc_raw_clone(flags);
        if (pid < 0) {
                lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_NEWUSER "
                                  "| CLONE_NEWCGROUP | CLONE_NEWNS | "
@@ -138,15 +145,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       flags |= CLONE_NEWUSER;
-       if (cgns_supported())
-               flags |= CLONE_NEWCGROUP;
-       flags |= CLONE_NEWNS;
-       flags |= CLONE_NEWIPC;
-       flags |= CLONE_NEWNET;
-       flags |= CLONE_NEWIPC;
-       flags |= CLONE_NEWPID;
-       flags |= CLONE_NEWUTS;
        pid = lxc_raw_clone(flags);
        if (pid < 0) {
                lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_NEWUSER "
@@ -165,9 +163,81 @@ int main(int argc, char *argv[])
        status = wait_for_pid(pid);
        if (status == 0) {
                lxc_error("%s\n", "Failed to retrieve correct exit status");
+               exit(EXIT_FAILURE);
+       }
+
+       pid = lxc_raw_clone(CLONE_VFORK);
+       if (pid < 0) {
+               lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_VFORK);");
+               exit(EXIT_FAILURE);
+       }
+
+
+       if (pid == 0) {
+               lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
                exit(EXIT_SUCCESS);
        }
 
+       status = wait_for_pid(pid);
+       if (status != 0) {
+               lxc_error("%s\n", "Failed to retrieve correct exit status");
+               exit(EXIT_FAILURE);
+       }
+
+       pid = lxc_raw_clone(CLONE_VFORK);
+       if (pid < 0) {
+               lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_VFORK);");
+               exit(EXIT_FAILURE);
+       }
+
+
+       if (pid == 0) {
+               lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
+               exit(EXIT_FAILURE);
+       }
+
+       status = wait_for_pid(pid);
+       if (status == 0) {
+               lxc_error("%s\n", "Failed to retrieve correct exit status");
+               exit(EXIT_FAILURE);
+       }
+
+       pid = lxc_raw_clone(CLONE_FILES);
+       if (pid < 0) {
+               lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_FILES);");
+               exit(EXIT_FAILURE);
+       }
+
+
+       if (pid == 0) {
+               lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
+               exit(EXIT_SUCCESS);
+       }
+
+       status = wait_for_pid(pid);
+       if (status != 0) {
+               lxc_error("%s\n", "Failed to retrieve correct exit status");
+               exit(EXIT_FAILURE);
+       }
+
+       pid = lxc_raw_clone(CLONE_FILES);
+       if (pid < 0) {
+               lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_FILES);");
+               exit(EXIT_FAILURE);
+       }
+
+
+       if (pid == 0) {
+               lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
+               exit(EXIT_FAILURE);
+       }
+
+       status = wait_for_pid(pid);
+       if (status == 0) {
+               lxc_error("%s\n", "Failed to retrieve correct exit status");
+               exit(EXIT_FAILURE);
+       }
+
        lxc_debug("%s\n", "All lxc_raw_clone() tests successful");
        exit(EXIT_SUCCESS);
 }