Commit graph

358 commits

Author SHA1 Message Date
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Lennart Poettering 62570f6f03 fs-util: add new CHASE_TRAIL_SLASH flag for chase_symlinks()
This rearranges chase_symlinks() a bit: if no special flags are
specified it will now revert to behaviour before
b12d25a8d6. However, if the new
CHASE_TRAIL_SLASH flag is specified it will follow the behaviour
introduced by that commit.

I wasn't sure which one to make the beaviour that requires specification
of a flag to enable. I opted to make the "append trailing slash"
behaviour the one to enable by a flag, following the thinking that the
function should primarily be used to generate a normalized path, and I
am pretty sure a path without trailing slash is the more "normalized"
one, as the trailing slash is not really a part of it, but merely a
"decorator" that tells various system calls to generate ENOTDIR if the
path doesn't refer to a path.

Or to say this differently: if the slash was part of normalization then
we really should add it in all cases when the final path is a directory,
not just when the user originally specified it.

Fixes: #8544
Replaces: #8545
2018-03-22 19:54:24 +01:00
Zbigniew Jędrzejewski-Szmek 37cbc1d579 When mangling names, optionally emit a warning (#8400)
The warning is not emitted for absolute paths like /dev/sda or /home, which are
converted to .device and .mount unit names without any fuss.

Most of the time it's unlikely that users use invalid unit names on purpose,
so let's warn them. Warnings are silenced when --quiet is used.

$ build/systemctl show -p Id hello@foo-bar/baz
Invalid unit name "hello@foo-bar/baz" was escaped as "hello@foo-bar-baz" (maybe you should use systemd-escape?)
Id=hello@foo-bar-baz.service

$ build/systemd-run --user --slice foo-bar/baz --unit foo-bar/foo true
Invalid unit name "foo-bar/foo" was escaped as "foo-bar-foo" (maybe you should use systemd-escape?)
Invalid unit name "foo-bar/baz" was escaped as "foo-bar-baz" (maybe you should use systemd-escape?)
Running as unit: foo-bar-foo.service

Fixes #8302.
2018-03-21 15:26:47 +01:00
Yu Watanabe ee5324aa04 tree-wide: voidify pager_open()
Even if pager_open() fails, in general, we should continue the operations.
All erroneous cases in pager_open() show log message in the function.
So, it is not necessary to check the returned value.
2018-03-19 21:04:02 +09:00
Douglas Christman 2de6b06b27 journalctl: make journalctl -g work as documented
Add "g" to optstring so both "--grep" and "-g" work with journalctl
2018-03-01 21:50:38 +08:00
Zbigniew Jędrzejewski-Szmek e79d0b59c8 journalctl: improve hint about lack of access for --user-unit=...
When running journalctl --user-unit=foo as an unprivileged user we could get
the usual hint:
Hint: You are currently not seeing messages from the system and other users.
      Users in groups 'adm', 'systemd-journal', 'wheel' can see all messages.
      ...
But with --user-unit our filter is:
(((_UID=0 OR _UID=1000) AND OBJECT_SYSTEMD_USER_UNIT=foo.service) OR
 ((_UID=0 OR _UID=1000) AND COREDUMP_USER_UNIT=foo.service) OR
 (_UID=1000 AND USER_UNIT=foo.service) OR
 (_UID=1000 AND _SYSTEMD_USER_UNIT=foo.service))
so we would never see messages from other users.

We could still see messages from the system. In fact, on my machine the
only messages with OBJECT_SYSTEMD_USER_UNIT= are from the system:
journalctl  $(journalctl -F OBJECT_SYSTEMD_USER_UNIT|sed 's/.*/OBJECT_SYSTEMD_USER_UNIT=\0/')

Thus, a more correct hint is that we cannot see messages from the system.
Make it so.

Fixes #7887.
2018-02-20 22:36:01 +01:00
Peter Portante ec316d199a journalctl: Periodically call sd_journal_process in journalctl
If `journalctl` take a long time to process messages, and during that
time journal file rotation occurs, a `journalctl` client will keep
those rotated files open until it calls `sd_journal_process()`, which
typically happens as a result of calling `sd_journal_wait()` below in
the "following" case.  By periodically calling `sd_journal_process()`
during the processing loop we shrink the window of time a client
instance has open file descriptors for rotated (deleted) journal
files.

(Lennart: slightly reworked version, that dropped some of the commenting
which was solved otherwise)
2018-02-12 11:27:12 +01:00
Zbigniew Jędrzejewski-Szmek aa9122bf3d Revert "Periodically call sd_journal_process in journalctl" (#8147)
This reverts commit 992149c07e.

https://github.com/systemd/systemd/pull/8144#issuecomment-364464627
$ (set -o pipefail; sudo ./build/journalctl --no-pager | wc -l; echo $?)
Failed to process inotify events: Bad file descriptor
1025
1
2018-02-09 20:10:00 +01:00
Peter Portante 992149c07e Periodically call sd_journal_process in journalctl
If `journalctl` take a long time to process messages, and during that
time journal file rotation occurs, a `journalctl` client will keep
those rotated files open until it calls `sd_journal_process()`, which
typically happens as a result of calling `sd_journal_wait()` below in
the "following" case.  By periodically calling `sd_journal_process()`
during the processing loop we shrink the window of time a client
instance has open file descriptors for rotated (deleted) journal
files.

**Warning**

This change does not appear to solve the case of a "paused" output
stream. If somebody is using `journalctl | less` and pauses the
output, then without a background thread periodically listening for
inotify delete events and cleaning up, journal logs will eventually
stop flowing in cases where a journal client with enough open files
causes the "free" disk space threshold to be crossed.
2018-02-08 20:04:18 +01:00
Hermann Gausterer fabf4dae16 journalctl: typo fix 2018-01-28 20:49:55 +01:00
Zbigniew Jędrzejewski-Szmek b4766d5f15 journalctl: add highlighting for matched substring
Red is used for highligting, the same as grep does. Except when the line is
highlighted red already, because it has high priority, in which case plain ansi
highlight is used for the matched substring.

Coloring is implemented for short and cat outputs, and not for other types.
I guess we could also add it for verbose output in the future.
2018-01-28 14:50:01 +01:00
Zbigniew Jędrzejewski-Szmek 61c5f8a1f0 journalctl: make matching optionally case sensitive
Case sensitive or case insensitive matching can be requested using
--case-sensitive[=yes|no].

Unless specified, matching is case sensitive if the pattern contains any
uppercase letters, and case insensitive otherwise. This matches what
forward-search does in emacs, and recently also --ignore-case in less.  This
works surprisingly well, because usually when one is wants to do case-sensitive
matching, the pattern is usually camel-cased. In the less frequent case when
case-sensitive matching is required with an all-lowercase pattern,
--case-sensitive can be used to override the automatic logic.
2018-01-28 14:50:01 +01:00
Zbigniew Jędrzejewski-Szmek 6becf48ca3 journalctl: regexp matching 2018-01-27 13:40:57 +01:00
Lennart Poettering f1d34068ef tree-wide: add DEBUG_LOGGING macro that checks whether debug logging is on (#7645)
This makes things a bit easier to read I think, and also makes sure we
always use the _unlikely_ wrapper around it, which so far we used
sometimes and other times we didn't. Let's clean that up.
2017-12-15 11:09:00 +01:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +01:00
Lennart Poettering 9b3f8e5968 journalctl: add --output-fields= to --help text (#7443)
Follow-up for #7181
2017-11-24 10:04:14 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lars Karlitski cc25a67e2a journalctl: add --output-fields= (#7181)
This option allows restricting the shown fields in the output modes that
would normally show all fields. It allows clients that are only
interested in a subset of the fields to access those more efficiently.
Also, it makes the resulting size of the output more predictable.

It has no effect on the various `short` output modes, because those
already only show a subset of the fields.
2017-10-27 12:10:47 +09:00
Lennart Poettering 4aa1d31c89 Merge pull request #6974 from keszybz/clean-up-defines
Clean up define definitions
2017-10-04 19:25:30 +02:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
Kai-Heng Feng e3695e499a journalctl: honor --quiet when vacuuming (#6771)
'journalctl --vacuum-*' does not suppress output message with --quiet.

Let journal_directory_vacuum honors --quiet to fix the problem.

BugLink: https://bugs.launchpad.net/bugs/1692188
2017-09-08 14:25:44 +02:00
Vito Caputo b1aa5ced45 shared: leave output_journal() output in buffer (#6304)
e268b81e moved an fflush() from output_json() to the generic
output_journal(), when it probably should have deleted all fflush()
calls from logs-show.c altogether.

The caller supplies the FILE * to these functions, and should be in
charge of flushing as needed.  The current implementation essentially
defeats any buffering stdio was bringing to the table, resulting in
extraneous tiny write() calls in commands like `journalctl -b`.

This commit removes the fflush() call from output_journal(), and adds
them to journalctl before waiting for more entries and at completion.
This way in the hot path when journalctl loops on entries stdio can
combine multiple entries into bulkier write() calls.
2017-07-07 14:32:21 -04:00
Lars Karlitski 5f42943c35 journalctl: honor --show-cursor in more sitatuations
Try to honor --show-cursor in more situations by never terminating early
when we didn't read any logs.

In particular, sd_journal_previous_skip() now returns 0 when it didn't
actually skip anything (for example with --lines=0), which resulted in
--show-cursor not working anymore.
2017-05-11 22:49:20 +02:00
Ian Wienand 7e563bfc97 Add short-iso-precise for journalctl output (#5884)
This adds a short-iso-precise option for journalctl output.  It is similar to
short-iso, but includes microseconds.
2017-05-07 20:23:49 -04:00
Zbigniew Jędrzejewski-Szmek 4f37cbd911 journalctl: move access_check() to shared/
The only functional change is that log_notice("No journal files were found.")
is not printed any more with --quiet. log_error("No journal files were opened
due to insufficient permissions.") is still printed.

I wasn't quite sure where to put this function, but shared/ seems to be the
right place and none of the existing files seem to fit too well.

v2: rename journal_access_check to journal_access_check_and_warn.
2017-02-28 21:37:35 -05:00
Lucas Werkmeister cc7de2ba32 tree-wide: add man: to manpage references (#5402)
Found with:

    git grep '"[^"]*[a-z0-9]([0-9]\+p\?)' src/ | grep -vF man:
2017-02-20 18:45:35 -05:00
Lucas Werkmeister 1e94df4471 journalctl: add reference to sd-id128(3) to output (#5382)
SD_ID128_MAKE is clearly not a standard C macro, so let’s point the user
to its documentation to let them know which header they need and what
they can then do with MESSAGE_XYZ.
2017-02-18 16:36:25 -05:00
Zbigniew Jędrzejewski-Szmek 1075122f42 journalctl: replace string_erase with memset('x')
The compiler should not be able to optimize out the memset, because optarg is global
memory. In this case, not making the argument an empty string is nicer, so just use
an open-coded version of string_erase from before the explicit_bzero change.
2017-02-05 21:07:55 -05:00
Zbigniew Jędrzejewski-Szmek 4761fd0ffb journal-file, journalctl: provide better hint about unsupported features
https://bugzilla.redhat.com/show_bug.cgi?id=1416201

$ journalctl -b
Journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ uses an unsupported feature, ignoring file.
Use SYSTEMD_LOG_LEVEL=debug journalctl --file=/var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ to see the details.
-- No entries --

$ journalctl --file=/var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~
Journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ uses incompatible flag lz4-compressed disabled at compilation time.
Failed to open journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~: Protocol not supported
mmap cache statistics: 0 hit, 1 miss
Failed to open files: Protocol not supported
2017-01-24 19:19:33 -05:00
Zbigniew Jędrzejewski-Szmek e50412ef19 journalctl: fix memleak
This is harmless, it would only happen if --verify-key is used multiple times.
But let's fix it for correctness.

CID ##1368415.
2017-01-15 12:39:15 -05:00
Lucas Werkmeister 6bae9b2abb journalctl: expunge verification key from argv (#5081)
After parsing the --verify-key argument, overwrite it with null bytes.
This minimizes (but does not completely eliminate) the time frame within
which another process on the system can extract the verification key
from the journalctl command line.
2017-01-14 23:03:00 -05:00
Lennart Poettering 493097eecc journalctl: improve wording in an errors message
Fixes: #4660
2016-12-14 18:29:30 +01:00
Lennart Poettering c4f4fce79e fs-util: add flags parameter to chase_symlinks()
Let's remove chase_symlinks_prefix() and instead introduce a flags parameter to
chase_symlinks(), with a flag CHASE_PREFIX_ROOT that exposes the behaviour of
chase_symlinks_prefix().
2016-12-01 00:25:51 +01:00
Lennart Poettering e187369587 tree-wide: stop using canonicalize_file_name(), use chase_symlinks() instead
Let's use chase_symlinks() everywhere, and stop using GNU
canonicalize_file_name() everywhere. For most cases this should not change
behaviour, however increase exposure of our function to get better tested. Most
importantly in a few cases (most notably nspawn) it can take the correct root
directory into account when chasing symlinks.
2016-12-01 00:25:51 +01:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Lennart Poettering 8da830bca9 journalctl: don't claim the journal was stored on disk
Let's just say that the journal takes up space in the file system, not on disk,
as tmpfs is definitely a file system, but not a disk.

Fixes: #4059
2016-10-12 20:25:20 +02:00
Lennart Poettering 202fd896e5 journal: when we encounter a broken journal file, add some debug logging
Let's make it easier to figure out when we see an invalid journal file, why we
consider it invalid, and add some minimal debug logging for it.

This log output is normally not seen (after all, this all is library code),
unless debug logging is exlicitly turned on.
2016-10-12 20:25:20 +02:00
hese10 ec02a6c90a Avoid forever loop for journalctl --list-boots command (#4278)
When date is changed in system to future and normal user logs to new journal file, and then date is changed back to present time, the "journalctl --list-boot" command goes to forever loop. This commit tries to fix this problem by checking first the boot id list if the found boot id was already in that list. If it is found, then stopping the boot id find loop.
2016-10-12 18:40:28 +02:00
hi117 9ea78383e8 Updated formatting for printing the key for FSS (#4165)
The key used to be jammed next to the local file path. Based on the format string on line 1675, I determined that the order of arguments was written incorrectly, and updated the function based on that assumption.

Before:
```
Please write down the following secret verification key. It should be stored
at a safe location and should not be saved locally on disk.

        /var/log/journal/9b47c1a5b339412887a197b7654673a7/fss8f66d6-f0a998-f782d0-1fe522/18fdb8-35a4e900

The sealing key is automatically changed every 15min.
```

After:
```
Please write down the following secret verification key. It should be stored
at a safe location and should not be saved locally on disk.

        d53ed4-cc43d6-284e10-8f0324/18fdb8-35a4e900

The sealing key is automatically changed every 15min.
```
2016-09-16 10:14:55 -04:00
Topi Miettinen 646853bdd8 fileio: simplify mkostemp_safe() (#4090)
According to its manual page, flags given to mkostemp(3) shouldn't include
O_RDWR, O_CREAT or O_EXCL flags as these are always included. Beyond
those, the only flag that all callers (except a few tests where it
probably doesn't matter) use is O_CLOEXEC, so set that unconditionally.
2016-09-13 08:20:38 +02:00
Zbigniew Jędrzejewski-Szmek 0a1750934f journalctl: allow --root argument for journal watching
It is useful to look at a (possibly inactive) container or other os tree
with --root=/path/to/container. This is similar to specifying
--directory=/path/to/container/var/log/journal --directory=/path/to/container/run/systemd/journal
(if using --directory multiple times was allowed), but doesn't require
as much typing.
2016-08-12 00:38:03 -04:00
Zbigniew Jędrzejewski-Szmek 584c6e7050 journalctl,systemctl: add "short-full", "short-unix" mode to --help 2016-08-04 09:03:31 -04:00
Lennart Poettering 3bbaff3e08 tree-wide: use sd_id128_is_null() instead of sd_id128_equal where appropriate
It's a bit easier to read because shorter. Also, most likely a tiny bit faster.
2016-07-22 12:38:08 +02:00
Zbigniew Jędrzejewski-Szmek 592855c318 journalct: allow --boot=0 to DTRT with --file/--directory
--boot=0 magically meant "this boot", but when used with --file/--directory it
should simply refer to the last boot found in the specified journal. This way,
--boot and --list-boots are consistent.

Fixes #3603.
2016-06-28 16:19:59 -04:00
Zbigniew Jędrzejewski-Szmek 07ff6b0823 journalctl: use simpler variable names in get_boots()
Those are just local variables and ref_boot_offset is especially
obnoxious.
2016-06-28 16:14:04 -04:00
Zbigniew Jędrzejewski-Szmek 8453f06257 journalct: do no allow --this-boot to take arguments
Before --this-boot was deprecated in a331b5e6d4, it did not take
any arguments.
2016-06-28 16:14:04 -04:00
Zbigniew Jędrzejewski-Szmek f3bd7561c5 journalctl: allow --file/--directory with --boot or --list-boots
It works mostly fine, and can be quite useful to examine data from another
system.

OTOH, a single boot id doesn't make sense with --merge, so mixing with --merge
is still not allowed.
2016-06-28 16:14:04 -04:00
Lennart Poettering 54f8c958f1 tree-wide: use ansi_highlight() instead of ANSI_HIGHLIGHT where appropriate
Let's make sure SYSTEMD_COLORS is honour by more tools
2016-05-30 18:22:16 +02:00