Commit Graph
2486 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek e9dc98c56b journald: inline one variable declaration 2024-01-30 10:11:30 +01:00
Zbigniew Jędrzejewski-Szmek e1054a8bcd bsod: do not use STRLEN
The compiler optimizes strlen away, so we can use the simplest form that is
type safe and more natural. STRLEN is only for array initialization.
2024-01-30 10:11:07 +01:00
Frantisek Sumsal b9f880d528 journalctl: consider shut down namespaced sd-journald instance synced
If the namespaced systemd-journald instance was shut down due to
inactivity, we can consider it synchronized, so avoid throwing an error
in such case.

This should help with the random TEST-44-LOG-NAMESPACE fails where we
might try to sync the namespace just after it was shut down:

[    7.682941] H testsuite-44.sh[381]: + systemd-run --wait -p LogNamespace=foobaz echo 'hello world'
[    7.693916] H systemd-journald[389]: Failed to open /dev/kmsg, ignoring: Operation not permitted
[    7.693983] H systemd-journald[389]: Collecting audit messages is disabled.
[    7.725511] H systemd[1]: Started systemd-journald@foobar.service.
[    7.726496] H systemd[1]: Listening on systemd-journald-varlink@foobaz.socket.
[    7.726808] H systemd[1]: Listening on systemd-journald@foobaz.socket.
[    7.750774] H systemd[1]: Started run-u3.service.
[    7.795122] H systemd[1]: run-u3.service: Deactivated successfully.
[    7.842042] H testsuite-44.sh[390]: Running as unit: run-u3.service; invocation ID: 56380adeb36940a8a170d9ffd2e1e433
[    7.842561] H systemd[1]: systemd-journald-varlink@foobaz.socket: Deactivated successfully.
[    7.842762] H systemd[1]: Closed systemd-journald-varlink@foobaz.socket.
[    7.846394] H systemd[1]: systemd-journald@foobaz.socket: Deactivated successfully.
[    7.846566] H systemd[1]: Closed systemd-journald@foobaz.socket.
[    7.852983] H testsuite-44.sh[390]: Finished with result: success
[    7.852983] H testsuite-44.sh[390]: Main processes terminated with: code=exited/status=0
[    7.852983] H testsuite-44.sh[390]: Service runtime: 44ms
[    7.852983] H testsuite-44.sh[390]: CPU time consumed: 8ms
[    7.852983] H testsuite-44.sh[390]: Memory peak: 880.0K
[    7.852983] H testsuite-44.sh[390]: Memory swap peak: 0B
[    7.853785] H testsuite-44.sh[381]: + journalctl --namespace=foobar --sync
[    7.860095] H systemd-journald[389]: Received client request to sync journal.
[    7.862119] H testsuite-44.sh[381]: + journalctl --namespace=foobaz --sync
[    7.868381] H journalctl[396]: Failed to connect to /run/systemd/journal.foobaz/io.systemd.journal: Connection refused
[    7.871498] H systemd[1]: testsuite-44.service: Main process exited, code=exited, status=1/FAILURE
[    7.871642] H systemd[1]: testsuite-44.service: Failed with result 'exit-code'.
[    7.930772] H systemd[1]: Failed to start testsuite-44.service.
2024-01-19 11:41:34 +00:00
Lennart Poettering 71d0ecc5b9 varlink: introduce varlink_call_and_log() which calls and then logs an error
As it turns out we do this in a similar way at various times (and
sometimes incorrectly), hence add a common implementation to share the
code and fix the incorrect behaviour.
2024-01-17 16:20:54 +01:00
Lennart Poettering 0444391d1e varlink: drop "ret_flags" parameter from varlink_call()
The parameter returns the flags field of the reply message. This is only
relevant in very few cases, hence drop it from the call, but keep it in
a more generic varlink_call_full() call for those who need it.

