Commit Graph

6670 Commits

Author SHA1 Message Date
Yu Watanabe
93bb67090c log: introduce a knob to make assert_return() critical
These can be used to check if we trigger assert_return()
unexpectedly.

Co-authored-by: Frantisek Sumsal <frantisek@sumsal.cz>
2023-12-24 01:52:26 +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
Mike Yuan
76270f5c09 terminal-util: introduce isatty_safe that rejects EBADF 2023-12-22 23:06:48 +08:00
Mike Yuan
d3f818fea6 terminal-util: use RET_GATHER more 2023-12-22 23:04:47 +08:00
Lennart Poettering
dc6522b18f Merge pull request #28658 from H5117/enroll_with_ec
cryptsetup: Add support for EC keys in PKCS#11 tokens
2023-12-21 22:45:40 +01:00
Lennart Poettering
63e9c38370 terminal-util: add helper that determines terminal default bg color 2023-12-21 19:15:01 +01:00
Lennart Poettering
d02d4f83f0 terminal-util: add helper for disabling terminal echo in termios struct 2023-12-21 19:15:01 +01:00
Lennart Poettering
20f8b345db env-util: add strv_env_assignf() helper 2023-12-21 19:07:29 +01:00
Lennart Poettering
fccad70602 socket-util: remove unnecessary variable 2023-12-21 15:22:16 +01:00
Lennart Poettering
989740ebc4 socket-util: make sure SO_PEERSEC returned string is always NUL terminated
it's not entirely clear to me if the manual NUL termination is
necessary, but let's better be safe than sorry, since this is apparently
up to the LSMs, and I am not sure we can trust them all.

A lot of other code (such as dbus-broker) patches in the NUL byte, hence
let's be rather safe-then-sorry, it's trivial after all.
2023-12-21 15:21:23 +01:00
Vladimir Stoiakin
a3c1b0d74c TEST-24-CRYPTSETUP: add test for PKCS#11 tokens
Introduces new dependencies on SoftHSM, OpenSC and GnuTLS for the test.
2023-12-20 11:52:18 +03:00
Yu Watanabe
5d889f3ab8 signal-util: align table 2023-12-20 03:07:46 +09:00
Yu Watanabe
97df9fa065 time-util: make usleep_safe() return earlier if 0 is passed 2023-12-20 03:07:46 +09:00
Lennart Poettering
8722c7e7bc siphash: make sure siphash24_compress_usec_t() works the same on LE/BE archs
Let's be systematic here, and always hash LE values. It doesn't matter
in our current codebase, but it might one day.
2023-12-19 11:48:53 +09:00
Lennart Poettering
e22ca70008 ether-addr-util: split out logic to mark MAC addresses as random 2023-12-19 11:48:05 +09:00
Mike Yuan
7312c422f0 basic/uid-range: add uid_map_read_one helper 2023-12-15 21:22:51 +08:00
Mike Yuan
121b705426 cgroup-util: check ferror() first
Also, there's no need to set use errno_or_else(), since fscanf() is
documented to set errno on error.
2023-12-15 21:21:17 +08:00
Luca Boccassi
266e8d0eb6 Merge pull request #30417 from YHNdnzj/unit-log-resource
core/unit: clean up unit_log_resources
2023-12-14 08:45:26 +00:00
Lennart Poettering
21c43631d7 rlimit-util: add pid_getrlimit() helper
This is gets the resource limits off a specified process, and is very
similar to prlimit() with a NULL new_rlimit argument. In fact, it tries
that first. However, it then falls back to use /proc/$PID/limits. Why?
Simply because Linux prohibits access to prlimit() for processes with a
different UID, but /proc/$PID/limits still works.

This is preparation to allow nspawn to run unprivileged.
2023-12-14 08:31:29 +00:00
Lennart Poettering
a1796e9bd8 pidref: add pidref_set_parent() for race-freely getting pidref on ppid 2023-12-13 18:00:14 +01:00
Mike Yuan
ba354c164f iovec-util: add missing assertion 2023-12-13 20:42:05 +08:00
Yu Watanabe
a0460dfed6 parse-util: accept arbitrary MTU size when AF_UNSPEC
When [Link] MTU= is specified in a .network file, we have no idea about
that what kind of interface will be configured with the .network file.
The maximum and minimum MTU size depend on the kind of interface.
So, we should not filter MTU eagerly in the parser.

