journalctl -u unit is not very useful, because it doesn't show
systemd messages about starting, stopping, coredumps, etc,
like systemctl status unit does. Make it show the same
information using the same rules.
If somebody really want to see just messages from by the unit,
it is easy enough to use _SYSTEMD_UNIT=...
<term><option>-u</option></term>
<term><option>--unit=</option></term>
<term><option>-u</option></term>
<term><option>--unit=</option></term>
- <listitem><para>Show data only of the
- specified unit. This will add a match
- for <literal>_SYSTEMD_UNIT=</literal>
- for the specified
- unit.</para></listitem>
+ <listitem><para>Show messages for the
+ specified systemd unit. This will add
+ a match for messages from the unit
+ (<literal>_SYSTEMD_UNIT=</literal>)
+ and additional matches for messages
+ from systemd and messages about
+ coredumps for the specified unit.
+ </para></listitem>
</varlistentry>
<varlistentry>
<term><option>--user-unit=</option></term>
</varlistentry>
<varlistentry>
<term><option>--user-unit=</option></term>
- <listitem><para>Show data only of the
+ <listitem><para>Show messages for the
specified user session unit. This will
specified user session unit. This will
- add a match for
- <literal>_SYSTEMD_USER_UNIT=</literal>
- for the specified
- unit.</para></listitem>
+ add a match for messages from the unit
+ (<literal>_SYSTEMD_USER_UNIT=</literal>
+ and <literal>_UID=</literal>) and
+ additional matches for messages from
+ session systemd and messages about
+ coredumps for the specified unit.
+ </para></listitem>
</varlistentry>
<varlistentry>
</varlistentry>
<varlistentry>
#include <systemd/sd-journal.h>
#include "log.h"
#include <systemd/sd-journal.h>
#include "log.h"
#include "util.h"
#include "path-util.h"
#include "build.h"
#include "util.h"
#include "path-util.h"
#include "build.h"
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;
{ "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 },
arg_until_set = true;
break;
arg_until_set = true;
break;
- arg_unit_type = "_SYSTEMD_USER_UNIT=";
+ arg_unit_system = true;
- arg_unit_type = "_SYSTEMD_UNIT=";
+ arg_unit_system = false;
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)