Do something similar for varlink_callb().
2024-01-17 16:14:10 +01:00
Zbigniew Jędrzejewski-Szmek 8e1ac16bc6 src/basic: rename uid-alloc-range.[ch] to uid-classification.[ch]
We had both uid-range.h and uid-alloc-range.h. The latter now contains helpers
like {uid,gid}_is_{system,dynamic,container}(), uid_for_system_journal(), so
the existing name is outdated. I think the uid-range.[ch] should stay separate
because it has a bunch of helpers for parsing and printing of uid ranges. So
let's rename as in $subject to better reflect the contents of the file and make
the two sets of files harder to confuse.
2024-01-09 11:15:00 +01:00
Lennart Poettering b20e9dc515 env-util: add new setenvf() helper
And convert some pieces of code over.
2024-01-08 23:22:58 +01:00
Frantisek Sumsal 68f66a1713 journalctl: implement --list-namespaces
Apart from being useful on its own, this will be used in the following
commit for shell completions.
2024-01-05 19:21:51 +01:00
Sergei Zhmylev 25aa35d465 journalctl: add --exclude-identifier option 2024-01-04 23:21:39 +01:00
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Mike Yuan dd9c8da865 various: clean up isatty() handling
As per https://github.com/systemd/systemd/pull/30547#discussion_r1434371627
2023-12-22 23:06:49 +08:00
Yu Watanabe 43127aebc7 tree-wide: use hashmap_isempty() and friends 2023-12-22 01:27:09 +09:00
Frantisek Sumsal 159d1e2659 journalctl: also refuse --cursor-file= with --since=
We already refuse the other two cursor-related options (--cursor= and
--after-cursor=) with --since=, so let's do the same with
--cursor-file=.

Closes: #20523
2023-12-18 17:06:43 +01:00
Frantisek Sumsal 4207a5577a journalctl: don't skip over messages not matching the cursor
When --after-cursor=/--cursor-file= is used together with a journal
filter, we still skipped over the first matching entry even if it wasn't
the entry the cursor points at, thus missing one "valid" entry
completely. Let's fix this by checking if the entry cursor after seeking
matches the user provided cursor, and skip to the next entry only when
the cursors match.

Resolves: #30288
2023-12-07 13:31:25 +09:00
Yu Watanabe 65cf964662 Merge pull request #30312 from yuwata/journal-cleanups
journal: several cleanups
2023-12-07 13:23:06 +09:00
Yu Watanabe 2ae16d36ac journal: use sd_event_now() 2023-12-06 11:01:32 +09:00
Yu Watanabe 90c27eb43b journal: use usec_add() and usec_sub_unsigned() 2023-12-06 11:01:28 +09:00
Yu Watanabe 6336c63559 journal: add short comment for boolean arguments 2023-12-06 11:00:48 +09:00
Yu Watanabe 80b1156b96 journal: split out server_new() from server_init()
Then, use DEFINE_MAIN_FUNCTION() macro in journald.
No functional change, just refactoring to follow our usual coding style.
2023-12-06 11:00:48 +09:00
Lennart Poettering dde54b8a85 journalctl: add short option "-i" for "--file="
I see myself frequently typing in "journalctl --file=…". That's a lot to
type. Let's add a short switch too. Unfortunately, "-f" and "-F" are
already taken, hence let's pick "-i".
2023-11-30 16:21:00 +01:00
Yu Watanabe 3197d778e0 journal: sync immediately on shutting down journald
Otherwise, sd_event_add_time_relative() or sd_event_source_set_time_relative()
below will trigger assert_return().

Prompted by #30029.
2023-11-22 14:07:19 +00:00
Frantisek Sumsal 7ec22d7d4b bsod: install the signal handler only just before we need it
Otherwise we might get stuck in sd_journal_wait(), since it handles
EINTR internally.

Resolves: #30084
2023-11-21 16:58:33 +00:00
Yu Watanabe 965040d811 test: always call test_setup_logging() 2023-11-18 03:04:27 +09:00
Frantisek Sumsal d603e3d58c journal: recalculate line_max when stdout stream state changes
Otherwise we might still use the more restrictive limit when we get to
STDOUT_STREAM_RUNNING, causing unexpected line breaks in the journal
messages.

