Commit Graph

2614 Commits

Author SHA1 Message Date
Lennart Poettering
f2ef9f7760 Fix display of qrcodes by bsod and other related cleanups (#34914) 2024-10-30 17:44:40 +01:00
Zbigniew Jędrzejewski-Szmek
10faa40ba7 cryptenroll,homectl,journalctl: adjust messages before qrcodes
Users will generally know what a qrcode is, so let's not treat them as dumb and
explain that it can be scanned. OTOH, we should say what the qrcode contains
and it is useful to give a hint why the users would want to scan it. Reword
messages accordingly.

(Also, don't say "to your phone", when somebody might be using a stolen phone,
or something else then a phone.)
2024-10-30 15:03:18 +01:00
Zbigniew Jędrzejewski-Szmek
abf1cae0a7 bsod: make message for qrcode more useful
People know what a qrcode is. We don't need to tell them to scan it.
Instead, we should say what the code contains.

While at it, rename "stream" to "f" in line with the usual style.
2024-10-30 15:03:17 +01:00
Zbigniew Jędrzejewski-Szmek
5a64c86936 bsod: do not check for color support
When invoked on a running system, bsod would not print the qrcode.
The check for "color support" on stdout is pointless, since we're not
printing to stdout but to a terminal fd that is opened separately.
2024-10-29 09:41:23 +01:00
Zbigniew Jędrzejewski-Szmek
23441a3d88 sd-json,tree-wide: add sd_json_format_enabled() and use it everwhere
We often used a pattern like if (!FLAGS_SET(flags, SD_JSON_FORMAT_OFF)),
which is rather verbose and also contains a double negative, which we try
to avoid. Add a little helper to avoid an explicit bit check.

This change clarifies an aditional thing: in some cases we treated
SD_JSON_FORMAT_OFF as a flag (flags & SD_JSON_FORMAT_OFF), while in other cases
we treated it as an independent enum value (flags == SD_JSON_FORMAT_OFF).
In the first form, flags like SD_JSON_FORMAT_SSE do _not_ turn the json
output on, while in the second form they do. Let's use the first form
everywhere.

No functional change intended.

Initially I wasn't sure if this helper should be made public or just internal,
but it seems such a common pattern that if we expose the flags, we might just
as well expose it too, to make life easier for any consumers.
2024-10-28 09:23:07 +01:00
Yu Watanabe
ce2b92e8b0 journalctl: do not directly use optarg, but copy optarg before use
Otherwise, if the process forks child processes, then the arguments
cannot be used from them.
To avoid potential issues like the one fixed by
6d3012bab4.
2024-10-16 23:06:42 +09:00
Yu Watanabe
d0ad4e88d4 journalctl: erase verify key before free
Even optarg is erased, copied string was not erased.
Let's erase the copied key for safety.
2024-10-16 20:53:57 +09:00
Yu Watanabe
f769518c9a tree-wide: drop doubled empty lines 2024-10-07 09:51:37 +02:00
Mike Yuan
eda6223942 basic/memory-util: introduce mempcpy_typesafe 2024-09-20 08:29:35 +09:00
Lennart Poettering
d7a6bb9891 tree-wide: make sigprocmask() changes more automatic
This tries to get rid of most manual sigprocmask() changes, in favour
of:

1. The SD_EVENT_SIGNAL_PROCMASK flag to sd_event_add_signal()
2. The sd_event_set_signal_exit() call for handling SIGTERM/SIGINT
3. Move masking of SIGWINCH into ptyfwd, out of nspawn/vmspawn/run

And while we are at it get rid of a bunch of event source fields whose
lifetime is bound to the sd_event object they belong to anyway, and make
use of the "floating" event source feature of sd-event instead.
2024-09-13 17:12:28 +02:00
Lennart Poettering
742e00e3f5 journald: mention the access mode we tried to open /dev/kmsg in
Let's make clearer what we are going to use /dev/kmsg for: read/write or just
writing. This hopefully should avoid confusion, such as the one #33975
is result of.

(Also while we are at it, add one extra debug message).

Fixes: #33975
2024-09-06 16:07:27 +02:00
Lennart Poettering
6f5cf41570 time-util: rework localtime_or_gmtime() into localtime_or_gmtime_usec()
We typically want to deal in usec_t, hence let's change the prototype
accordingly, and do proper range checks. Also, make sure are not
confused by negative times.

Do something similar for mktime_or_timegm().

This is a more comprehensive alternative to #34065

Replaces: #34065
2024-09-05 17:40:25 +02:00
Mike Yuan
ad501930d7 socket-util: make recvmsg_safe() handle MSG_TRUNC too
Also, unify MSG_TRUNC handling all across the codebase.
2024-09-04 18:51:44 +02:00
Yu Watanabe
42efe5be1d tree-wide: drop msg argument for DEFINE_CONFIG_PARSE() macro and friends
This makes the macros use log_syntax_parse_error(), hopefully which provides
more informative log message in general, and reduces binary size.
2024-09-02 05:45:09 +09:00
Mike Yuan
fad3feec12 shared/logs-show: introduce journal_browse_prepare()
which combines sigbus_install() and bumping fd limit.
2024-08-22 20:33:22 +02:00
Lennart Poettering
300b7e7620 tree-wide: use isatty_safe() more 2024-08-20 11:11:53 +02:00
Luca Boccassi
2e59aa50da Merge pull request #33944 from yuwata/journal-max-retention-sec
journal: do not rotate journal when MaxRetentionSec= is set
2024-08-05 11:28:48 +02:00
Yu Watanabe
b55027efe4 journal: set flushed flag even if we fail to open runtime journals
As at this stage, a persistent journal file has been already opened, and
saved seqnum has been reset, and any later journal entries will be stored
to the file. Hence we should not open the runtime journal file by
server_system_journal_open() again.
2024-08-05 11:27:20 +02:00
Yu Watanabe
0d113f8e70 journal: comment the default value in journald.conf 2024-08-05 15:33:32 +09:00
Yu Watanabe
b63c18db03 journal: do not rotate journal when MaxRetentionSec= is set
The setting is about vacuuming archived journal files. It is not
necessary to rotate the current journal. Note, journal file rotation is
controlled by MaxFileSec=.

Fixes #31315.
2024-08-05 15:33:32 +09:00
Yu Watanabe
a8bc75089d journalctl: fix compile error on i386
Fixes the following error:
===
In file included from ../src/basic/macro.h:13,
                 from ../src/basic/dirent-util.h:8,
                 from ../src/journal/journalctl-misc.c:3:
../src/journal/journalctl-misc.c: In function 'show_log_ids':
../src/journal/journalctl-misc.c:107:22: error: comparison is always true due to limited range of data type [-Werror=type-limits]
  107 |         assert(n_ids < INT64_MAX);
      |                      ^
../src/fundamental/macro-fundamental.h:70:44: note: in definition of macro '_unlikely_'
   70 | #define _unlikely_(x) (__builtin_expect(!!(x), 0))
      |                                            ^
../src/basic/macro.h:165:22: note: in expansion of macro 'assert_message_se'
  165 | #define assert(expr) assert_message_se(expr, #expr)
      |                      ^~~~~~~~~~~~~~~~~
../src/journal/journalctl-misc.c:107:9: note: in expansion of macro 'assert'
  107 |         assert(n_ids < INT64_MAX);
      |         ^~~~~~
cc1: all warnings being treated as errors
===

Follow-up for 0a8c1f6212.
2024-08-01 10:49:40 +02:00
Yu Watanabe
7d3ae6b213 journalctl: add --list-invocations command and -I/--invocation options
The --list-invocations command is similar to --list-boots, but shows
invocation IDs of specified unit. This should be useful when showing
a specific invocation of a unit.

The --invocation option is similar to --boot, but takes a invocation ID
or an offset. The -I option is equivalent to --invocation=0.
2024-08-01 07:31:44 +09:00
Yu Watanabe
0a8c1f6212 use int64_t for index in show_log_ids() 2024-08-01 07:31:44 +09:00
Yu Watanabe
b3a16f3985 journalctl: split out show_log_ids() from action_list_boots()
No functional change, just refactoring and prepraration for later change.
2024-08-01 07:31:44 +09:00
Yu Watanabe
a581a2ce8d journalctl: update log messages 2024-08-01 07:31:44 +09:00
Yu Watanabe
6ecee6cf2b logs-show: rename BootId -> LogId
The struct itself is generic, and can be used for other ID.
Let's rename it to more generic one.
No functional change, just refactoring and preparation for later
commits.
2024-08-01 07:31:44 +09:00
Lennart Poettering
b7120388f8 terminal-util: split out color macros/helpers into its own header
This is a lot of stuff, and sometimes quite wild, let's turn this into
its own header.

All stuff color-related that just generates sequences is now in
ansi-color.h (no .c file!), and everything more complex that
probes/ineracts with terminals remains in termina-util.[ch]
2024-07-19 11:44:04 +02:00
Lennart Poettering
53f0ab5151 terminal-util: rename set_terminal_cursor_position() → terminal_set_cursor_position()
Let's prefix these functions with the subsystem name, and clean them up
a bit. Specifically, drop the error logging, it's entirely duplicative,
since every single caller does it anyway.
2024-07-19 11:41:43 +02:00
Lennart Poettering
25ff515b39 sd-varlink: make our internal Varlink API public as sd-varlink.[ch]
It's time. sd-json was already done earlier in this cycle, let's now
make sd-varlink public too.

This is mostly just a search/replace job of epical proportions.

I left some functions internal (mostly IDL handling), and I turned some
static inline calls into regular calls.
2024-07-16 11:57:32 +02:00
Mike Yuan
c53580bf2e Merge pull request #33401 from yuwata/journal-revert-source-boottime-timestamp
journal: partially revert recent changes
2024-06-24 15:34:16 +02:00
Yu Watanabe
461e4656e7 journal: drop mapping from CLOCK_BOOTTIME -> CLOCK_MONOTONIC
This partially reverts commit a9357c2ce2.

Some kmsg sent before sleep may be received by systemd-journald after
sleep. In that case, map_clock_usec() does not provide correct
timestamp.
So, we cannot provide reliable _SOURCE_MONOTONIC_TIMESTAMP.
2024-06-20 00:10:12 +09:00
Zbigniew Jędrzejewski-Szmek
bfd5a0687f various: move const ptr indicator to return value 2024-06-19 16:28:28 +02:00
Yu Watanabe
a9357c2ce2 journal: introduce _SOURCE_BOOTTIME_TIMESTAMP field
Then, fix the monotonic timestamp.

The _SOURCE_MONOTONIC_TIMESTAMP field is already used in other projects.
Hence, we cannot remove the field. But, let's store the correct value.
The existence of the new _SOURCE_BOOTTIME_TIMESTAMP field can indicate
that the monotonic timestamp field is reliable or not.
2024-06-18 17:57:40 +09:00
Lennart Poettering
309a747fa6 libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our
Varlink API is built on top of our JSON API we need to make that public
first (it's a nice API, but JSON APIs there are already enough, this is
purely about the Varlink angle).

I made most of the json.h APIs public, and just placed them in
sd-json.h. Sometimes I wasn't so sure however, since the underlying data
structures would have to be made public too. If in doubt I didn#t risk
it, and moved the relevant API to src/libsystemd/sd-json/json-util.h
instead (without any sd_* symbol prefixes).

This is mostly a giant search/replace patch.
2024-06-12 18:42:22 +02:00
Zbigniew Jędrzejewski-Szmek
a3ada90a37 various: remove unnecessary check before sd_event_source_set_enabled()
sd_event_source_set_enabled() does the same check internally.
2024-05-30 12:11:58 +02:00
Yu Watanabe
3148edb254 journald: always unset flushed flag when the runtime journal is opened
If the runtime journal is opened, we will anyway write journal entries
to the runtime journal, even if the persistent journal is writable.
Hence, we need to flush the runtime journal file later.
2024-05-26 03:11:24 +09:00
Yu Watanabe
349fa06134 journald: log removal of runtime journal directories 2024-05-26 03:11:24 +09:00
Yu Watanabe
672a9ac7d0 journald: close runtime journal earlier
Then, we can use SD_JOURNAL_ASSUME_IMMUTABLE flag, and the performance
of reading runtime journal should be improved.
2024-05-26 03:11:14 +09:00
David Tardon
119f22526e journald-server: drop another invalid assert()
config_parse_forward_to_socket() is not used for parsing unit files
either.

Follow-up-for: f31cff849d
2024-05-16 10:10:25 +02:00
David Tardon
2ef7cdc425 journald-server: drop invalid assert()
config_parse_compress() is not used for parsing unit files, hence unit
is always NULL.

Fixes #32856

Follow-up-for: 6813be2eba
2024-05-16 10:10:19 +02:00
Yu Watanabe
0e2e3fa35a journal-rate-limit: replace in-house management of JournalRateLimitGroup with OrderedHashmap
No functional change, just refactoring.
2024-05-13 19:21:23 +09:00
Yu Watanabe
8df477675d journal-rate-limit: split out journal_ratelimit_group_acquire()
No functional change, just refactoring.
2024-05-12 10:32:14 +09:00
Yu Watanabe
bab044b94b journal-rate-limit: introduce cleanup function for JournalRateLimitGroup
This also makes journal_ratelimit_group_new() use structured initializer.
2024-05-12 10:32:14 +09:00
Yu Watanabe
88c434f75c journal-rate-limit: rename variables
'r' is usually used for storing return value.
2024-05-12 10:32:14 +09:00
Yu Watanabe
1bdaad997d journal-rate-limit: use FOREACH_ELEMENT() and usec_add() 2024-05-12 10:32:14 +09:00
Yu Watanabe
bba23ba47f journal-rate-limit: make journal_ratelimit_group_free() return NULL
To make it follow our recent coding style.
2024-05-12 10:32:14 +09:00
Yu Watanabe
1cb1538f78 journal-rate-limit: add trailing comma in table 2024-05-12 10:32:14 +09:00
Yu Watanabe
78da0721c8 test: introduce test cases for journal_ratelimit_test() 2024-05-12 10:31:41 +09:00
Yu Watanabe
c1db424db5 tree-wide: use LOG_PRI() and LOG_FAC() 2024-05-12 09:49:45 +09:00
Yu Watanabe
d0936a7266 journalctl: make --list-boots support -n/--lines= option
Also mention that -r/--reverse is supported by the command.
2024-05-10 11:43:57 +09:00