From: 2xsec Date: Tue, 3 Jul 2018 09:24:26 +0000 (+0900) Subject: tests: cleanup shortlived.c X-Git-Tag: lxc-3.1.0~221^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ce5c91e606070f8d01dbe4e362337708a690290;p=thirdparty%2Flxc.git tests: cleanup shortlived.c Signed-off-by: 2xsec --- diff --git a/src/tests/shortlived.c b/src/tests/shortlived.c index 2a039a2f3..da2f04f76 100644 --- a/src/tests/shortlived.c +++ b/src/tests/shortlived.c @@ -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); } }