Follow-up to: 80e9720616
Resolves: #29916
2023-11-09 13:29:00 +01:00
Felix Dörre e375bc5fcc journalctl: verify sealed log epochs are continuous
Currently empty epochs are not sealed. This allows an attacker to truncate
a sealed log and continue it without any problems showing when verifying the
log.

This partially addresses CVE-2023-31438. One way to extend this change to
address CVE-2023-31438 completely, would be to verify that there is exactly
one seal per epoch (and not sealing when the epoch has not ended yet).

the change also adds a journal-file flag: HEADER_COMPATIBLE_SEALED_CONTINUOUS
this flag indicates that a journal file is sealed continuously and decides whether
any missing crypto epochs should trigger a warning or an error.
2023-11-09 05:13:27 +09:00
Frantisek Sumsal f742f4176c bsod: restore vt on SIGTERM/SIGINT
Let's install a simple no-op signal handler without SA_RESTART for
SIGINT/SIGTERM, which allows us to interrupt read_one_char() and follow
it up with a proper cleanup, including restoring the vt to the original
state.

Resolves: #29478
2023-11-03 16:06:56 +00:00
Lennart Poettering ac110243a8 bsod,loop-util: fix fd validity check 2023-11-01 15:21:20 +01:00
Lennart Poettering 7113640493 fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
We use it for more than just pipe() arrays. For example also for
socketpair(). Hence let's give it a generic name.

Also add EBADF_TRIPLET to mirror this for things like
stdin/stdout/stderr arrays, which we use a bunch of times.
2023-10-26 22:30:42 +02:00
Yu Watanabe 1bd0cefcab tree-wide: fix typo 2023-10-26 12:42:49 +09:00
Frantisek Sumsal c8ccd444a2 core,journal: drop unnecessary !! casts 2023-10-25 11:21:40 +02:00
Luca Boccassi e5cd8bc060 Merge pull request #29601 from yuwata/mmap-check-overflow
mmap: check offset and size more carefully
2023-10-24 12:20:04 +01:00
Lennart Poettering c24e0dbea1 iovec-util: make IOVEC_TOTAL_SIZE() a regular function
The function isn't necessarily fast (it's O(n)), and there's no reason
to have it defined as inline function, since it's neither fast, nor
entirely trivial.
2023-10-20 10:43:50 +02:00
Lennart Poettering bd1ae17833 io-util: split out "struct iovec" related calls into their own .c/.h files
This is preparation for #28891, which adds a bunch more helpers around
"struct iovec", at which point this really deserves its own .c/.h file.

The idea is that we sooner or later can consider "struct iovec" as an
entirely generic mechanism to reference some binary blob, and is the
go-to type for this purpose whenever we need one.
2023-10-20 10:34:33 +02:00
Yu Watanabe cbdac0c33a tree-wide: check results of PAGE_ALIGN()
Fixes CID#1491282, CID#1491283, CID#1491285, CID#1491288.
2023-10-19 18:31:44 +09:00
Frantisek Sumsal 4820c9d417 fuzz: unify logging setup
Make sure we don't log anything when running in "fuzzing" mode. Also,
when at it, unify the setup logic into a helper, pretty similar to
the test_setup_logging() one.

Addresses:
  - https://github.com/systemd/systemd/pull/29558#pullrequestreview-1676060607
  - https://github.com/systemd/systemd/pull/29558#discussion_r1358940663
2023-10-19 10:05:20 +01:00
Lennart Poettering 4d9f092b5e process-util: add pidref_is_unwaited() and make pid_is_unwaited() return errors 2023-10-18 14:49:40 +02:00
Lennart Poettering 8b51341545 process-util: add pidref_get_uid() and rename get_process_uid() → pidref_get_uid() 2023-10-18 14:39:33 +02:00
Lennart Poettering d7d748548b process-util: add pidref_get_comm() and rename get_process_comm() to pid_get_comm() 2023-10-18 14:39:33 +02:00
Lennart Poettering a034620f1a process-util: add pidref_get_cmdline() 2023-10-18 14:39:33 +02:00
Franck Bui 6495361c7d meson: add build option for install path of main config files
This allows distros to install configuration file templates in /usr/lib/systemd
for example.

