1
0
mirror of https://github.com/systemd/systemd synced 2025-11-12 05:14:46 +01:00

Compare commits

...

13 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
640ebaa952
Merge pull request #15648 from poettering/journalctl-cat-beefup
journalctl: honour --output-fields= in -o cat mode
2020-05-05 14:00:26 +02:00
Lennart Poettering
c83347b49d man: migrate more specifier explanations to standard-specifiers.xml
We probably can migrate even more, but for now let's just migrate those
which have the 1:1 identical text everywhere.

(Also, let's add the % entry to all specifier tables)
2020-05-05 11:33:13 +02:00
Zbigniew Jędrzejewski-Szmek
90f1f8188b
Merge pull request #15701 from poettering/systemctl-json-table
systemctl: optionally output tables as json
2020-05-05 11:05:00 +02:00
ianhi
cae97f3b60 correct evdev dimensions for T490 trackpad
The original source of these dimensions had swapped the x y dimension
arguments to touchpad-edge-detector. The correct dimensions are
x = 100 mm, y = 68 mm
2020-05-05 10:30:43 +02:00
Diego Escalante Urrelo
4723f9ef16 hwdb: Fix brightness keys for Logitech K811
Closes: #15698
2020-05-05 10:28:54 +02:00
Lennart Poettering
5fe4d1b514 shutdown: fix spacing in shutdown error message 2020-05-05 10:23:47 +02:00
Lennart Poettering
5444520628 logs-show: declare [static 2] on all highlight parameters 2020-05-05 09:22:27 +02:00
Lennart Poettering
e0e3d38726 man: document the new -o cat feature 2020-05-05 09:22:27 +02:00
Lennart Poettering
4d5d1bba73 journalctl: optionally, show a different field than MESSAGE in -o cat mode
Fixes: #15621
2020-05-05 09:22:26 +02:00
Lennart Poettering
54ff74d273 journal: use set_contains() where appropriate 2020-05-05 09:04:30 +02:00
Motiejus Jakštys
5c4deb9a5c nspawn: mount custom paths before writing to /etc
Consider such configuration:

    $ systemd-nspawn --read-only --timezone=copy --resolv-conf=copy-host \
        --overlay="+/etc::/etc" <...>

Assuming one wants `/` to be read-only, DNS and `/etc/localtime` to
work. One way to do it is to create an overlay filesystem in `/etc/`.
However, systemd-nspawn tries to create `/etc/resolv.conf` and
`/etc/localtime` before mounting the custom paths, while `/` (and, by
extension, `/etc`) is read-only. Thus it fails to create those files.

Mounting custom paths before modifying anything in `/etc/` makes this
possible.

Full example:

```
$ debootstrap buster /var/lib/machines/t1 http://deb.debian.org/debian
$ systemd-nspawn --private-users=false --timezone=copy --resolv-conf=copy-host --read-only --tmpfs=/var --tmpfs=/run --overlay="+/etc::/etc" -D /var/lib/machines/t1 ping -c 1 example.com
Spawning container t1 on /var/lib/machines/t1.
Press ^] three times within 1s to kill container.
ping: example.com: Temporary failure in name resolution
Container t1 failed with error code 130.
```

With the patch:

```
$ sudo ./build/systemd-nspawn --private-users=false --timezone=copy --resolv-conf=copy-host --read-only --tmpfs=/var --tmpfs=/run --overlay="+/etc::/etc" -D /var/lib/machines/t1 ping -qc 1 example.com
Spawning container t1 on /var/lib/machines/t1.
Press ^] three times within 1s to kill container.
PING example.com (93.184.216.34) 56(84) bytes of data.

--- example.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 110.912/110.912/110.912/0.000 ms
Container t1 exited successfully.
```
2020-05-05 09:02:57 +02:00
Lennart Poettering
49cd06fa2d systemctl: optionally output tables in JSON format 2020-05-05 08:15:04 +02:00
Lennart Poettering
e21b76cd68 format-table: generate better JSON field names
Let's try to mangle table contents a bit to make them more suitable as
JSON field names. Specifically when we see "foo bar" convert this to
"foo_bar" as field name, as variable/field names are generally assumed
to be without spaces.
2020-05-05 08:13:58 +02:00
14 changed files with 216 additions and 174 deletions

View File

@ -523,10 +523,10 @@ evdev:name:AlpsPS/2 ALPS GlidePoint:dmi:*svnLENOVO:*pvrLenovoYoga500-14IBD*
# Lenovo Thinkpad T490
evdev:name:SynPS/2 Synaptics TouchPad:dmi:*:svnLENOVO:*pvrThinkPadT490:*
EVDEV_ABS_00=::57
EVDEV_ABS_01=::33
EVDEV_ABS_35=::57
EVDEV_ABS_36=::33
EVDEV_ABS_00=::44
EVDEV_ABS_01=::52
EVDEV_ABS_35=::44
EVDEV_ABS_36=::52
# Lenovo Legion Y9000X2020
evdev:name:MSFT0001:02 04F3:304B Touchpad:dmi:*svnLENOVO:*pvrLenovoLegionY9000X2020*

View File

@ -1013,6 +1013,11 @@ evdev:input:b0005v046DpB30B*
KEYBOARD_KEY_c103a=prog3 # Smartkey C → XF86Launch3
KEYBOARD_KEY_c103b=prog4 # Smartkey D → XF86Launch4
# Logitech K811
evdev:input:b0005v046DpB317*
KEYBOARD_KEY_70047=brightnessdown
KEYBOARD_KEY_70048=brightnessup
# iTouch
evdev:input:b0003v046DpC308*
KEYBOARD_KEY_90001=shop # Shopping

View File

@ -374,9 +374,10 @@
<option>cat</option>
</term>
<listitem>
<para>generates a very terse output, only showing the
actual message of each journal entry with no metadata,
not even a timestamp.</para>
<para>generates a very terse output, only showing the actual message of each journal entry
with no metadata, not even a timestamp. If combined with the
<option>--output-fields=</option> option will output the listed fields for each log record,
instead of the message.</para>
</listitem>
</varlistentry>
@ -398,10 +399,11 @@
<varlistentry>
<term><option>--output-fields=</option></term>
<listitem><para>A comma separated list of the fields which should be included in the output. This has an
effect only for the output modes which would normally show all fields (<option>verbose</option>,
<option>export</option>, <option>json</option>, <option>json-pretty</option>, <option>json-sse</option> and
<option>json-seq</option>). The <literal>__CURSOR</literal>, <literal>__REALTIME_TIMESTAMP</literal>,
<listitem><para>A comma separated list of the fields which should be included in the output. This has
an effect only for the output modes which would normally show all fields (<option>verbose</option>,
<option>export</option>, <option>json</option>, <option>json-pretty</option>,
<option>json-sse</option> and <option>json-seq</option>), as well as on <option>cat</option>. For the
former, the <literal>__CURSOR</literal>, <literal>__REALTIME_TIMESTAMP</literal>,
<literal>__MONOTONIC_TIMESTAMP</literal>, and <literal>_BOOT_ID</literal> fields are always
printed.</para></listitem>
</varlistentry>

View File

@ -4,6 +4,11 @@
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
<tbody>
<row id='b'>
<entry><literal>%b</literal></entry>
<entry>Boot ID</entry>
<entry>The boot ID of the running system, formatted as string. See <citerefentry><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry> for more information.</entry>
</row>
<row id='a'>
<entry><literal>%a</literal></entry>
<entry>Architecture</entry>
@ -14,11 +19,26 @@
<entry>Operating system build ID</entry>
<entry>The operating system build identifier of the running system, as read from the <varname>BUILD_ID=</varname> field of <filename>/etc/os-release</filename>. If not set, resolves to an empty string. See <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<row id='H'>
<entry><literal>%H</literal></entry>
<entry>Host name</entry>
<entry>The hostname of the running system.</entry>
</row>
<row id='m'>
<entry><literal>%m</literal></entry>
<entry>Machine ID</entry>
<entry>The machine ID of the running system, formatted as string. See <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<row id='o'>
<entry><literal>%o</literal></entry>
<entry>Operating system ID</entry>
<entry>The operating system identifier of the running system, as read from the <varname>ID=</varname> field of <filename>/etc/os-release</filename>. See <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<row id='v'>
<entry><literal>%v</literal></entry>
<entry>Kernel release</entry>
<entry>Identical to <command>uname -r</command> output.</entry>
</row>
<row id='w'>
<entry><literal>%w</literal></entry>
<entry>Operating system version ID</entry>
@ -29,4 +49,9 @@
<entry>Operating system variant ID</entry>
<entry>The operating system variant identifier of the running system, as read from the <varname>VARIANT_ID=</varname> field of <filename>/etc/os-release</filename>. If not set, resolves to an empty string. See <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<row id='percent'>
<entry><literal>%%</literal></entry>
<entry>Single percent sign</entry>
<entry>Use <literal>%%</literal> in place of <literal>%</literal> to specify a single percent sign.</entry>
</row>
</tbody>

View File

@ -90,30 +90,15 @@
</thead>
<tbody>
<xi:include href="standard-specifiers.xml" xpointer="a"/>
<row>
<entry><literal>%b</literal></entry>
<entry>Boot ID</entry>
<entry>The boot ID of the running system, formatted as string. See <citerefentry><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="b"/>
<xi:include href="standard-specifiers.xml" xpointer="B"/>
<row>
<entry><literal>%H</literal></entry>
<entry>Host name</entry>
<entry>The hostname of the running system.</entry>
</row>
<row>
<entry><literal>%m</literal></entry>
<entry>Machine ID</entry>
<entry>The machine ID of the running system, formatted as string. See <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="H"/>
<xi:include href="standard-specifiers.xml" xpointer="m"/>
<xi:include href="standard-specifiers.xml" xpointer="o"/>
<row>
<entry><literal>%v</literal></entry>
<entry>Kernel release</entry>
<entry>Identical to <command>uname -r</command> output.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="v"/>
<xi:include href="standard-specifiers.xml" xpointer="w"/>
<xi:include href="standard-specifiers.xml" xpointer="W"/>
<xi:include href="standard-specifiers.xml" xpointer="percent"/>
</tbody>
</tgroup>
</table>

View File

@ -1715,11 +1715,7 @@
<entry>Architecture</entry>
<entry>A short string identifying the architecture of the local system. A string such as <constant>x86</constant>, <constant>x86-64</constant> or <constant>arm64</constant>. See the architectures defined for <varname>ConditionArchitecture=</varname> above for a full list.</entry>
</row>
<row>
<entry><literal>%b</literal></entry>
<entry>Boot ID</entry>
<entry>The boot ID of the running system, formatted as string. See <citerefentry><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="b"/>
<xi:include href="standard-specifiers.xml" xpointer="B"/>
<row>
<entry><literal>%C</literal></entry>
@ -1744,6 +1740,7 @@
Note that this setting is <emphasis>not</emphasis> influenced by the <varname>User=</varname> setting configurable in the [Service] section of the service unit.</entry>
</row>
<row>
<!-- We do not use the common definition from standard-specifiers.xml here since we want a slightly more verbose explanation here, referring to the reload cycle. -->
<entry><literal>%H</literal></entry>
<entry>Host name</entry>
<entry>The hostname of the running system at the point in time the unit configuration is loaded.</entry>
@ -1773,11 +1770,7 @@ Note that this setting is <emphasis>not</emphasis> influenced by the <varname>Us
<entry>Log directory root</entry>
<entry>This is either <filename>/var/log</filename> (for the system manager) or the path <literal>$XDG_CONFIG_HOME</literal> resolves to with <filename index="false">/log</filename> appended (for user managers).</entry>
</row>
<row>
<entry><literal>%m</literal></entry>
<entry>Machine ID</entry>
<entry>The machine ID of the running system, formatted as string. See <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="m"/>
<xi:include href="standard-specifiers.xml" xpointer="o"/>
<row>
<entry><literal>%n</literal></entry>
@ -1843,11 +1836,7 @@ Note that this setting is <emphasis>not</emphasis> influenced by the <varname>Us
Note that this setting is <emphasis>not</emphasis> influenced by the <varname>User=</varname> setting configurable in the [Service] section of the service unit.</entry>
</row>
<row>
<entry><literal>%v</literal></entry>
<entry>Kernel release</entry>
<entry>Identical to <command>uname -r</command> output</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="v"/>
<row>
<entry><literal>%V</literal></entry>
<entry>Directory for larger and persistent temporary files</entry>
@ -1855,11 +1844,7 @@ Note that this setting is <emphasis>not</emphasis> influenced by the <varname>Us
</row>
<xi:include href="standard-specifiers.xml" xpointer="w"/>
<xi:include href="standard-specifiers.xml" xpointer="W"/>
<row>
<entry><literal>%%</literal></entry>
<entry>Single percent sign</entry>
<entry>Use <literal>%%</literal> in place of <literal>%</literal> to specify a single percent sign.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="percent"/>
</tbody>
</tgroup>
</table>

View File

@ -252,33 +252,17 @@ r - 500-900
</thead>
<tbody>
<xi:include href="standard-specifiers.xml" xpointer="a"/>
<row>
<entry><literal>%b</literal></entry>
<entry>Boot ID</entry>
<entry>The boot ID of the running system, formatted as string. See <citerefentry><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="b"/>
<xi:include href="standard-specifiers.xml" xpointer="B"/>
<row>
<entry><literal>%H</literal></entry>
<entry>Host name</entry>
<entry>The hostname of the running system.</entry>
</row>
<row>
<entry><literal>%m</literal></entry>
<entry>Machine ID</entry>
<entry>The machine ID of the running system, formatted as string. See <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="H"/>
<xi:include href="standard-specifiers.xml" xpointer="m"/>
<xi:include href="standard-specifiers.xml" xpointer="o"/>
<row>
<entry><literal>%T</literal></entry>
<entry>Directory for temporary files</entry>
<entry>This is either <filename>/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry>
</row>
<row>
<entry><literal>%v</literal></entry>
<entry>Kernel release</entry>
<entry>Identical to <command>uname -r</command> output.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="v"/>
<row>
<entry><literal>%V</literal></entry>
<entry>Directory for larger and persistent temporary files</entry>
@ -286,11 +270,7 @@ r - 500-900
</row>
<xi:include href="standard-specifiers.xml" xpointer="w"/>
<xi:include href="standard-specifiers.xml" xpointer="W"/>
<row>
<entry><literal>%%</literal></entry>
<entry>Escaped <literal>%</literal></entry>
<entry>Single percent sign.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="percent"/>
</tbody>
</tgroup>
</table>

View File

@ -633,11 +633,7 @@ w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
</thead>
<tbody>
<xi:include href="standard-specifiers.xml" xpointer="a"/>
<row>
<entry><literal>%b</literal></entry>
<entry>Boot ID</entry>
<entry>The boot ID of the running system, formatted as string. See <citerefentry><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="b"/>
<xi:include href="standard-specifiers.xml" xpointer="B"/>
<row>
<entry><literal>%C</literal></entry>
@ -649,21 +645,13 @@ w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
<entry>User home directory</entry>
<entry>This is the home directory of the user running the command. In case of the system instance this resolves to <literal>/root</literal>.</entry>
</row>
<row>
<entry><literal>%H</literal></entry>
<entry>Host name</entry>
<entry>The hostname of the running system.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="H"/>
<row>
<entry><literal>%L</literal></entry>
<entry>System or user log directory</entry>
<entry>In <option>--user</option> mode, this is the same as <varname>$XDG_CONFIG_HOME</varname> with <filename index="false">/log</filename> appended, and <filename>/var/log</filename> otherwise.</entry>
</row>
<row>
<entry><literal>%m</literal></entry>
<entry>Machine ID</entry>
<entry>The machine ID of the running system, formatted as string. See <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="m"/>
<xi:include href="standard-specifiers.xml" xpointer="o"/>
<row>
<entry><literal>%S</literal></entry>
@ -700,11 +688,7 @@ w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
<entry>User UID</entry>
<entry>This is the numeric UID of the user running the command. In case of the system instance this resolves to <constant>0</constant>.</entry>
</row>
<row>
<entry><literal>%v</literal></entry>
<entry>Kernel release</entry>
<entry>Identical to <command>uname -r</command> output.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="v"/>
<row>
<entry><literal>%V</literal></entry>
<entry>Directory for larger and persistent temporary files</entry>
@ -712,11 +696,7 @@ w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
</row>
<xi:include href="standard-specifiers.xml" xpointer="w"/>
<xi:include href="standard-specifiers.xml" xpointer="W"/>
<row>
<entry><literal>%%</literal></entry>
<entry>Escaped <literal>%</literal></entry>
<entry>Single percent sign.</entry>
</row>
<xi:include href="standard-specifiers.xml" xpointer="percent"/>
</tbody>
</tgroup>
</table>

View File

@ -3486,6 +3486,16 @@ static int outer_child(
if (r < 0)
return r;
r = mount_custom(
directory,
arg_custom_mounts,
arg_n_custom_mounts,
arg_uid_shift,
arg_selinux_apifs_context,
MOUNT_NON_ROOT_ONLY);
if (r < 0)
return r;
r = setup_timezone(directory);
if (r < 0)
return r;
@ -3502,16 +3512,6 @@ static int outer_child(
if (r < 0)
return r;
r = mount_custom(
directory,
arg_custom_mounts,
arg_n_custom_mounts,
arg_uid_shift,
arg_selinux_apifs_context,
MOUNT_NON_ROOT_ONLY);
if (r < 0)
return r;
if (!arg_use_cgns) {
r = mount_cgroups(
directory,

View File

@ -1241,7 +1241,7 @@ static int table_data_compare(const size_t *a, const size_t *b, Table *t) {
return CMP(*a, *b);
}
static const char *table_data_format(Table *t, TableData *d) {
static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercasing) {
assert(d);
if (d->formatted)
@ -1253,7 +1253,7 @@ static const char *table_data_format(Table *t, TableData *d) {
case TABLE_STRING:
case TABLE_PATH:
if (d->uppercase) {
if (d->uppercase && !avoid_uppercasing) {
char *p, *q;
d->formatted = new(char, strlen(d->string) + 1);
@ -1602,7 +1602,7 @@ static int table_data_requested_width_height(
const char *t;
int r;
t = table_data_format(table, d);
t = table_data_format(table, d, false);
if (!t)
return -ENOMEM;
@ -1784,7 +1784,7 @@ int table_print(Table *t, FILE *f) {
* ellipsis. Hence, let's figure out the last line, and account for its
* length plus ellipsis. */
field = table_data_format(t, d);
field = table_data_format(t, d, false);
if (!field)
return -ENOMEM;
@ -1969,7 +1969,7 @@ int table_print(Table *t, FILE *f) {
assert_se(d = row[t->display_map ? t->display_map[j] : j]);
field = table_data_format(t, d);
field = table_data_format(t, d, false);
if (!field)
return -ENOMEM;
@ -2256,6 +2256,24 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
}
}
static char* string_to_json_field_name(const char *f) {
char *c, *x;
/* Tries to make a string more suitable as JSON field name. There are no strict rules defined what a
* field name can be hence this is a bit vague and black magic. Right now we only convert spaces to
* underscores and leave everything as is. */
c = strdup(f);
if (!c)
return NULL;
for (x = c; *x; x++)
if (isspace(*x))
*x = '_';
return c;
}
int table_to_json(Table *t, JsonVariant **ret) {
JsonVariant **rows = NULL, **elements = NULL;
_cleanup_free_ size_t *sorted = NULL;
@ -2298,11 +2316,27 @@ int table_to_json(Table *t, JsonVariant **ret) {
}
for (j = 0; j < display_columns; j++) {
_cleanup_free_ char *mangled = NULL;
const char *formatted;
TableData *d;
assert_se(d = t->data[t->display_map ? t->display_map[j] : j]);
r = table_data_to_json(d, elements + j*2);
/* Field names must be strings, hence format whatever we got here as a string first */
formatted = table_data_format(t, d, true);
if (!formatted) {
r = -ENOMEM;
goto finish;
}
/* Arbitrary strings suck as field names, try to mangle them into something more suitable hence */
mangled = string_to_json_field_name(formatted);
if (!mangled) {
r = -ENOMEM;
goto finish;
}
r = json_variant_new_string(elements + j*2, mangled);
if (r < 0)
goto finish;
}

View File

@ -131,7 +131,7 @@ static int field_set_test(Set *fields, const char *name, size_t n) {
if (!s)
return log_oom();
return set_get(fields, s) ? 1 : 0;
return set_contains(fields, s);
}
static bool shall_print(const char *p, size_t l, OutputFlags flags) {
@ -158,7 +158,7 @@ static bool print_multiline(
bool audit,
const char* message,
size_t message_len,
size_t highlight[2]) {
size_t highlight[static 2]) {
const char *color_on = "", *color_off = "", *highlight_on = "";
const char *pos, *end;
@ -370,7 +370,7 @@ static int output_short(
unsigned n_columns,
OutputFlags flags,
Set *output_fields,
const size_t highlight[2]) {
const size_t highlight[static 2]) {
int r;
const void *data;
@ -534,7 +534,7 @@ static int output_verbose(
unsigned n_columns,
OutputFlags flags,
Set *output_fields,
const size_t highlight[2]) {
const size_t highlight[static 2]) {
const void *data;
size_t length;
@ -653,7 +653,7 @@ static int output_export(
unsigned n_columns,
OutputFlags flags,
Set *output_fields,
const size_t highlight[2]) {
const size_t highlight[static 2]) {
sd_id128_t boot_id;
char sid[SD_ID128_STRING_MAX];
@ -883,7 +883,7 @@ static int output_json(
unsigned n_columns,
OutputFlags flags,
Set *output_fields,
const size_t highlight[2]) {
const size_t highlight[static 2]) {
char sid[SD_ID128_STRING_MAX], usecbuf[DECIMAL_STR_MAX(usec_t)];
_cleanup_(json_variant_unrefp) JsonVariant *object = NULL;
@ -1016,6 +1016,57 @@ finish:
return r;
}
static int output_cat_field(
FILE *f,
sd_journal *j,
OutputFlags flags,
const char *field,
const size_t highlight[static 2]) {
const char *highlight_on, *highlight_off;
const void *data;
size_t l, fl;
int r;
if (FLAGS_SET(flags, OUTPUT_COLOR)) {
highlight_on = ANSI_HIGHLIGHT_RED;
highlight_off = ANSI_NORMAL;
} else
highlight_on = highlight_off = "";
r = sd_journal_get_data(j, field, &data, &l);
if (r == -EBADMSG) {
log_debug_errno(r, "Skipping message we can't read: %m");
return 0;
}
if (r == -ENOENT) /* An entry without the requested field */
return 0;
if (r < 0)
return log_error_errno(r, "Failed to get data: %m");
fl = strlen(field);
assert(l >= fl + 1);
assert(((char*) data)[fl] == '=');
data = (const uint8_t*) data + fl + 1;
l -= fl + 1;
if (highlight && FLAGS_SET(flags, OUTPUT_COLOR)) {
assert(highlight[0] <= highlight[1]);
assert(highlight[1] <= l);
fwrite((const char*) data, 1, highlight[0], f);
fwrite(highlight_on, 1, strlen(highlight_on), f);
fwrite((const char*) data + highlight[0], 1, highlight[1] - highlight[0], f);
fwrite(highlight_off, 1, strlen(highlight_off), f);
fwrite((const char*) data + highlight[1], 1, l - highlight[1], f);
} else
fwrite((const char*) data, 1, l, f);
fputc('\n', f);
return 0;
}
static int output_cat(
FILE *f,
sd_journal *j,
@ -1023,51 +1074,26 @@ static int output_cat(
unsigned n_columns,
OutputFlags flags,
Set *output_fields,
const size_t highlight[2]) {
const size_t highlight[static 2]) {
const void *data;
size_t l;
const char *field;
Iterator iterator;
int r;
const char *highlight_on = "", *highlight_off = "";
assert(j);
assert(f);
if (flags & OUTPUT_COLOR) {
highlight_on = ANSI_HIGHLIGHT_RED;
highlight_off = ANSI_NORMAL;
(void) sd_journal_set_data_threshold(j, 0);
if (set_isempty(output_fields))
return output_cat_field(f, j, flags, "MESSAGE", highlight);
SET_FOREACH(field, output_fields, iterator) {
r = output_cat_field(f, j, flags, field, streq(field, "MESSAGE") ? highlight : NULL);
if (r < 0)
return r;
}
sd_journal_set_data_threshold(j, 0);
r = sd_journal_get_data(j, "MESSAGE", &data, &l);
if (r == -EBADMSG) {
log_debug_errno(r, "Skipping message we can't read: %m");
return 0;
}
if (r < 0) {
/* An entry without MESSAGE=? */
if (r == -ENOENT)
return 0;
return log_error_errno(r, "Failed to get data: %m");
}
assert(l >= 8);
if (highlight && (flags & OUTPUT_COLOR)) {
assert(highlight[0] <= highlight[1]);
assert(highlight[1] <= l - 8);
fwrite((const char*) data + 8, 1, highlight[0], f);
fwrite(highlight_on, 1, strlen(highlight_on), f);
fwrite((const char*) data + 8 + highlight[0], 1, highlight[1] - highlight[0], f);
fwrite(highlight_off, 1, strlen(highlight_off), f);
fwrite((const char*) data + 8 + highlight[1], 1, l - 8 - highlight[1], f);
} else
fwrite((const char*) data + 8, 1, l - 8, f);
fputc('\n', f);
return 0;
}
@ -1078,7 +1104,7 @@ static int (*output_funcs[_OUTPUT_MODE_MAX])(
unsigned n_columns,
OutputFlags flags,
Set *output_fields,
const size_t highlight[2]) = {
const size_t highlight[static 2]) = {
[OUTPUT_SHORT] = output_short,
[OUTPUT_SHORT_ISO] = output_short,
@ -1104,7 +1130,7 @@ int show_journal_entry(
unsigned n_columns,
OutputFlags flags,
char **output_fields,
const size_t highlight[2],
const size_t highlight[static 2],
bool *ellipsized) {
int ret;

View File

@ -20,7 +20,7 @@ int show_journal_entry(
unsigned n_columns,
OutputFlags flags,
char **output_fields,
const size_t highlight[2],
const size_t highlight[static 2],
bool *ellipsized);
int show_journal(
FILE *f,

View File

@ -525,7 +525,7 @@ int main(int argc, char *argv[]) {
}
if (need_umount || need_swapoff || need_loop_detach || need_dm_detach)
log_error("Failed to finalize %s%s%s%s ignoring",
log_error("Failed to finalize%s%s%s%s ignoring.",
need_umount ? " file systems," : "",
need_swapoff ? " swap devices," : "",
need_loop_detach ? " loop devices," : "",

View File

@ -390,6 +390,21 @@ static bool output_show_unit(const UnitInfo *u, char **patterns) {
return true;
}
static int output_table(Table *table) {
int r;
assert(table);
if (OUTPUT_MODE_IS_JSON(arg_output))
r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO);
else
r = table_print(table, NULL);
if (r < 0)
return log_error_errno(r, "Failed to show table: %m");
return 0;
}
static int output_units_list(const UnitInfo *unit_infos, unsigned c) {
_cleanup_(table_unrefp) Table *table = NULL;
const UnitInfo *u;
@ -473,9 +488,9 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) {
return log_error_errno(r, "Failed to hide column: %m");
}
r = table_print(table, NULL);
r = output_table(table);
if (r < 0)
return log_error_errno(r, "Failed to print the table: %m");
return r;
if (!arg_no_legend) {
const char *on, *off;
@ -1039,9 +1054,9 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) {
off = ansi_normal();
}
r = table_print(table, NULL);
r = output_table(table);
if (r < 0)
return log_error_errno(r, "Failed to print the table: %m");
return r;
if (!arg_no_legend) {
printf("\n%s%u sockets listed.%s\n", on, cs, off);
@ -1285,9 +1300,9 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) {
off = ansi_normal();
}
r = table_print(table, NULL);
r = output_table(table);
if (r < 0)
return log_error_errno(r, "Failed to print the table: %m");
return r;
if (!arg_no_legend) {
printf("\n%s%u timers listed.%s\n", on, n, off);
@ -1501,9 +1516,9 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) {
return table_log_add_error(r);
}
r = table_print(table, NULL);
r = output_table(table);
if (r < 0)
return log_error_errno(r, "Failed to print the table: %m");
return r;
if (!arg_no_legend)
printf("\n%u unit files listed.\n", c);
@ -2033,9 +2048,9 @@ static int output_machines_list(struct machine_info *machine_infos, unsigned n)
return table_log_add_error(r);
}
r = table_print(table, NULL);
r = output_table(table);
if (r < 0)
return log_error_errno(r, "Failed to print the table: %m");
return r;
if (!arg_no_legend) {
printf("\n");
@ -8601,6 +8616,11 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown output '%s'.",
optarg);
if (OUTPUT_MODE_IS_JSON(arg_output)) {
arg_no_legend = true;
arg_plain = true;
}
break;
case 'i':