]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal/journalctl.c
tree-wide: use TAKE_PTR() and TAKE_FD() macros
[thirdparty/systemd.git] / src / journal / journalctl.c
index 2cf35f7e669999662a7977dde70db3093802cf3b..bcb75befe1f08990c0d0a03fbfc6cc19b7c190c2 100644 (file)
@@ -316,7 +316,7 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset
 
 static void help(void) {
 
-        pager_open(arg_no_pager, arg_pager_end);
+        (void) pager_open(arg_no_pager, arg_pager_end);
 
         printf("%s [OPTIONS...] [MATCHES...]\n\n"
                "Query the journal.\n\n"
@@ -494,7 +494,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:S:U:t:u:NF:xrM:", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:g:c:S:U:t:u:NF:xrM:", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -921,10 +921,9 @@ static int parse_argv(int argc, char *argv[]) {
                         if (!v)
                                 return log_oom();
 
-                        if (!arg_output_fields) {
-                                arg_output_fields = v;
-                                v = NULL;
-                        } else {
+                        if (!arg_output_fields)
+                                arg_output_fields = TAKE_PTR(v);
+                        else {
                                 r = strv_extend_strv(&arg_output_fields, v, true);
                                 if (r < 0)
                                         return log_oom();
@@ -972,8 +971,7 @@ static int parse_argv(int argc, char *argv[]) {
                 return -EINVAL;
         }
 
-        if (!strv_isempty(arg_system_units) && (arg_journal_type == SD_JOURNAL_CURRENT_USER)) {
-
+        if (!strv_isempty(arg_system_units) && arg_journal_type == SD_JOURNAL_CURRENT_USER) {
                 /* Specifying --user and --unit= at the same time makes no sense (as the former excludes the user
                  * journal, but the latter excludes the system journal, thus resulting in empty output). Let's be nice
                  * to users, and automatically turn --unit= into --user-unit= if combined with --user. */
@@ -1071,7 +1069,7 @@ static int add_matches(sd_journal *j, char **args) {
                         _cleanup_free_ char *p = NULL, *t = NULL, *t2 = NULL, *interpreter = NULL;
                         struct stat st;
 
-                        r = chase_symlinks(*i, NULL, 0, &p);
+                        r = chase_symlinks(*i, NULL, CHASE_TRAIL_SLASH, &p);
                         if (r < 0)
                                 return log_error_errno(r, "Couldn't canonicalize path: %m");
 
@@ -1230,8 +1228,7 @@ static int discover_next_boot(sd_journal *j,
         if (r < 0)
                 return r;
 
-        *ret = next_boot;
-        next_boot = NULL;
+        *ret = TAKE_PTR(next_boot);
 
         return 0;
 }
@@ -1343,8 +1340,7 @@ static int get_boots(
                                 }
                         }
                         LIST_INSERT_AFTER(boot_list, head, tail, current);
-                        tail = current;
-                        current = NULL;
+                        tail = TAKE_PTR(current);
                         count++;
                 }
         }
@@ -1370,7 +1366,7 @@ static int list_boots(sd_journal *j) {
         if (count == 0)
                 return count;
 
-        pager_open(arg_no_pager, arg_pager_end);
+        (void) pager_open(arg_no_pager, arg_pager_end);
 
         /* numbers are one less, but we need an extra char for the sign */
         w = DECIMAL_STR_WIDTH(count - 1) + 1;
@@ -1509,8 +1505,8 @@ static int get_possible_units(
                 }
         }
 
-        *units = found;
-        found = NULL;
+        *units = TAKE_PTR(found);
+
         return 0;
 }
 
@@ -1540,7 +1536,7 @@ static int add_units(sd_journal *j) {
         STRV_FOREACH(i, arg_system_units) {
                 _cleanup_free_ char *u = NULL;
 
-                r = unit_name_mangle(*i, UNIT_NAME_GLOB, &u);
+                r = unit_name_mangle(*i, UNIT_NAME_MANGLE_GLOB | (arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN), &u);
                 if (r < 0)
                         return r;
 
@@ -1585,7 +1581,7 @@ static int add_units(sd_journal *j) {
         STRV_FOREACH(i, arg_user_units) {
                 _cleanup_free_ char *u = NULL;
 
-                r = unit_name_mangle(*i, UNIT_NAME_GLOB, &u);
+                r = unit_name_mangle(*i, UNIT_NAME_MANGLE_GLOB | (arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN), &u);
                 if (r < 0)
                         return r;
 
@@ -2136,7 +2132,7 @@ int main(int argc, char *argv[]) {
                 } else {
                         bool oneline = arg_action == ACTION_LIST_CATALOG;
 
-                        pager_open(arg_no_pager, arg_pager_end);
+                        (void) pager_open(arg_no_pager, arg_pager_end);
 
                         if (optind < argc)
                                 r = catalog_list_items(stdout, database, oneline, argv + optind);
@@ -2241,7 +2237,8 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        r = journal_access_check_and_warn(j, arg_quiet);
+        r = journal_access_check_and_warn(j, arg_quiet,
+                                          !(arg_journal_type == SD_JOURNAL_CURRENT_USER || arg_user_units));
         if (r < 0)
                 goto finish;
 
@@ -2492,7 +2489,7 @@ int main(int argc, char *argv[]) {
                 need_seek = true;
 
         if (!arg_follow)
-                pager_open(arg_no_pager, arg_pager_end);
+                (void) pager_open(arg_no_pager, arg_pager_end);
 
         if (!arg_quiet && (arg_lines != 0 || arg_follow)) {
                 usec_t start, end;
@@ -2641,25 +2638,13 @@ int main(int argc, char *argv[]) {
                                 goto finish;
 
                         n_shown++;
-                        
-                        /* If journalctl take a long time to process messages, and
-                         * during that time journal file rotation occurs, a journalctl
-                         * client will keep those rotated files open until it calls
-                         * sd_journal_process(), which typically happens as a result
-                         * of calling sd_journal_wait() below in the "following" case.
-                         * By periodically calling sd_journal_process() during the
-                         * processing loop we shrink the window of time a client
-                         * instance has open file descriptors for rotated (deleted)
-                         * journal files.
-                         *
-                         * FIXME: This change does not appear to solve the case of a
-                         * "paused" output stream. If somebody is using `journalctl | less`
-                         * and pauses the output, then without a background thread
-                         * periodically listening for inotify delete events and cleaning
-                         * up, journal logs will eventually stop flowing in cases where
-                         * a journal client with enough open files causes the "free"
-                         * disk space threshold to be crossed. 
-                         */
+
+                        /* If journalctl take a long time to process messages, and during that time journal file
+                         * rotation occurs, a journalctl client will keep those rotated files open until it calls
+                         * sd_journal_process(), which typically happens as a result of calling sd_journal_wait() below
+                         * in the "following" case.  By periodically calling sd_journal_process() during the processing
+                         * loop we shrink the window of time a client instance has open file descriptors for rotated
+                         * (deleted) journal files. */
                         if ((n_shown % PROCESS_INOTIFY_INTERVAL) == 0) {
                                 r = sd_journal_process(j);
                                 if (r < 0) {