Closes #30140.
2023-12-08 10:47:42 +09:00
Lennart Poettering
cbc51d0cf4 Merge pull request #30101 from poettering/underline-rework
systemctl: "list-units" table tweaks
2023-12-06 22:13:12 +01:00
Lennart Poettering
4d56442755 recurse-dir: add new readdir_all_at() helper
This new helper combines open() with readdir_all() to simplify a few
callers.
2023-12-06 22:12:48 +01:00
Lennart Poettering
dc7a49ed25 Merge pull request #30183 from poettering/nlcr
NL → CRNL conversion fixes when logging at the same time as ptyfwd runs
2023-12-06 22:12:17 +01:00
Lennart Poettering
6498a0c2cc user-util: add new helper fully_set_uid_gid()
Usually when we do setresuid() we also do setesgid() and setgroups().
Let's add a common helper that does all three, and use it everywhere.
2023-12-06 22:11:38 +01:00
Luca Boccassi
d5401e36dc Merge pull request #30332 from bluca/softreboot_pivot_in_place
switch-root: also check that mount IDs are the same, not just inodes
2023-12-06 21:01:13 +00:00
Luca Boccassi
5134e54625 basic: add fds_are_same_mount() helper 2023-12-05 17:20:27 +00:00
Yu Watanabe
829732d40a basic: fix typo 2023-12-05 23:50:25 +09:00
Yu Watanabe
e521898d83 capability-util: avoid false-positive use-of-uninitialized-value error
fuzzers randomly fail with the following:
```
==172==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f41169cb39b in update_argv /work/build/../../src/systemd/src/basic/argv-util.c:96:13
    #1 0x7f41169cb39b in rename_process /work/build/../../src/systemd/src/basic/argv-util.c:210:16
    #2 0x7f4116b6824e in safe_fork_full /work/build/../../src/systemd/src/basic/process-util.c:1516:21
    #3 0x7f4116bffa36 in safe_fork /work/build/../../src/systemd/src/basic/process-util.h:191:16
    #4 0x7f4116bffa36 in parse_timestamp /work/build/../../src/systemd/src/basic/time-util.c:1047:13
    #5 0x4a61e6 in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-time-util.c:16:16
    #6 0x4c4a13 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #7 0x4c41fa in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3
    #8 0x4c58c9 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:757:19
    #9 0x4c6595 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:895:5
    #10 0x4b58ff in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #11 0x4def52 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #12 0x7f4115ea3082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: e678fe54a5d2c2092f8e47eb0b33105e380f7340)
    #13 0x41f5ad in _start (build-out/fuzz-time-util+0x41f5ad)

DEDUP_TOKEN: update_argv--rename_process--safe_fork_full
  Uninitialized value was created by an allocation of 'fv' in the stack frame of function 'have_effective_cap'
    #0 0x7f41169d3540 in have_effective_cap /work/build/../../src/systemd/src/basic/capability-util.c:21
```
2023-11-28 10:22:39 +01:00
Lennart Poettering
d19ddf91fd log: when writing a log message to a TTY always end line in CRNL
This should make sure our log lines look nice even if the tty we are
connected to is in raw mode. Normally, it's the TTY's job to turn an NL
we output into a CRNL and interpret it accordingly. However, if the tty
is in "raw" mode it won't do that. Specifically, this is controlled by
the ONLCR flag on the TTY. A TTY might be in raw mode if our "ptyfwd"
logic is used for example, where a 2nd tty is bi-directionally connected
to the primary tty, and duplicate processing is not desired.

Hence, let's just write out the CR on our own. This will make sure that
whenever we output something subsequent output always continues on the
beginning of the next line again, regardless the mode the TTY is in. Of
course, if the TTY is *not* in raw mode, then the extra CR we now
generate is redundant, but it shouldn't hurt either, as it just moves
the cursor to the front of the line even though already is just there.

We only to that if we actually talk to a TTY though, since we don't want
the extra CRs if we are redirected to a pipe or file or so. We are not
on Windows after all.

