daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From 134a85fc4fa6d1c3209e11415b2610147e2e1aac Mon Sep 17 00:00:00 2001
923a60
From: Lennart Poettering <lennart@poettering.net>
923a60
Date: Mon, 18 May 2015 23:50:34 +0200
923a60
Subject: [PATCH] journalctl: only have a single exit path from main()
923a60
923a60
That way we can be sure we execute the destructors properly, and can be
923a60
valgrind-clean.
923a60
923a60
Cherry-picked from: 909dea0c7ced0042fa3acd8cd05f5007a2cf2cea
923a60
Related: #1318994
923a60
---
923a60
 src/journal/journalctl.c | 51 +++++++++++++++++++++-------------------
923a60
 1 file changed, 27 insertions(+), 24 deletions(-)
923a60
923a60
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
923a60
index c7a19f236c..31da357c1b 100644
923a60
--- a/src/journal/journalctl.c
923a60
+++ b/src/journal/journalctl.c
923a60
@@ -532,7 +532,7 @@ static int parse_argv(int argc, char *argv[]) {
923a60
                         arg_boot = true;
923a60
 
923a60
                         if (optarg) {
923a60
-                                r =  parse_boot_descriptor(optarg, &arg_boot_id, &arg_boot_offset);
923a60
+                                r = parse_boot_descriptor(optarg, &arg_boot_id, &arg_boot_offset);
923a60
                                 if (r < 0) {
923a60
                                         log_error("Failed to parse boot descriptor '%s'", optarg);
923a60
                                         return -EINVAL;
923a60
@@ -1929,12 +1929,12 @@ int main(int argc, char *argv[]) {
923a60
         if (r < 0) {
923a60
                 log_error_errno(r, "Failed to open %s: %m",
923a60
                                 arg_directory ? arg_directory : arg_file ? "files" : "journal");
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         r = access_check(j);
923a60
         if (r < 0)
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
 
923a60
         if (arg_action == ACTION_VERIFY) {
923a60
                 r = verify(j);
923a60
@@ -1943,7 +1943,8 @@ int main(int argc, char *argv[]) {
923a60
 
923a60
         if (arg_action == ACTION_PRINT_HEADER) {
923a60
                 journal_print_header(j);
923a60
-                return EXIT_SUCCESS;
923a60
+                r = 0;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         if (arg_action == ACTION_DISK_USAGE) {
923a60
@@ -1952,11 +1953,11 @@ int main(int argc, char *argv[]) {
923a60
 
923a60
                 r = sd_journal_get_usage(j, &bytes);
923a60
                 if (r < 0)
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
 
923a60
                 printf("Archived and active journals take up %s on disk.\n",
923a60
                        format_bytes(sbytes, sizeof(sbytes), bytes));
923a60
-                return EXIT_SUCCESS;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         if (arg_action == ACTION_VACUUM) {
923a60
@@ -1976,7 +1977,7 @@ int main(int argc, char *argv[]) {
923a60
                         }
923a60
                 }
923a60
 
923a60
-                return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         if (arg_action == ACTION_LIST_BOOTS) {
923a60
@@ -1995,11 +1996,11 @@ int main(int argc, char *argv[]) {
923a60
          * It may need to seek the journal to find parent boot IDs. */
923a60
         r = add_boot(j);
923a60
         if (r < 0)
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
 
923a60
         r = add_dmesg(j);
923a60
         if (r < 0)
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
 
923a60
         r = add_units(j);
923a60
         strv_free(arg_system_units);
923a60
@@ -2007,25 +2008,25 @@ int main(int argc, char *argv[]) {
923a60
 
923a60
         if (r < 0) {
923a60
                 log_error_errno(r, "Failed to add filter for units: %m");
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         r = add_syslog_identifier(j);
923a60
         if (r < 0) {
923a60
                 log_error_errno(r, "Failed to add filter for syslog identifiers: %m");
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         r = add_priorities(j);
923a60
         if (r < 0) {
923a60
                 log_error_errno(r, "Failed to add filter for priorities: %m");
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         r = add_matches(j, argv + optind);
923a60
         if (r < 0) {
923a60
                 log_error_errno(r, "Failed to add filters: %m");
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         if (_unlikely_(log_get_max_level() >= LOG_DEBUG)) {
923a60
@@ -2042,13 +2043,13 @@ int main(int argc, char *argv[]) {
923a60
                 r = sd_journal_set_data_threshold(j, 0);
923a60
                 if (r < 0) {
923a60
                         log_error("Failed to unset data size threshold");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
 
923a60
                 r = sd_journal_query_unique(j, arg_field);
923a60
                 if (r < 0) {
923a60
                         log_error_errno(r, "Failed to query unique data objects: %m");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
 
923a60
                 SD_JOURNAL_FOREACH_UNIQUE(j, data, size) {
923a60
@@ -2066,22 +2067,24 @@ int main(int argc, char *argv[]) {
923a60
                         n_shown ++;
923a60
                 }
923a60
 
923a60
-                return EXIT_SUCCESS;
923a60
+                r = 0;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         /* Opening the fd now means the first sd_journal_wait() will actually wait */
923a60
         if (arg_follow) {
923a60
                 r = sd_journal_get_fd(j);
923a60
                 if (r < 0)
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
         }
923a60
 
923a60
         if (arg_cursor || arg_after_cursor) {
923a60
                 r = sd_journal_seek_cursor(j, arg_cursor ?: arg_after_cursor);
923a60
                 if (r < 0) {
923a60
                         log_error_errno(r, "Failed to seek to cursor: %m");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
+
923a60
                 if (!arg_reverse)
923a60
                         r = sd_journal_next_skip(j, 1 + !!arg_after_cursor);
923a60
                 else
923a60
@@ -2099,7 +2102,7 @@ int main(int argc, char *argv[]) {
923a60
                 r = sd_journal_seek_realtime_usec(j, arg_since);
923a60
                 if (r < 0) {
923a60
                         log_error_errno(r, "Failed to seek to date: %m");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
                 r = sd_journal_next(j);
923a60
 
923a60
@@ -2107,7 +2110,7 @@ int main(int argc, char *argv[]) {
923a60
                 r = sd_journal_seek_realtime_usec(j, arg_until);
923a60
                 if (r < 0) {
923a60
                         log_error_errno(r, "Failed to seek to date: %m");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
                 r = sd_journal_previous(j);
923a60
 
923a60
@@ -2115,7 +2118,7 @@ int main(int argc, char *argv[]) {
923a60
                 r = sd_journal_seek_tail(j);
923a60
                 if (r < 0) {
923a60
                         log_error_errno(r, "Failed to seek to tail: %m");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
 
923a60
                 r = sd_journal_previous_skip(j, arg_lines);
923a60
@@ -2124,7 +2127,7 @@ int main(int argc, char *argv[]) {
923a60
                 r = sd_journal_seek_tail(j);
923a60
                 if (r < 0) {
923a60
                         log_error_errno(r, "Failed to seek to tail: %m");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
 
923a60
                 r = sd_journal_previous(j);
923a60
@@ -2133,7 +2136,7 @@ int main(int argc, char *argv[]) {
923a60
                 r = sd_journal_seek_head(j);
923a60
                 if (r < 0) {
923a60
                         log_error_errno(r, "Failed to seek to head: %m");
923a60
-                        return EXIT_FAILURE;
923a60
+                        goto finish;
923a60
                 }
923a60
 
923a60
                 r = sd_journal_next(j);
923a60
@@ -2141,7 +2144,7 @@ int main(int argc, char *argv[]) {
923a60
 
923a60
         if (r < 0) {
923a60
                 log_error_errno(r, "Failed to iterate through journal: %m");
923a60
-                return EXIT_FAILURE;
923a60
+                goto finish;
923a60
         }
923a60
 
923a60
         if (r == 0) {