Unverified Commit 90bc298b by 2xsec Committed by Christian Brauner

tests: cleanup shortlived.c

Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent dd63f0e7
...@@ -46,10 +46,12 @@ static int destroy_container(void) ...@@ -46,10 +46,12 @@ static int destroy_container(void)
perror("fork"); perror("fork");
return -1; return -1;
} }
if (pid == 0) { if (pid == 0) {
execlp("lxc-destroy", "lxc-destroy", "-f", "-n", MYNAME, NULL); execlp("lxc-destroy", "lxc-destroy", "-f", "-n", MYNAME, NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
again: again:
ret = waitpid(pid, &status, 0); ret = waitpid(pid, &status, 0);
if (ret == -1) { if (ret == -1) {
...@@ -58,12 +60,15 @@ again: ...@@ -58,12 +60,15 @@ again:
perror("waitpid"); perror("waitpid");
return -1; return -1;
} }
if (ret != pid) if (ret != pid)
goto again; goto again;
if (!WIFEXITED(status)) { // did not exit normally if (!WIFEXITED(status)) { // did not exit normally
fprintf(stderr, "%d: lxc-create exited abnormally\n", __LINE__); fprintf(stderr, "%d: lxc-create exited abnormally\n", __LINE__);
return -1; return -1;
} }
return WEXITSTATUS(status); return WEXITSTATUS(status);
} }
...@@ -76,24 +81,30 @@ static int create_container(void) ...@@ -76,24 +81,30 @@ static int create_container(void)
perror("fork"); perror("fork");
return -1; return -1;
} }
if (pid == 0) { if (pid == 0) {
execlp("lxc-create", "lxc-create", "-t", "busybox", "-n", MYNAME, NULL); execlp("lxc-create", "lxc-create", "-t", "busybox", "-n", MYNAME, NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
again: again:
ret = waitpid(pid, &status, 0); ret = waitpid(pid, &status, 0);
if (ret == -1) { if (ret == -1) {
if (errno == EINTR) if (errno == EINTR)
goto again; goto again;
perror("waitpid"); perror("waitpid");
return -1; return -1;
} }
if (ret != pid) if (ret != pid)
goto again; goto again;
if (!WIFEXITED(status)) { // did not exit normally if (!WIFEXITED(status)) { // did not exit normally
fprintf(stderr, "%d: lxc-create exited abnormally\n", __LINE__); fprintf(stderr, "%d: lxc-create exited abnormally\n", __LINE__);
return -1; return -1;
} }
return WEXITSTATUS(status); return WEXITSTATUS(status);
} }
...@@ -124,6 +135,7 @@ int main(int argc, char *argv[]) ...@@ -124,6 +135,7 @@ int main(int argc, char *argv[])
log.prefix = "shortlived"; log.prefix = "shortlived";
log.quiet = false; log.quiet = false;
log.lxcpath = NULL; log.lxcpath = NULL;
if (lxc_log_init(&log)) if (lxc_log_init(&log))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -256,11 +268,13 @@ out: ...@@ -256,11 +268,13 @@ out:
if (fd >= 0) { if (fd >= 0) {
char buf[4096]; char buf[4096];
ssize_t buflen; ssize_t buflen;
while ((buflen = read(fd, buf, 1024)) > 0) { while ((buflen = read(fd, buf, 1024)) > 0) {
buflen = write(STDERR_FILENO, buf, buflen); buflen = write(STDERR_FILENO, buf, buflen);
if (buflen <= 0) if (buflen <= 0)
break; break;
} }
close(fd); close(fd);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment