Commit Graph

191 Commits

Author SHA1 Message Date
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering 67bd5620f6 util: make size macros unsigned
By making them unsigned comparing them with other sizes is less likely
to trigger compiler warnings regarding signed/unsigned comparisons.
After all sizes (i.e. size_t) are generally assumed to be unsigned, so
these should be too.

Prompted-by: https://github.com/systemd/systemd/pull/17345#issuecomment-709402332
2020-10-20 15:51:48 +09:00
Zbigniew Jędrzejewski-Szmek 90e74a66e6 tree-wide: define iterator inside of the macro 2020-09-08 12:14:05 +02:00
Luca Boccassi 7b3eb5c97e basic/time-util: add function to format timestamps with different styles
Instead of a multiple fixed format helper functions, add an enum and
a single helper, so that it's easier to extend in the future.
2020-08-19 15:30:13 +01:00
Lennart Poettering e3eec1fd10 journalctl: in "-o cat" mode show color
Let's provide a modicum of niceness, even in this barebones mode.

Fixes: #16232
2020-08-07 10:05:13 +02:00
Lennart Poettering ee5c1311ee logs: when embedding catalog info in log output use a dash of color and unicode
let's separate things out a bit, to make it easier to discern log output
and catalog data.

catalog data is now colored green (which is a color we don't use for log
data currently), and prefixed with a block shade.
2020-07-15 09:32:03 +02:00
Zbigniew Jędrzejewski-Szmek 85fbebe61a journal: fix buffer overrun when urlifying
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21122.

message is only valid until message_len, and we need to make sure we're not
reading pass that. Bug introduced in 2108b56749.
2020-06-25 08:51:21 +02:00
Lennart Poettering 2fac514fa9 logs: strndupa() cannot fail 2020-05-29 10:41:30 +02:00
Lennart Poettering 2108b56749 journal: show documentation hyperlink if known in log output 2020-05-29 10:41:30 +02:00
Zbigniew Jędrzejewski-Szmek 2f063186d5 shared/logs-show: constify Set *fields 2020-05-06 17:03:00 +02:00
Zbigniew Jędrzejewski-Szmek be32732168 basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.

hashmap_put_strdup() was already doing something similar.

(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)

No functional change intended.
2020-05-06 16:54:06 +02:00
Frantisek Sumsal 05c7d9bf5b Revert "logs-show: declare [static 2] on all highlight parameters"
This reverts commit 5444520628.

See: https://github.com/systemd/systemd/pull/15706
2020-05-05 16:37:45 +03:00
Lennart Poettering 5444520628 logs-show: declare [static 2] on all highlight parameters 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
HATAYAMA Daisuke 27f31daf3e shared/logs-show: Remove unused OUTPUT_FOLLOW
As of the commit aae9a96d4b removing --follow
option in systemctl command, OUTPUT_FOLLOW has never been set anywhere. Let's
remove it.

The condition expression of the if-statement in show_journal() that refers to
OUTPUT_FOLLOW now thus evaluates always to true. Hence, the call of
sd_journal_wait() is in dead code, and the outer infinite for-loop is
meaningless, which we remove as cleanup.

There is no functional change by this commit.
2020-03-02 18:27:55 +09:00
Zbigniew Jędrzejewski-Szmek 1a8f0ce64f systemctl: be more specific when emitting warning about rotated journal
See inline comment for disucssion.
Fixes #14281.
2020-02-27 19:52:08 +01:00
Lennart Poettering d93dda3afe systemctl: show logs for correct namespace of service 2020-01-31 15:02:52 +01:00
Lennart Poettering 5905d7cf5b tree-wide: use SD_ID128_STRING_MAX where appropriate 2019-12-10 11:56:18 +01:00
Lennart Poettering b5ea030d65 id128: introduce ID128_UUID_STRING_MAX for sizing UUID buffers 2019-12-10 11:56:18 +01:00
Yu Watanabe f21e58b47d tree-wide: drop time.h when time-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
Yu Watanabe 8cec0a5c32 tree-wide: drop duplicated blank lines
```
$ for i in */*.[ch] */*/*.[ch]; do sed -e '/^$/ {N; s/\n$//g}' -i $i; done
$ git checkout HEAD -- basic/linux shared/linux
```
2019-07-15 18:41:27 +02:00
Zbigniew Jędrzejewski-Szmek 79dc477f2f shared/logs-show: urlify CONFIG_FILE in verbose mode
Now all short-*, verbose, with-unit modes are handled. cat, export, json-* are
not, but those are usually used for post-processing, so I don't think it'd be
useful there.
2019-07-10 14:20:09 +02:00
Zbigniew Jędrzejewski-Szmek 76f7cc3fe4 shared/logs-show: urlify CONFIG_FILE in short mode
v2:
- check that the filename is terminated by ':', ' ', or EOS
- fix grep highlight overlap check
2019-07-10 14:19:26 +02:00
Zbigniew Jędrzejewski-Szmek 71b7a6c47e shared/logs-show: indentation 2019-07-02 09:34:12 +02:00
Zbigniew Jędrzejewski-Szmek 194da5ca51 shared/logs-show: show audit logs in blue
Audit logs always have _TRANSPORT=audit and no PRIORITY= field set.  This means
that they are shown in the default foreground color. There can be quite a lot
of them, and they often repeat the same information that is already logged by
applications, leading to a "wall of text" effect. Let's mark them with a
different color. This splits the logs visually into "normal logs" and "audit
logs".
2019-05-17 15:06:59 +02:00
Zbigniew Jędrzejewski-Szmek 37b8d2f699 basic/log: use colors to highlight messages like journalctl 2019-05-08 09:45:38 +02:00
Lennart Poettering 0cb8e3d118 util: split out namespace related stuff into a new namespace-util.[ch] pair
Just some minor reorganiztion.
2019-03-13 12:16:38 +01:00
Louis Taylor e768a4f032 tree-wide: use '"' instead of '\"'
The escape used previously was redundant and made things more confusing.
2019-01-17 16:46:29 +00:00
Lennart Poettering 67df9b7a06 logs-show: use grey color for de-emphasizing journal log output 2018-12-05 18:46:23 +01:00
Lennart Poettering 1e9e7196cb
Merge pull request #11042 from yuwata/tiny-coding-style-fixes
Tiny coding style fixes
2018-12-04 16:15:09 +01:00
Yu Watanabe f2a3de0116 tree-wide: add whitespace between type and variable name 2018-12-04 09:29:54 +01:00
Lennart Poettering 9e964bb8e4 output-mode: add generic helper to pick right JsonFormatFlags for given OutputMode 2018-12-03 22:42:38 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Lennart Poettering 1edcb6a91c tree-wide: port over other candidates for namespace_fork()
Let's always use the same, correct, way to join a namespace.
2018-11-13 10:49:18 +01:00
Lennart Poettering 8e04444385 journalctl: port JSON output mode to new JSON API
Also, while we are at it, beef it up, by adding json-seq support (i.e.
https://tools.ietf.org/html/rfc7464). This is particularly useful in
conjunction with jq's --seq switch.
2018-10-11 17:25:27 +02:00
Lennart Poettering 38b581bc05 logs-show: make highlight parameter const (#10311) 2018-10-09 16:43:47 +09:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 0ab896b343 journal-remote: do not send _BOOT_ID twice
Also remove the comma from the comment everywhere, I think the comma
unnecessarilly put emphasis on the clause after the comma.

Fixes #9090.

Reproducer:
systemd-journal-remote --split-mode=none -o /tmp/msg6.journal --trust=all --listen-http=8080
systemd-journal-upload -u http://localhost:8080
journalctl --file /tmp/msg6.journal -o verbose -n1
2018-05-31 14:33:41 +02:00
Zbigniew Jędrzejewski-Szmek 03d1319b12 shared/logs-show: be more careful before using a _SOURCE_REALTIME_TIMESTAMP entry
journalctl -o short would display those entries, but journalctl -o short-full
would refuse. If the entry is bad, just fall back to the receive-side realtime
timestamp like we would if it was completely missing.
2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek d3d280242c Always allow timestamps to be printed
If the timestamp is above 9999-12-30, (or 2038-something-something on 32 bit),
use XXXX-XX-XX XX:XX:XX as the replacement.

The problem with refusing to print timestamps is that our code accepts such
timestamps, so we can't really just refuse to process them afterwards. Also, it
makes journal files non-portable, because suddently we might completely refuse
to print entries which are totally OK on a different machine.
2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek 9be391d4db shared/logs-show: use _cleanup_ 2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek 324d6aa926 shared/logs-show: fix mixup between length-based memory duplication and string operations
We'd look for a '=' separator using memchr, i.e. ignoring any nul bytes in the
string, but then do a strndup, which would terminate on any nul byte, and then
again do a memcmp, which would access memory past the chunk allocated by strndup.

Of course, we probably shouldn't allow keys with nul bytes in them. But we
currently do, so there might be journal files like that out there. So let's fix
the journal-reading code first.
2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek 889e396046 shared/logs-show: export show_journal()
This is a nice function to output some journal entries without much ado.
2018-05-31 13:04:18 +02:00
Zbigniew Jędrzejewski-Szmek 9b972c9aab journal: rename output_journal to show_journal_entry
We have show_journal, and output_journal, and it's not immediately clear
how they related. Rename the first to show that it just prints one entry.
2018-05-31 13:04:18 +02:00
Lennart Poettering d27b725abf tree-wide: make use of memory_startswith() at various places 2018-05-30 13:11:51 +02:00
Luca Boccassi 49805b3d81 journalctl: add with-unit mode
When dealing with a large number of template instances, for example
when launching daemons per VRF, it is hard for operators to correlate
log lines to arguments.
Add a new with-unit mode which, if available, prefixes unit and user
unit names when displaying its log messages instead of the syslog
identifier. It will also use the full timestamp with timezones, like
the short-full mode.
2018-05-25 14:45:34 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00