Currently we install "empty" config files in /etc/systemd/. They serve two
purposes:

- The file contains commented-out values that show the default settings.
- It is easier to edit the right file if it is already there, the user doesn't
  have to type in the path correctly, and the basic file structure is already in
  place so it's easier to edit.

Things that have happened since this approach was put in place:

- We started supporting drop-ins for config files, and drop-ins are the
  recommended way to create local configuration overrides.
- We have systemd-analyze cat-config which takes care of iterating over
  all possible locations (/etc, /run, /usr, /usr/local) and figuring out
  the right file.
- Because of the first two points, systemd-analyze cat-config is much better,
  because it takes care of finding all the drop-ins and figuring out the
  precedence. Looking at files manually is still possible of course, but not
  very convenient.

The disadvantages of the current approach with "empty" files in /etc:

- We clutter up /etc so it's harder to see what the local configuration actually is.
- If a user edits the file, package updates will not override the file (e.g.
  systemd.rpm uses %config(noreplace). This means that the "documented defaults"
  will become stale over time, if the user ever edits the main config file.

Thus, I think that it's reasonable to:

- Install the main config file to /usr/lib so that it serves as reference for
  syntax and option names and default values and is properly updated on package
  upgrades.
- Recommend to users to always use drop-ins for configuration and
  systemd-analyze cat-config to view the documentation.

This setting makes this change opt-in.

Fixes #18420.

[zjs: add more text to the description]
2023-10-17 18:57:45 +02:00
Zbigniew Jędrzejewski-Szmek ee691c802b Merge pull request #29242 from fbuihuu/update-main-config-file-headers
config files: update their header to reflect that they can be install…
2023-10-17 18:56:09 +02:00
Yu Watanabe 955fc5d8ab tree-wide: add missing sigbus handling 2023-10-07 11:13:27 +02:00
Lennart Poettering abef4a7b3c tree-wide: make all our Varlink APIs introspectable 2023-10-06 11:49:38 +02:00
Lennart Poettering bd1791b597 cgroup-util: drop "controller" argument from various cgroup helper calls
systemd's own cgroup hierarchy is special to us, we use it to actually
manage processes. Because of that many calls tha apply to cgroups are
only ever called with the SYSTEMD_CGROUP_CONTROLLER as controller
argument. Let's hence remove the argument altogether.

This in particular touches the kill and xattr routines.

This changes no behaviour, we just drop an argument that is always set
to the same value anyway.

This is preparation to eventually getting rid of the cgroupvs1, because
on cgroupvs2 the cgroup paths do not change for different controllers,
there's only a single hierarchy there.
2023-10-05 11:11:04 +02:00
Yu Watanabe d287ece7f1 test: split test-tables into three
Let's drop dependency to libjournal_core and libudevd_core from
test-tables.
2023-10-02 10:52:45 +09:00
Yu Watanabe 1d3ef11dfe journal: move several tests to libsystemd/sd-journal
This also renames test-journal-xyz for journald (rather than sd-journal)
to test-journald-xyz.
2023-10-02 10:52:45 +09:00
Yu Watanabe 1e09470303 journald: move and rename journal/managed-journal-file.[ch] -> shared/journal-file-util.[ch]
The files are used by both journald and journal-remote.
Let's move them to src/shared.
2023-10-02 10:52:45 +09:00
Yu Watanabe 45c0ecba2d journald: drop ManagedJournalFile
The ManagedJournalFile object is a trivial wrapper of JournalFile.
Let's drop it, and also drop 'managed_' prefix from the functions.
2023-10-02 10:52:45 +09:00
Yu Watanabe 5f6b79b73b journald: split-out closing journal files from managed_journal_file_open()
No functional change, just refactoring and preparation for later
commits.
2023-10-02 10:52:45 +09:00
Yu Watanabe 34d17ac128 journald: do not close all files stored in Server.deferred_closes
Just before the call of managed_journal_file_open(), we already called
server_vacuum_deferred_closes(), so there is a room to store the file.
2023-10-02 10:52:45 +09:00