]> git.proxmox.com Git - mirror_lxc.git/commitdiff
coccinelle: use standard exit identifiers
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 9 Feb 2019 10:23:54 +0000 (11:23 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 9 Feb 2019 10:23:54 +0000 (11:23 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
13 files changed:
coccinelle/exit.cocci [new file with mode: 0644]
src/lxc/attach.c
src/lxc/cmd/lxc_init.c
src/lxc/storage/nbd.c
src/lxc/tools/arguments.c
src/lxc/tools/lxc_autostart.c
src/tests/aa.c
src/tests/cgpath.c
src/tests/list.c
src/tests/locktests.c
src/tests/may_control.c
src/tests/snapshot.c
src/tests/startone.c

diff --git a/coccinelle/exit.cocci b/coccinelle/exit.cocci
new file mode 100644 (file)
index 0000000..8b81600
--- /dev/null
@@ -0,0 +1,16 @@
+@@
+@@
+- exit(0);
++ exit(EXIT_SUCCESS);
+@@
+@@
+- _exit(0);
++ _exit(EXIT_SUCCESS);
+@@
+@@
+- exit(1);
++ exit(EXIT_FAILURE);
+@@
+@@
+- _exit(1);
++ _exit(EXIT_FAILURE);
index df9dda02eb45755ea07eec0951c8fa67bd1d67cf..eb5ae74600911f1f89fe63dd964ad54266e6fd32 100644 (file)
@@ -1521,7 +1521,7 @@ int lxc_attach(const char *name, const char *lxcpath,
 
        /* The rest is in the hands of the initial and the attached process. */
        lxc_proc_put_context_info(init_ctx);
-       _exit(0);
+       _exit(EXIT_SUCCESS);
 }
 
 int lxc_attach_run_command(void *payload)
index 7b94f37b6e3952697d890537d08e57f44e42665d..d9ba40b8d88af1e592d3052d944006752c773059 100644 (file)
@@ -459,13 +459,13 @@ __noreturn static void print_usage_exit(const struct option longopts[])
 {
        fprintf(stderr, "Usage: lxc-init [-n|--name=NAME] [-h|--help] [--usage] [--version]\n\
                [-q|--quiet] [-P|--lxcpath=LXCPATH]\n");
-       exit(0);
+       exit(EXIT_SUCCESS);
 }
 
 __noreturn static void print_version_exit(void)
 {
        printf("%s\n", LXC_VERSION);
-       exit(0);
+       exit(EXIT_SUCCESS);
 }
 
 static void print_help(void)
index 09990467ad9749a49780259b72c4b667e9e2c4c2..6c59bacf0bda5731090e99e0bd10b74a26348cbb 100644 (file)
@@ -208,13 +208,13 @@ static int do_attach_nbd(void *d)
 
        if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) {
                SYSERROR("Error blocking signals for nbd watcher");
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        sfd = signalfd(-1, &mask, 0);
        if (sfd == -1) {
                SYSERROR("Error opening signalfd for nbd task");
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        if (prctl(PR_SET_PDEATHSIG, prctl_arg(SIGHUP), prctl_arg(0),
@@ -231,7 +231,7 @@ static int do_attach_nbd(void *d)
                        if (fdsi.ssi_signo == SIGHUP) {
                                /* container has exited */
                                nbd_detach(nbd);
-                               exit(0);
+                               exit(EXIT_SUCCESS);
                        } else if (fdsi.ssi_signo == SIGCHLD) {
                                int status;
 
@@ -241,7 +241,7 @@ static int do_attach_nbd(void *d)
                                        if ((WIFEXITED(status) && WEXITSTATUS(status) != 0) ||
                                                        WIFSIGNALED(status)) {
                                                nbd_detach(nbd);
-                                               exit(1);
+                                               exit(EXIT_FAILURE);
                                        }
                                }
                        }
@@ -255,7 +255,7 @@ static int do_attach_nbd(void *d)
 
        execlp("qemu-nbd", "qemu-nbd", "-c", nbd, path, (char *)NULL);
        SYSERROR("Error executing qemu-nbd");
-       _exit(1);
+       _exit(EXIT_FAILURE);
 }
 
 static bool clone_attach_nbd(const char *nbd, const char *path)
@@ -304,7 +304,7 @@ static void nbd_detach(const char *path)
 
        execlp("qemu-nbd", "qemu-nbd", "-d", path, (char *)NULL);
        SYSERROR("Error executing qemu-nbd");
-       _exit(1);
+       _exit(EXIT_FAILURE);
 }
 
 /*
index f335f62250bf9a980bfd664cb2af0758201d8457..859a9fbc3323fe66549e177d32e7632d500a3463 100644 (file)
@@ -135,13 +135,13 @@ __noreturn static void print_usage_exit(const struct option longopts[],
        }
 
        fprintf(stderr, "\n");
-       exit(0);
+       exit(EXIT_SUCCESS);
 }
 
 __noreturn static void print_version_exit()
 {
        printf("%s\n", lxc_get_version());
-       exit(0);
+       exit(EXIT_SUCCESS);
 }
 
 __noreturn static void print_help_exit(const struct lxc_arguments *args,
index d6f3cb126ed982995d76fe811be3a275c078116f..ccac42b1c5f11fc6309d1e97af4ede9a84937507 100644 (file)
@@ -512,7 +512,7 @@ int main(int argc, char *argv[])
        free(containers);
 
        if (failed == count)
-               exit(1);        /* Total failure */
+               exit(EXIT_FAILURE);     /* Total failure */
        else if (failed > 0)
                exit(2);        /* Partial failure */
 
index 7a83e8e17fab2defff72424dc3760f43638041a8..69808b6f3b8a5bb3167a436f6302c5c41b93cfcb 100644 (file)
@@ -154,7 +154,7 @@ int main(int argc, char *argv[])
        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)) {
@@ -190,9 +190,9 @@ int main(int argc, char *argv[])
        c->stop(c);
 
        try_to_remove();
-       exit(0);
+       exit(EXIT_SUCCESS);
 
 err:
        try_to_remove();
-       exit(1);
+       exit(EXIT_FAILURE);
 }
