Commit Graph

441 Commits

Author SHA1 Message Date
Lennart Poettering 9200bb30d0 journalctl: make pcre2 a dlopen() dependency
Let's make use of the library if it is installed, but otherwise just
generate a nice error and provide all other functionality.
2020-07-21 10:37:54 +02:00
Zbigniew Jędrzejewski-Szmek f83803a649
Merge pull request #16238 from keszybz/set-handling-more
Fix handling of cases where a duplicate item is added to a set and related cleanups
2020-06-24 17:42:13 +02:00
Filipe Brandenburger 41d1f469cf log: introduce log_parse_environment_cli() and log_setup_cli()
Presently, CLI utilities such as systemctl will check whether they have a tty
attached or not to decide whether to parse /proc/cmdline or EFI variable
SystemdOptions looking for systemd.log_* entries.

But this check will be misleading if these tools are being launched by a
daemon, such as a monitoring daemon or automation service that runs in
background.

Make log handling of CLI tools uniform by never checking /proc/cmdline or EFI
variables to determine the logging level.

Furthermore, introduce a new log_setup_cli() shortcut to set up common options
used by most command-line utilities.
2020-06-24 16:49:26 +02:00
Zbigniew Jędrzejewski-Szmek de7fef4b6e tree-wide: use set_ensure_put()
Patch contains a coccinelle script, but it only works in some cases. Many
parts were converted by hand.

Note: I did not fix errors in return value handing. This will be done separate
to keep the patch comprehensible. No functional change is intended in this
patch.
2020-06-22 16:32:37 +02:00
Lennart Poettering dad28bffd6 tree-wide: check POLLNVAL everywhere
poll() sets POLLNVAL inside of the poll structures if an invalid fd is
passed. So far we generally didn't check for that, thus not taking
notice of the error. Given that this specific kind of error is generally
indication of a programming error, and given that our code is embedded
into our projects via NSS or because people link against our library,
let's explicitly check for this and convert it to EBADF.

(I ran into a busy loop because of this missing check when some of my
test code accidentally closed an fd it shouldn't close, so this is a
real thing)
2020-06-10 08:57:31 +02:00
Lennart Poettering 544e146b0e journalctl,elsewhere: make sure --file=foo fails with sane error msg if foo is not readable
It annoyed me for quite a while that running "journalctl --file=…" on a
file that is not readable failed with a "File not found" error instead
of a permission error. Let's fix that.

We make this work by using the GLOB_NOCHECK flag for glob() which means
that files are not accessible will be returned in the array as they are
instead of being filtered away. This then means that our later attemps
to open the files will fail cleanly with a good error message.
2020-05-19 15:26:51 +02:00
Lennart Poettering 41ab8c67eb tree-wide: use structured initialization at various places 2020-04-24 07:44:42 +02:00
Frantisek Sumsal 86b52a3958 tree-wide: fix spelling errors
Based on a report from Fossies.org using Codespell.

