chiark / gitweb /
libsystemd-journal: return 0 on success in get_data()
[elogind.git] / src / journal / journalctl.c
index 4c9862fa6ce5a83c080c189bcae6febf09feb753..c90fecd239e5bc641ea01068569a3361d5363f46 100644 (file)
@@ -75,6 +75,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 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;
@@ -100,6 +101,7 @@ static int help(void) {
                "  -c --cursor=CURSOR     Start showing entries from specified cursor\n"
                "  -b --this-boot         Show data only from current boot\n"
                "  -u --unit=UNIT         Show data only from the specified unit\n"
                "  -c --cursor=CURSOR     Start showing entries from specified cursor\n"
                "  -b --this-boot         Show data only from current boot\n"
                "  -u --unit=UNIT         Show data only from the specified unit\n"
+               "     --user-unit=UNIT    Show data only from the specified user session unit\n"
                "  -p --priority=RANGE    Show only messages within the specified priority range\n"
                "  -f --follow            Follow journal\n"
                "  -n --lines[=INTEGER]   Number of journal entries to show\n"
                "  -p --priority=RANGE    Show only messages within the specified priority range\n"
                "  -f --follow            Follow journal\n"
                "  -n --lines[=INTEGER]   Number of journal entries to show\n"
@@ -152,6 +154,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_DISK_USAGE,
                 ARG_SINCE,
                 ARG_UNTIL,
                 ARG_DISK_USAGE,
                 ARG_SINCE,
                 ARG_UNTIL,
+                ARG_USER_UNIT,
                 ARG_LIST_CATALOG,
                 ARG_UPDATE_CATALOG
         };
                 ARG_LIST_CATALOG,
                 ARG_UPDATE_CATALOG
         };
@@ -181,6 +184,7 @@ 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'              },
                 { "field",        required_argument, NULL, 'F'              },
                 { "catalog",      no_argument,       NULL, 'x'              },
                 { "unit",         required_argument, NULL, 'u'              },
                 { "field",        required_argument, NULL, 'F'              },
                 { "catalog",      no_argument,       NULL, 'x'              },
@@ -404,8 +408,14 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_until_set = true;
                         break;
 
                         arg_until_set = true;
                         break;
 
+                case ARG_USER_UNIT:
+                        arg_unit = optarg;
+                        arg_unit_type = "_SYSTEMD_USER_UNIT=";
+                        break;
+
                 case 'u':
                         arg_unit = optarg;
                 case 'u':
                         arg_unit = optarg;
+                        arg_unit_type = "_SYSTEMD_UNIT=";
                         break;
 
                 case '?':
                         break;
 
                 case '?':
@@ -583,7 +593,8 @@ static int add_unit(sd_journal *j) {
         if (!u)
                 return log_oom();
 
         if (!u)
                 return log_oom();
 
-        m = strappend("_SYSTEMD_UNIT=", u);
+        m = strappend(arg_unit_type, u);
+
         if (!m)
                 return log_oom();
 
         if (!m)
                 return log_oom();
 
@@ -859,16 +870,16 @@ static int verify(sd_journal *j) {
 static int access_check(void) {
 
 #ifdef HAVE_ACL
 static int access_check(void) {
 
 #ifdef HAVE_ACL
-        if (access("/var/log/journal", F_OK) < 0 && geteuid() != 0 && in_group("adm") <= 0) {
-                log_error("Unprivileged users can't see messages unless persistent log storage is enabled. Users in the group 'adm' can always see messages.");
+        if (access("/var/log/journal", F_OK) < 0 && geteuid() != 0 && in_group("systemd-journal") <= 0) {
+                log_error("Unprivileged users can't see messages unless persistent log storage is enabled. Users in the group 'systemd-journal' can always see messages.");
                 return -EACCES;
         }
 
                 return -EACCES;
         }
 
-        if (!arg_quiet && geteuid() != 0 && in_group("adm") <= 0)
-                log_warning("Showing user generated messages only. Users in the group 'adm' can see all messages. Pass -q to turn this notice off.");
+        if (!arg_quiet && geteuid() != 0 && in_group("systemd-journal") <= 0)
+                log_warning("Showing user generated messages only. Users in the group 'systemd-journal' can see all messages. Pass -q to turn this notice off.");
 #else
 #else
-        if (geteuid() != 0 && in_group("adm") <= 0) {
-                log_error("No access to messages. Only users in the group 'adm' can see messages.");
+        if (geteuid() != 0 && in_group("systemd-journal") <= 0) {
+                log_error("No access to messages. Only users in the group 'systemd-journal' can see messages.");
                 return -EACCES;
         }
 #endif
                 return -EACCES;
         }
 #endif
@@ -1092,7 +1103,7 @@ int main(int argc, char *argv[]) {
                         int flags;
 
                         if (need_seek) {
                         int flags;
 
                         if (need_seek) {
-                                if(!arg_reverse)
+                                if (!arg_reverse)
                                         r = sd_journal_next(j);
                                 else
                                         r = sd_journal_previous(j);
                                         r = sd_journal_next(j);
                                 else
                                         r = sd_journal_previous(j);