#include "lxctest.h"
#include "utils.h"
+#ifndef HAVE_STRLCPY
+#include "include/strlcpy.h"
+#endif
+
#define MYNAME "shortlived"
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) {
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);
}
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);
}
char template[sizeof(P_tmpdir"/shortlived_XXXXXX")];
int ret = EXIT_FAILURE;
- strcpy(template, P_tmpdir"/shortlived_XXXXXX");
+ (void)strlcpy(template, P_tmpdir"/shortlived_XXXXXX", sizeof(template));
+
i = lxc_make_tmpfile(template, false);
if (i < 0) {
lxc_error("Failed to create temporary log file for container %s\n", MYNAME);
log.prefix = "shortlived";
log.quiet = false;
log.lxcpath = NULL;
+
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
/* Test whether we can start a really short-lived daemonized container with lxc-init. */
for (i = 0; i < 10; i++) {
/* An container started with lxc-init will always start
- * succesfully unless lxc-init has a bug.
+ * successfully unless lxc-init has a bug.
*/
if (!c->startl(c, 1, NULL)) {
fprintf(stderr, "%d: %s failed to start on %dth iteration\n", __LINE__, c->name, i);
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);
}
}