]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/tests/snapshot.c
github: Update for main branch
[mirror_lxc.git] / src / tests / snapshot.c
index ed5643a7ab493bb3c963f047a809378e370d204b..dfbf78e4591ad5a18faf68062c3a0bf02b641703 100644 (file)
@@ -16,6 +16,9 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
+
+#include "config.h"
+
 #include <lxc/lxccontainer.h>
 
 #include <errno.h>
@@ -23,7 +26,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/stat.h>
-#include "lxc/lxc.h"
+#include "lxc.h"
 
 #define MYNAME "snapxxx1"
 #define MYNAME2 "snapxxx3"
 static void try_to_remove(void)
 {
        struct lxc_container *c;
+
        c = lxc_container_new(RESTNAME, NULL);
        if (c) {
                c->snapshot_destroy_all(c);
                if (c->is_defined(c))
                        c->destroy(c);
+
                lxc_container_put(c);
        }
+
        c = lxc_container_new(MYNAME2, NULL);
        if (c) {
                c->destroy_with_snapshots(c);
                lxc_container_put(c);
        }
+
        c = lxc_container_new(MYNAME, NULL);
        if (c) {
                c->snapshot_destroy_all(c);
                if (c->is_defined(c))
                        c->destroy(c);
+
                lxc_container_put(c);
        }
 }
@@ -66,25 +74,30 @@ int main(int argc, char *argv[])
                template = argv[1];
 
        try_to_remove();
+
        c = lxc_container_new(MYNAME, NULL);
        if (!c) {
                fprintf(stderr, "%s: %d: failed to load first container\n", __FILE__, __LINE__);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        if (c->is_defined(c)) {
                fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
                (void) c->destroy_with_snapshots(c);
        }
+
        if (!c->set_config_item(c, "lxc.net.0.type", "empty")) {
                fprintf(stderr, "%s: %d: failed to set network type\n", __FILE__, __LINE__);
                goto err;
        }
+
        c->save_config(c, NULL);
+
        if (!c->createl(c, template, NULL, NULL, 0, NULL)) {
                fprintf(stderr, "%s: %d: failed to create %s container\n", __FILE__, __LINE__, template);
                goto err;
        }
+
        c->load_config(c, NULL);
 
        if (c->snapshot(c, NULL) != 0) {
@@ -110,13 +123,14 @@ int main(int argc, char *argv[])
                fprintf(stderr, "%s: %d: failed listing containers\n", __FILE__, __LINE__);
                goto err;
        }
+
        if (strcmp(s->name, "snap0") != 0) {
                fprintf(stderr, "%s: %d: snapshot had bad name\n", __FILE__, __LINE__);
                goto err;
        }
-       for (i=0; i<n; i++) {
+
+       for (i=0; i<n; i++)
                s[i].free(&s[i]);
-       }
        free(s);
 
        if (!c->snapshot_restore(c, "snap0", RESTNAME)) {
@@ -152,13 +166,14 @@ int main(int argc, char *argv[])
                fprintf(stderr, "%s: %d: failed listing containers\n", __FILE__, __LINE__);
                goto err;
        }
+
        if (strcmp(s->name, "snap0") != 0) {
                fprintf(stderr, "%s: %d: snapshot had bad name\n", __FILE__, __LINE__);
                goto err;
        }
-       for (i=0; i<n; i++) {
+
+       for (i=0; i<n; i++)
                s[i].free(&s[i]);
-       }
        free(s);
 
        if (!c2->snapshot_restore(c2, "snap0", NULL)) {
@@ -176,11 +191,12 @@ good:
        try_to_remove();
 
        printf("All tests passed\n");
-       exit(0);
+       exit(EXIT_SUCCESS);
+
 err:
        lxc_container_put(c);
        try_to_remove();
 
        fprintf(stderr, "Exiting on error\n");
-       exit(1);
+       exit(EXIT_FAILURE);
 }