chiark / gitweb /
journalctl: show systemd messages about unit for -u
[elogind.git] / src / journal / journalctl.c
index 3682329e4688f93ff416ad222ef5b69e2729836c..65114b2ff8a219711c56d5d1adc4ba9bf41f5d7e 100644 (file)
@@ -38,6 +38,7 @@
 #include <systemd/sd-journal.h>
 
 #include "log.h"
 #include <systemd/sd-journal.h>
 
 #include "log.h"
+#include "logs-show.h"
 #include "util.h"
 #include "path-util.h"
 #include "build.h"
 #include "util.h"
 #include "path-util.h"
 #include "build.h"
@@ -76,7 +77,7 @@ static usec_t arg_interval = DEFAULT_FSS_INTERVAL_USEC;
 static usec_t arg_since, arg_until;
 static bool arg_since_set = false, arg_until_set = false;
 static const char *arg_unit = NULL;
 static usec_t arg_since, arg_until;
 static bool arg_since_set = false, arg_until_set = false;
 static const char *arg_unit = NULL;
-static const char *arg_unit_type = NULL;
+static bool arg_unit_system;
 static const char *arg_field = NULL;
 static bool arg_catalog = false;
 static bool arg_reverse = false;
 static const char *arg_field = NULL;
 static bool arg_catalog = false;
 static bool arg_reverse = false;
@@ -187,8 +188,8 @@ static int parse_argv(int argc, char *argv[]) {
                 { "cursor",       required_argument, NULL, 'c'              },
                 { "since",        required_argument, NULL, ARG_SINCE        },
                 { "until",        required_argument, NULL, ARG_UNTIL        },
                 { "cursor",       required_argument, NULL, 'c'              },
                 { "since",        required_argument, NULL, ARG_SINCE        },
                 { "until",        required_argument, NULL, ARG_UNTIL        },
-                { "user-unit",    required_argument, NULL, ARG_USER_UNIT    },
                 { "unit",         required_argument, NULL, 'u'              },
                 { "unit",         required_argument, NULL, 'u'              },
+                { "user-unit",    required_argument, NULL, ARG_USER_UNIT    },
                 { "field",        required_argument, NULL, 'F'              },
                 { "catalog",      no_argument,       NULL, 'x'              },
                 { "list-catalog", no_argument,       NULL, ARG_LIST_CATALOG },
                 { "field",        required_argument, NULL, 'F'              },
                 { "catalog",      no_argument,       NULL, 'x'              },
                 { "list-catalog", no_argument,       NULL, ARG_LIST_CATALOG },
@@ -419,14 +420,14 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_until_set = true;
                         break;
 
                         arg_until_set = true;
                         break;
 
-                case ARG_USER_UNIT:
+                case 'u':
                         arg_unit = optarg;
                         arg_unit = optarg;
-                        arg_unit_type = "_SYSTEMD_USER_UNIT=";
+                        arg_unit_system = true;
                         break;
 
                         break;
 
-                case 'u':
+                case ARG_USER_UNIT:
                         arg_unit = optarg;
                         arg_unit = optarg;
-                        arg_unit_type = "_SYSTEMD_UNIT=";
+                        arg_unit_system = false;
                         break;
 
                 case '?':
                         break;
 
                 case '?':
@@ -604,16 +605,12 @@ static int add_unit(sd_journal *j) {
         if (!u)
                 return log_oom();
 
         if (!u)
                 return log_oom();
 
-        m = strappend(arg_unit_type, u);
-
-        if (!m)
-                return log_oom();
-
-        r = sd_journal_add_match(j, m, strlen(m));
-        if (r < 0) {
-                log_error("Failed to add match: %s", strerror(-r));
+        if (arg_unit_system)
+                r = add_matches_for_unit(j, u);
+        else
+                r = add_matches_for_user_unit(j, u, getuid());
+        if (r < 0)
                 return r;
                 return r;
-        }
 
         return 0;
 }
 
         return 0;
 }