Followup to #15436
2020-04-21 23:21:08 +02:00
Zbigniew Jędrzejewski-Szmek 196dedd503 journalctl: implement --facility=foo
Fixes #9716.
2020-02-29 18:07:37 +01:00
Lennart Poettering 23d8c56046 journalctl: underline sections in --help 2020-01-31 15:10:40 +01:00
Lennart Poettering 21fa231ece journalctl: drop misplaced empty line 2020-01-31 15:02:48 +01:00
Lennart Poettering 6b25db87a1 journalctl: add new --namespace= switch for showing logs for namespace 2020-01-31 15:02:45 +01:00
Lennart Poettering 33ff74643e journalctl: use an anonymous array when an array is needed
I am pretty sure this makes things more readable, since the expected
argument here is actually an array.
2020-01-31 15:02:22 +01:00
Lennart Poettering e7238caf0c journalctl: use automatic memory cleanup 2020-01-31 15:01:57 +01:00
Lennart Poettering 0491150b5c journalctl: use log_error_errno() wherever we can 2020-01-31 15:01:53 +01:00
Lennart Poettering a6214d9643 journalctl: move pcre function code down
We usually put the static arguments at the top of each source files, do
so here too, and thus move the first code down.
2020-01-31 15:01:50 +01:00
Timo Schlüßler 23b3921663 journalctl: Correctly handle combination of --reverse and --lines (fixes #1596) 2020-01-13 17:35:06 +01:00
Timo Schlüßler 3ac9cac7f7 journalctl: Correctly handle --show-cursor in combination with --until or --since and --reverse 2020-01-13 17:33:50 +01:00
Lennart Poettering 3aebd9d6dd journalctl: pager_close() calls fflush(stdout) anyway as first thing 2019-11-28 15:15:24 +01:00
Lennart Poettering 2275b74741 journalctl: return EOPNOTSUPP if pcre is not enabled 2019-11-28 15:02:36 +01:00
Zbigniew Jędrzejewski-Szmek f0f3a0b52a
Merge pull request #14046 from poettering/id128-uuid
add "-u" switch to systemd-uuid for outputting ids in UUID format
2019-11-18 15:19:43 +01:00
Lennart Poettering 353b2baa20 tree-wide: clean up --help texts a bit
This cleans up and unifies the outut of --help texts a bit:

1. Highlight the human friendly description string, not the command
   line via ANSI sequences. Previously both this description string and
   the brief command line summary was marked with the same ANSI
   highlight sequence, but given we auto-page to less and less does not
   honour multi-line highlights only the command line summary was
   affectively highlighted. Rationale: for highlighting the description
   instead of the command line: the command line summary is relatively
   boring, and mostly the same for out tools, the description on the
   other hand is pregnant, important and captions the whole thing and
   hence deserves highlighting.

2. Always suffix "Options" with ":" in the help text

3. Rename "Flags" →  "Options" in one case

4. Move commands to the top in a few cases

5. add coloring to many more help pages

6. Unify on COMMAND instead of {COMMAND} in the command line summary.
   Some tools did it one way, others the other way. I am not sure what
   precisely {} is supposed to mean, that uppercasing doesn't, hence
   let's simplify and stick to the {}-less syntax

And minor other tweaks.
2019-11-18 15:14:43 +01:00
Lennart Poettering a19fdd66c2 id128: add new "-u" switch for outputting Ids in UUID format
For some unrelated stuff I wanted the machine ID in UUID format, and it
was annoying doing that manually. So let's add a switch for this, so
that this works:

    systemd-id128 machine-id -u
2019-11-15 19:07:05 +01:00
Jan Kundrát c488660e6e journalctl: allow running vacuum on remote journals, too
Right now the `systemd-journal-remote` service does not constrain its
resource usage (I just run out of space on my 100GB partition, for
example). This patch does not change that, but it at least makes it
possible to run something like:

  journalctl --directory /var/log/journal/remote --rotate --vacuum-size=90G

fixes #2376

Co-authored-by: Mike Auty <ikelos@gentoo.org>
2019-11-04 14:52:27 +01:00
Yu Watanabe a969d60645 tree-wide: drop locale.h when locale-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Zbigniew Jędrzejewski-Szmek a5648b8094 basic/fs-util: change CHASE_OPEN flag into a separate output parameter
chase_symlinks() would return negative on error, and either a non-negative status
or a non-negative fd when CHASE_OPEN was given. This made the interface quite
complicated, because dependning on the flags used, we would get two different
"types" of return object. Coverity was always confused by this, and flagged
every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it
would this that an fd is returned). This patch uses a saparate output parameter,
so there is no confusion.

(I think it is OK to have functions which return either an error or an fd. It's
only returning *either* an fd or a non-fd that is confusing.)
2019-10-24 22:44:24 +09:00
Arian van Putten 0e4a4f56be journalctl: Make journalctl --user-unit= match on _SYSTEMD_USER_SLICE
journalctl --unit= already did this, and allows you to tail all the logs
for a certain slice easily. It seemed only natural to make --user-unit
behave in a similar way.

The _SYSTEMD_USER_SLICE field was not documented as being added by
journald, so I have added that to the documentation too.

Furthermore, I have documented the existing behaviour of --unit= and the
new behaviour of --user-unit=

