Clean up: Coding style conformance adjustments in lttng-crash.c
[lttng-tools.git] / src / bin / lttng-crash / lttng-crash.c
index c3a8b778925d1de9bed8d191b1eec1324f982d2b..45fe71be7b67aadbb83a7b3a1d357a21171571a7 100644 (file)
@@ -34,6 +34,7 @@
 #include <dirent.h>
 #include <byteswap.h>
 #include <inttypes.h>
+#include <stdbool.h>
 
 #include <version.h>
 #include <lttng/lttng.h>
@@ -1062,12 +1063,14 @@ int delete_trace(const char *trace_path)
        trace_dir = opendir(trace_path);
        if (!trace_dir) {
                PERROR("Cannot open '%s' path", trace_path);
-               return -1;
+               ret = -errno;
+               goto end;
        }
        trace_dir_fd = dirfd(trace_dir);
        if (trace_dir_fd < 0) {
                PERROR("dirfd");
-               return -1;
+               ret = -errno;
+               goto end;
        }
 
        while ((entry = readdir(trace_dir))) {
@@ -1136,7 +1139,8 @@ int view_trace(const char *viewer_path, const char *trace_path)
  */
 int main(int argc, char *argv[])
 {
-       int ret, has_warning = 0;
+       int ret;
+       bool has_warning = false;
        const char *output_path = NULL;
        char tmppath[] = "/tmp/lttng-crash-XXXXXX";
 
@@ -1144,9 +1148,10 @@ int main(int argc, char *argv[])
 
        ret = parse_args(argc, argv);
        if (ret > 0) {
-               exit(EXIT_SUCCESS);
+               goto end;
        } else if (ret < 0) {
-               exit(EXIT_FAILURE);
+               has_warning = true;
+               goto end;
        }
 
        if (opt_output_path) {
@@ -1154,34 +1159,38 @@ int main(int argc, char *argv[])
                ret = mkdir(output_path, S_IRWXU | S_IRWXG);
                if (ret) {
                        PERROR("mkdir");
-                       exit(EXIT_FAILURE);
+                       has_warning = true;
+                       goto end;
                }
        } else {
                output_path = mkdtemp(tmppath);
                if (!output_path) {
                        PERROR("mkdtemp");
-                       exit(EXIT_FAILURE);
+                       has_warning = true;
+                       goto end;
                }
        }
 
        ret = extract_trace_recursive(output_path, input_path);
        if (ret < 0) {
-               exit(EXIT_FAILURE);
+               has_warning = true;
+               goto end;
        } else if (ret > 0) {
-               has_warning = 1;
+               /* extract_trace_recursive reported a warning. */
+               has_warning = true;
        }
        if (!opt_output_path) {
                /* View trace */
                ret = view_trace(opt_viewer_path, output_path);
-               if (ret)
-                       has_warning = 1;
-
+               if (ret) {
+                       has_warning = true;
+               }
                /* unlink temporary trace */
                ret = delete_trace(output_path);
-               if (ret)
-                       has_warning = 1;
+               if (ret) {
+                       has_warning = true;
+               }
        }
-       if (has_warning)
-               exit(EXIT_FAILURE);
-       exit(EXIT_SUCCESS);
+end:
+       exit(has_warning ? EXIT_FAILURE : EXIT_SUCCESS);
 }
This page took 0.02634 seconds and 5 git commands to generate.