From: 2xsec Date: Tue, 3 Jul 2018 09:23:48 +0000 (+0900) Subject: tests: cleanup saveconfig.c X-Git-Tag: lxc-3.1.0~221^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4edca7c7c98363f56f21acde9024cded99b8914;p=thirdparty%2Flxc.git tests: cleanup saveconfig.c Signed-off-by: 2xsec --- diff --git a/src/tests/saveconfig.c b/src/tests/saveconfig.c index 58f4d24b6..c73240223 100644 --- a/src/tests/saveconfig.c +++ b/src/tests/saveconfig.c @@ -37,24 +37,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); } @@ -90,6 +96,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "%d: failed writing config file /tmp/lxctest1\n", __LINE__); goto out; } + rename(LXCPATH "/" MYNAME "/config", LXCPATH "/" MYNAME "/config.bak"); if (!c->save_config(c, NULL)) { fprintf(stderr, "%d: failed writing config file\n", __LINE__); @@ -108,6 +115,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "all lxc_container tests passed for %s\n", c->name); ret = 0; + out: lxc_container_put(c); exit(ret);