The behaviour was actually not documented before, so I am also OK with
removing the match for the --unit= command instead.  The user would then
have to manually provide _SYSTEMD_SLICE= filter to journalctl in both
cases. Both options work for me.
2019-08-22 13:39:54 +02:00
Lennart Poettering b910cc72c0 tree-wide: get rid of strappend()
It's a special case of strjoin(), so no need to keep both. In particular
as typing strjoin() is even shoert than strappend().
2019-07-12 14:31:12 +09:00
Lennart Poettering 8e27167cc9
Merge pull request #13011 from keszybz/auto-erase
Remove string_erase and friends
2019-07-11 01:05:01 +02:00
Zbigniew Jędrzejewski-Szmek 309c6b19a7 Remove string_erase 2019-07-10 14:43:44 +02:00
Yu Watanabe 4bbccb02ea tree-wide: introduce strerror_safe() 2019-07-05 02:43:56 +09:00
Lennart Poettering 64ef83139c
Merge pull request #12837 from yuwata/tree-wide-lgtm-fixes
tree-wide: fix issues found by lgtm
2019-06-20 12:35:34 +02:00
Yu Watanabe 6d946490ba tree-wide: drop alloca() in loop 2019-06-20 06:29:19 +09:00
Yu Watanabe aa89266900 util: introduce format_bytes_full()
And move it into format-util.c.
2019-06-19 23:15:19 +09:00
Yu Watanabe 0bd3c2102f journalctl: make 'journalctl --flush' or friends not fail with varlink timeout
Closes #12570.
2019-06-04 23:27:26 +09:00
Yu Watanabe f2083c718b journalctl: mention --smart-relinquish-var in log message 2019-06-04 17:04:35 +09:00
Yu Watanabe 17087340c3 journalctl: fix error cause in log message
If varlink_call() returns negative errno, then `error` is null.
2019-06-04 17:03:36 +09:00
Frantisek Sumsal 6cda6774bd journalctl: return a non-zero EC when --grep returns no matches
When journalctl is compiled with PCRE2 support, let's return a non-zero
exit code when --grep is used and no match for given pattern is found.
This should allow users to use journalctl --grep in scripts instead of
piping journalctl into grep

Fixes #8152
2019-05-16 18:54:01 +02:00
Zbigniew Jędrzejewski-Szmek 77740b5993 journalctl: improve error messages
Follow-up for #12230.
2019-05-10 16:55:37 +02:00
Lennart Poettering c0dfcb318c journalctl: add new --relinquish and --smart-relinquish options
The latter is identical to the former, but becomes a NOP if
/var/log/journal is on the same mount as /, and thus during shutdown
unmounting /var is not necessary and hence we can keep logging until the
very end.
2019-05-09 14:26:42 -04:00
Lennart Poettering 4f413af2a0 journalctl: port --flush/--sync/--rotate to use varlink method calls 2019-05-09 14:26:40 -04:00
Lennart Poettering e95be7def2
Merge pull request #12411 from keszybz/pr/12394
run: when emitting the calendarspec warning, use red
2019-05-08 10:11:32 -04:00
Zbigniew Jędrzejewski-Szmek 1a04395959 Enable log colors for most of tools in /usr/bin
When emitting the calendarspec warning we want to see some color.
Follow-up for 04220fda5c.

Exceptions:
- systemctl, because it has a lot hand-crafted coloring
- tmpfiles, sysusers, stdio-bridge, etc, because they are also used in
  services and I'm not sure if this wouldn't mess up something.
2019-05-08 09:50:21 +02:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Lennart Poettering 6990fb6bc6 tree-wide: (void)ify a few unlink() and rmdir()
Let's be helpful to static analyzers which care about whether we
knowingly ignore return values. We do in these cases, since they are
usually part of error paths.
2019-03-27 18:09:56 +01:00
Zbigniew Jędrzejewski-Szmek 330b8fb379 journalctl: voidify mkdir_p() call and unify two similar code paths
Let's unify the two similar code paths to watch /run/systemd/journal.
The code in manager.c is similar, but it uses mkdir_p_label(), and unifying
that would be too much trouble, so let's just adjust the error messages to
be the same.

CID #1400224.
2019-03-27 13:01:44 +01:00
dana 4890482531 journalctl: support `-b all` to negate effect of -b
Also fix an issue where -b without argument didn't always behave as -b0
2019-03-19 10:48:26 +01:00
Lennart Poettering d8b4d14df4 util: split out nulstr related stuff to nulstr-util.[ch] 2019-03-14 13:25:52 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00