]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: turn --unit= in combination with --user into --user-unit= 3109/head
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Apr 2016 09:57:56 +0000 (11:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Apr 2016 17:29:01 +0000 (19:29 +0200)
Let's be nice to users, and let's turn the nonsensical "--unit=… --user" into
"--user-unit=…" which the user more likely meant.

Fixes #1621

src/journal/journalctl.c

index ae62170ae59f0cc18b0f54930e0aaa2d82a8689b..6de3489e1238ee33af17375d8f9783e782a765c1 100644 (file)
@@ -873,6 +873,18 @@ static int parse_argv(int argc, char *argv[]) {
                 return -EINVAL;
         }
 
+        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. */
+                r = strv_extend_strv(&arg_user_units, arg_system_units, true);
+                if (r < 0)
+                        return -ENOMEM;
+
+                arg_system_units = strv_free(arg_system_units);
+        }
+
         return 1;
 }