Fixes: #30155
2023-11-24 11:09:24 +01:00
Lennart Poettering
6a7e015429 stat-util: make file name arguments optional in inode_same_at() 2023-11-24 11:00:52 +01:00
Yu Watanabe
19f0a71ba0 io-util: actually retry on failure
Follow-up for e22c60a9d5.

Fixes #30152.
2023-11-22 20:38:38 +00:00
Lennart Poettering
40e1100283 recurse-dir: correct comment
The RECURSE_DIR_ENSURE_TYPE flag is actually interpreted by
readdir_all() already, hence rearrange comments to say so.
2023-11-22 17:44:29 +00:00
Luca Boccassi
61c232dc8b Merge pull request #30145 from poettering/reset-terminal-line-editing
make terminal line editing work with systemd-firstboot
2023-11-22 17:43:51 +00:00
Luca Boccassi
7d4b61d287 Merge pull request #30149 from yuwata/setlocale
locale-util: do not call setlocale() when multi-threaded
2023-11-22 17:43:39 +00:00
Luca Boccassi
31897753fb Merge pull request #30024 from keszybz/one-doc-thingy
Serialize units ratelimits and document StartLimitIntervalSec=infinity
2023-11-22 17:42:51 +00:00
Lennart Poettering
9b85e90780 fs-util: add comment explaining what xopenat() is for 2023-11-23 02:29:37 +09:00
Yu Watanabe
d54a45ad5f locale-util: drop unused init_gettext()
The function has not been used since 96d9117ad2.
2023-11-23 00:50:46 +09:00
Yu Watanabe
ca13432d60 locale-util: do not call setlocale() when multi-threaded
Fixes #30141.
2023-11-23 00:50:42 +09:00
Zbigniew Jędrzejewski-Szmek
fed25720ef core: use uniform style for RateLimit initialization
RateLimit is designed so that we can always initialize only the first two
fields explicitly. All other call sites use a single line for this.
2023-11-22 12:32:31 +00:00
Lennart Poettering
d5b6c6e378 terminal-util: drop ECHOPRT flag from TTY settings when resetting
Let's disable ECHOPRT for terminals we reset.

The feature only really makes sense for hardcopy terminals and we sure
as shit don't talk to one of those. It has the effect that when line
editing is on and you hit backspace it outputs "\" followed by the
removed character. This never makes sense on a TTY that can just erase
the character.

Hence turn of this flag.

We have carried this flag along for about forever, but it doesn't really
make sense. I guess we mostly tested the terminal reset stuff for output
only, not for input.

This change is in particular useful for tools such as
"systemd-firstboot" which interactively ask questions on the console,
and where line editing should really work.
2023-11-22 13:27:53 +01:00
Lennart Poettering
68e4c637f8 terminal-util: trivial modernizations for reset_terminal_fd() 2023-11-22 13:27:53 +01:00
Lennart Poettering
6ad2049dd9 terminal-util: add macro for adding underline to existing formats
This is different from the existing macros that generate "underline"
ANSI sequences: these ones are additive, i.e. do not reset the font to
the default first. The idea is to combine these with other ansi
sequences.
2023-11-20 13:00:43 +01:00
Yu Watanabe
25ac30bdb8 log: rename variables to store function call results 2023-11-16 09:21:10 +00:00
Luca Boccassi
b1ef479d5a Update syscalls list 2023-11-14 20:17:48 +00:00
Lennart Poettering
aa25e19b47 util-lib: share plymouth client code
Let's add a new "plymouth-util.c" module with helpers for talking to
plymouth. We so far had three places for this, let's unify the code
doing this a bit.
2023-11-13 14:17:05 +00:00
Zbigniew Jędrzejewski-Szmek
fa5a025167 Rename {dual,triple}_timestamp_get to {dual,triple}_timestamp_now
Those functions take a pointer to a timestamp and return a timestamp pointer,
so the reader would be justified to think that those are just getters. Rename
them to avoid confusion.
2023-11-13 13:27:07 +01:00
Mike Yuan
4c8d5f0217 pidref: introduce hash ops that doesn't come with destructor 2023-11-11 17:21:10 +08:00
Mike Yuan
2c302e8919 cgroup-util: introduce cg_pidref_get_unit 2023-11-11 17:21:10 +08:00