]> git.proxmox.com Git - mirror_lxc.git/commitdiff
tests: cleanup shortlived.c
author2xsec <dh48.jeong@samsung.com>
Tue, 3 Jul 2018 09:24:26 +0000 (18:24 +0900)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 3 Jul 2018 10:44:46 +0000 (12:44 +0200)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/tests/shortlived.c

index 2a039a2f392b9db952cd7b4a71bcb4adfc6f96af..da2f04f769acf4b471fca39ea7fce20ef5d1a12b 100644 (file)
@@ -46,10 +46,12 @@ 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) {
@@ -58,12 +60,15 @@ 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);
 }
 
@@ -76,24 +81,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);
 }
 
@@ -124,6 +135,7 @@ int main(int argc, char *argv[])
        log.prefix = "shortlived";
        log.quiet = false;
        log.lxcpath = NULL;
+
        if (lxc_log_init(&log))
                exit(EXIT_FAILURE);
 
@@ -256,11 +268,13 @@ out:
                if (fd >= 0) {
                        char buf[4096];
                        ssize_t buflen;
+
                        while ((buflen = read(fd, buf, 1024)) > 0) {
                                buflen = write(STDERR_FILENO, buf, buflen);
                                if (buflen <= 0)
                                        break;
                        }
+
                        close(fd);
                }
        }