index de999417c32e61b4a0bfc4412a43b57728d175a2..f4e246943e109b716ee71b14e4470c345ecf985a 100644 (file)
@@ -184,7 +184,7 @@ int main()
         * pam_cgroup */
        if (geteuid() != 0) {
                TSTERR("requires privilege");
-               exit(0);
+               exit(EXIT_SUCCESS);
        }
 
        #if TEST_ALREADY_RUNNING_CT
index 37f910e61f3ef5c4862f32b31edfc267947dd370..293835756c6c1480066b631f08b2d2cfd510cd79 100644 (file)
@@ -99,5 +99,5 @@ int main(int argc, char *argv[])
        test_list_func(lxcpath, "Active:", list_active_containers);
        test_list_func(lxcpath, "All:", list_all_containers);
 
-       exit(0);
+       exit(EXIT_SUCCESS);
 }
index cfec5f1bad4e62f4ba0fa8e252c45a3f00b033f8..74cd48541c5933e506fc83f9026fc15b1a2e6e0d 100644 (file)
@@ -37,46 +37,46 @@ static void test_two_locks(void)
        char c;
 
        if (pipe(p) < 0)
-               exit(1);
+               exit(EXIT_FAILURE);
 
        if ((pid = fork()) < 0)
-               exit(1);
+               exit(EXIT_FAILURE);
 
        if (pid == 0) {
                if (read(p[0], &c, 1) < 0) {
                        perror("read");
-                       exit(1);
+                       exit(EXIT_FAILURE);
                }
 
                l = lxc_newlock("/tmp", "lxctest-sem");
                if (!l) {
                        fprintf(stderr, "%d: child: failed to create lock\n", __LINE__);
-                       exit(1);
+                       exit(EXIT_FAILURE);
                }
 
                if (lxclock(l, 0) < 0) {
                        fprintf(stderr, "%d: child: failed to grab lock\n", __LINE__);
-                       exit(1);
+                       exit(EXIT_FAILURE);
                }
 
                fprintf(stderr, "%d: child: grabbed lock\n", __LINE__);
-               exit(0);
+               exit(EXIT_SUCCESS);
        }
 
        l = lxc_newlock("/tmp", "lxctest-sem");
        if (!l) {
                fprintf(stderr, "%d: failed to create lock\n", __LINE__);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        if (lxclock(l, 0) < 0) {
                fprintf(stderr, "%d; failed to get lock\n", __LINE__);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        if (write(p[1], "a", 1) < 0) {
                perror("write");
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        sleep(3);
@@ -87,13 +87,13 @@ static void test_two_locks(void)
                        printf("%d exited normally with exit code %d\n", pid,
                                WEXITSTATUS(status));
                        if (WEXITSTATUS(status) != 0)
-                               exit(1);
+                               exit(EXIT_FAILURE);
                } else
                        printf("%d did not exit normally\n", pid);
                return;
        } else if (ret < 0) {
                perror("waitpid");
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        kill(pid, SIGKILL);
@@ -112,26 +112,26 @@ int main(int argc, char *argv[])
        lock = lxc_newlock(NULL, NULL);
        if (!lock) {
                fprintf(stderr, "%d: failed to get unnamed lock\n", __LINE__);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        ret = lxclock(lock, 0);
        if (ret) {
                fprintf(stderr, "%d: failed to take unnamed lock (%d)\n", __LINE__, ret);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        ret = lxcunlock(lock);
        if (ret) {
                fprintf(stderr, "%d: failed to put unnamed lock (%d)\n", __LINE__, ret);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
        lxc_putlock(lock);
 
        lock = lxc_newlock("/var/lib/lxc", mycontainername);
        if (!lock) {
                fprintf(stderr, "%d: failed to get lock\n", __LINE__);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        struct stat sb;
@@ -141,7 +141,7 @@ int main(int argc, char *argv[])
        if (ret != 0) {
                fprintf(stderr, "%d: filename %s not created\n", __LINE__,
                        pathname);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
        lxc_putlock(lock);
 
index 2930deb2ad9687b1f3b5080cf8a6be81b065f12a..88437140d94a9e8e372b92330c636cec43ada8dd 100644 (file)
@@ -24,7 +24,7 @@
 static void usage(const char *me)
 {
        printf("Usage: %s name [lxcpath]\n", me);
-       exit(0);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char *argv[])
index 1b7d7ab448baa4b54a9a6c31350866e21202747d..e62230bc2fb50f3e93abc83c9ac51bac96c29bae 100644 (file)
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
        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)) {
@@ -188,12 +188,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);
 }
index a69c3c9ea61b6ada56d3f9293de0602cac5fdbaa..de9af07f8f420db41abef907de013faa3a2148f9 100644 (file)
@@ -170,13 +170,13 @@ int main(int argc, char *argv[])
 
        if (!lxc_container_get(c)) {
                fprintf(stderr, "%d: failed to get extra ref to container\n", __LINE__);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        c->want_daemonize(c, true);
        if (!c->startl(c, 0, NULL)) {
                fprintf(stderr, "%d: %s failed to start\n", __LINE__, c->name);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        sleep(3);