]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tests: cleanup startone.c
author2xsec <dh48.jeong@samsung.com>
Tue, 3 Jul 2018 09:26:40 +0000 (18:26 +0900)
committer2xsec <dh48.jeong@samsung.com>
Tue, 3 Jul 2018 09:26:40 +0000 (18:26 +0900)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/tests/startone.c

index d8e82be8134de6e998960e879262904ff9b9c9cf..86cdf4d5864cd36d49ebfcd6c96878ae03646dee 100644 (file)
@@ -39,24 +39,30 @@ static int destroy_container(void)
                perror("fork");
                return -1;
        }
+
        if (pid == 0) {
                execlp("lxc-destroy", "lxc-destroy", "-f", "-n", MYNAME, NULL);
                exit(EXIT_FAILURE);
        }
+
 again:
        ret = waitpid(pid, &status, 0);
        if (ret == -1) {
                if (errno == EINTR)
                        goto again;
+
                perror("waitpid");
                return -1;
        }
+
        if (ret != pid)
                goto again;
+
        if (!WIFEXITED(status))  { // did not exit normally
                fprintf(stderr, "%d: lxc-create exited abnormally\n", __LINE__);
                return -1;
        }
+
        return WEXITSTATUS(status);
 }
 
@@ -69,24 +75,30 @@ static int create_container(void)
                perror("fork");
                return -1;
        }
+
        if (pid == 0) {
                execlp("lxc-create", "lxc-create", "-t", "busybox", "-n", MYNAME, NULL);
                exit(EXIT_FAILURE);
        }
+
 again:
        ret = waitpid(pid, &status, 0);
        if (ret == -1) {
                if (errno == EINTR)
                        goto again;
+
                perror("waitpid");
                return -1;
        }
+
        if (ret != pid)
                goto again;
+
        if (!WIFEXITED(status))  { // did not exit normally
                fprintf(stderr, "%d: lxc-create exited abnormally\n", __LINE__);
                return -1;
        }
+
        return WEXITSTATUS(status);
 }
 
@@ -100,6 +112,7 @@ int main(int argc, char *argv[])
        int len;
 
        ret = 1;
+
        /* test a real container */
        c = lxc_container_new(MYNAME, NULL);
        if (!c) {
@@ -167,6 +180,7 @@ int main(int argc, char *argv[])
        }
 
        sleep(3);
+
        s = c->state(c);
        if (!s || strcmp(s, "RUNNING")) {
                fprintf(stderr, "%d: %s is in state %s, not in RUNNING.\n", __LINE__, c->name, s ? s : "undefined");
@@ -192,7 +206,7 @@ int main(int argc, char *argv[])
                goto out;
        }
 
-    sprintf(buf, "XXX");
+       sprintf(buf, "XXX");
        len = c->get_cgroup_item(c, "freezer.state", buf, 200);
        if (len <= 0 || (strcmp(buf, "FREEZING\n") && strcmp(buf, "FROZEN\n"))) {
                fprintf(stderr, "%d: not able to get freezer.state (len %d buf %s)\n", __LINE__, len, buf);