Commit Graph
6259 Commits
Author SHA1 Message Date
Mike Yuan ea25672de5 cgroup-setup: move cg_{,un}install_release_agent from cgroup-util
They're pid1-specific, so move them out of basic/.
2024-08-02 16:36:07 +02:00
Mike Yuan 3386f66200 cgroup-setup: drop unused cg_migrate_callback for cg_attach_everywhere()
While at it, move the typedef from cgroup-util to -setup.
2024-08-02 14:47:39 +02:00
Yu Watanabe 029709f932 socket-util: introduce netlink_socket_get_multicast_groups()
No functional change. Preparation for later commits.
2024-08-02 11:16:33 +09:00
Daan De Meyer ff5662129a Merge pull request #33885 from DaanDeMeyer/pidref-kthread
Two pidfd fixes
2024-07-31 19:07:35 +02:00
Daan De Meyer 5551426785 Merge pull request #33884 from DaanDeMeyer/log-context
log: Fix size calculation for number of iovecs
2024-07-31 14:23:08 +02:00
Daan De Meyer ead48ec35c cgroup-util: Don't try to open pidfd for kernel threads
The kernel might start returning -EINVAL when trying to open pidfd's
for kernel threads so let's not try to open pidfd's for kernel threads.
2024-07-31 13:50:16 +02:00
Daan De Meyer fc83ff3f55 log: Fix size calculation for number of iovecs
Each log context field can expand to up to three iovecs (key, value
and newline) so let's fix the size calculation to take this into
account.
2024-07-31 13:12:55 +02:00
Daan De Meyer 7881f485c9 execute: Drop log level to unit log level in exec_spawn()
All messages logged from exec_spawn() are attributed to the unit
and as such we should set the log level to the unit's max log level
for the duration of the function.
2024-07-31 13:12:55 +02:00
Daniel P. Berrangé 9d7be044ca Fix detection of TDX confidential VM on Azure platform
The original CVM detection logic for TDX assumes that the guest can see
the standard TDX CPUID leaf. This was true in Azure when this code was
originally written, however, current Azure now blocks that leaf in the
paravisor. Instead it is required to use the same Azure specific CPUID
leaf that is used for SEV-SNP detection, which reports the VM isolation
type.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-07-30 22:39:20 +02:00
Daan De Meyer 0fbb569de1 cgroup-util: Ignore kernel threads in cg_kill_items()
Similar to the implementation of cgroup.kill in the kernel, let's
skip kernel threads in cg_kill_items() as trying to kill kernel
threads as an unprivileged process will fail with EPERM and doesn't
do anything when running privileged.
2024-07-30 11:53:32 +02:00
Zbigniew Jędrzejewski-Szmek e520b1258c Merge pull request #30307 from bluca/enforce_inhibitors
logind: always check for inhibitor locks
2024-07-26 13:52:34 +02:00
Luca Boccassi 7020fa8feb Merge pull request #33825 from DaanDeMeyer/chattr
repart: Create disk image file with copy-on-write disabled on btrfs
2024-07-25 14:11:11 +01:00
Luca Boccassi 804874d26a logind: always check for inhibitor locks
Currently inhibitors are bypassed unless an explicit request is made to
check for them, or even in that case when the requestor is root or the
same uid as the holder of the lock.

But in many cases this makes it impractical to rely on inhibitor locks.
For example, in Debian there are several convoluted and archaic
workarounds that divert systemctl/reboot to some hacky custom scripts
to try and enforce blocking accidental reboots, when it's not expected
that the requestor will remember to specify the command line option
to enable checking for active inhibitor locks.

Also in many cases one wants to ensure that locks taken by a user are
respected by actions initiated by that same user.

Change logind so that inhibitors checks are not skipped in these
cases, and systemctl so that locks are checked in order to show a
friendly error message rather than "permission denied".

Add new block-weak and delay-weak modes that keep the previous
behaviour unchanged.
2024-07-25 12:22:36 +01:00
Mike Yuan 268f58076f basic/log: do not treat all negative errnos as synthetic
Currently, IS_SYNTHETIC_ERRNO() evaluates to true for all negative errnos,
because of the two's-complement negative value representation.
Subsequently, ERRNO= is not logged for most of our own code.
Let's fix this, by formatting all synthetic errnos as positive.
Then, treat all negative values as non-synthetic.

While at it, mark the evaluation order explicitly, and remove
unneeded comment.

Fixes #33800
2024-07-25 12:03:59 +02:00
Daan De Meyer 5e49684521 Make read_attr_path() more generic
Let's make this an openat() like function so it can be used in more
scenarios.
2024-07-24 18:58:41 +02:00
Daan De Meyer 1b05ac946a fs-util: Add XO_NOCOW flag
Let's add a flag for xopenat() that immediately makes a file NOCOW
after opening it if it's supported.
2024-07-24 18:58:41 +02:00
Daan De Meyer 32dfe3b63e fs-util: Clean up properly in xopenat_full() on labelling error
If we fail to relabel the file, we should unlink the file or directory
again, so let's make sure we do that.
2024-07-24 18:58:41 +02:00
Daan De Meyer 0dd82dab91 fs-util: Handle dangling symlinks in openat_report_new()
openat() will always resolve symlinks, except if O_NOFOLLOW is passed
or O_CREAT|O_EXCL is passed. This means that if a dangling symlink is
passed to openat_report_new(), the first call to openat() will always
fail with ENOENT and the second call to openat() will always fail with
EEXIST.

Let's catch this case explicitly and fallback to creating the file with
just O_CREAT and assume we're the ones that created the file. We can't
resolve the symlink with chase() because this function is itself called
by chase() so we could end up in weird recursive calls if we'd try to do
so.
2024-07-24 18:58:41 +02:00
Luca Boccassi 0d45d0ec58 Merge pull request #33810 from YHNdnzj/find-executable-simplify
path-util: minor cleanup for find_executable()
2024-07-23 23:08:19 +01:00
Mike Yuan 86a3c1fd95 namespace-util: introduce pidref_namespace_open() 2024-07-23 19:30:54 +02:00
Mike Yuan 30957ced45 namespace-util: explicitly specify namespace_info[]'s size
We do this already in all string lookup tables. This way
it's guaranteed that iterators which ends with _NAMESPACE_TYPE_MAX
wouldn't overrun the array.
2024-07-23 19:30:54 +02:00
Mike Yuan 0e7eda91f4 path-util: simplify final path for find_executable()
Currently, systemd-run ./test.sh would set Description=
to $PWD/./test.sh. This is quite ugly.
2024-07-23 18:48:15 +02:00
Mike Yuan 51b271ead7 path-util: trivial cleanup for find_executable_full() 2024-07-23 18:48:15 +02:00
Mike Yuan 31d76a1702 missing_socket: add SCM_PASSPIDFD and SCM_PIDFD
Preparation for later commits.
2024-07-21 22:50:58 +02:00
Mike Yuan 8dc303d3c8 process-util: modernize pidfd_get_pid() 2024-07-21 22:48:53 +02:00
Mike Yuan 77f709ca84 pidref: move comments that doesn't belong in pidref_copy() to pidref_dup()
Follow-up for 232e66217d
2024-07-21 22:48:53 +02:00
Lennart Poettering 0ea4198f0a terminal-util: add recognizable error if cols/rows of tty are initially not initialized
Various tty types come up with cols/rows not initialized (i.e. set to
zero). Let's detect these cases, and return a better error than EIO,
simply to make things easier to debug.
2024-07-19 11:44:04 +02:00
Lennart Poettering ad2fa21f83 terminal-util: extend timeout on background color request
I managed to hit the timeout a couple of times inside of slow qemu.
Let's increase it a bit to 1/3s
2024-07-19 11:44:04 +02:00
Lennart Poettering abe8e99ee6 terminal-util: try to avoid reading more from terminal than we need in get_default_background_color() 2024-07-19 11:44:04 +02:00
Lennart Poettering 2cd19499a0 tree-wide: acquire /dev/console lock around any attempts to reset TTY 2024-07-19 11:44:04 +02:00
Lennart Poettering dffbe1d152 terminal-util: teach resolve_dev_console() to deal correctly with /dev/console being a symlink
/dev/console is sometimes a symlink in container managers. Let's handle
that correctly, and resolve the symlink, and not consider the data from
/sys/ in that case.
2024-07-19 11:44:04 +02:00
Lennart Poettering 4a24cc859f terminal-util: move lock_dev_console() here
It doesn't really make sense to have that in dev-setup.c, which is
mostly about setting up /dev/, creating device nodes and stuff.

let's move it to the other stuff that deals with /dev/console's
peculiarities.
2024-07-19 11:44:04 +02:00
Lennart Poettering 45d785dfc0 terminal-util: refactor vt_disallocate()
Numerous fixes:

1. use vtnr_from_tty() to parse out VT number from tty path
2. open tty for write only when we want to output just ansi sequences
3. open tty in asynchronous mode, and apply a timeout, just to be safe
4. propagate error from writing (most callers ignore it anyway, might as
   well pass it along correctly)
2024-07-19 11:44:04 +02:00
Lennart Poettering 7147e10c9e terminal-util: move acquire_terminal() and AcquireTerminalFlags back together in header file 2024-07-19 11:44:04 +02:00
Lennart Poettering 061b445828 terminal-util: simplify terminal_set_size_fd() a tiny bit 2024-07-19 11:44:04 +02: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 1ca3924827 terminal-util: remove terminal_vhangup() because apparently unused 2024-07-19 11:44:04 +02:00
Lennart Poettering ac508b1173 terminal-util: rename return parameters ret_xyz 2024-07-19 11:44:04 +02:00
Lennart Poettering af1d3a6d92 terminal-util: modernize vt_reset_keyboard() a bit 2024-07-19 11:44:04 +02:00
Lennart Poettering b61c015aeb terminal-util: don't export vt_reset_keyboard() + vt_default_utf8() 2024-07-19 11:41:43 +02:00
Lennart Poettering 524e1240ff terminal-util: modernize terminal_reset_ansi_seq() a bit
Let's update the commentary a bit. Also, use a time-out of 100ms rather
than 50ms for this, simply to unify on the same value used in
vt_disallocate() in a similar case.
2024-07-19 11:41:43 +02:00
Lennart Poettering e2216800c5 terminal-util: don't export terminal_reset_ioctl()/terminal_reset_ansi_seq() anymore
We only use them in terminal-util.c, hence make them static (and move
them before their first using function).
2024-07-19 11:41:43 +02:00
Lennart Poettering 5a4e541779 terminal-util: rename reset_terminal_fd() → terminal_reset_ioctl()
Let's put "terminal_" as prefix, like with the other reset calls, and
let's make clear that this only encapsulates the ioctl-based reset
logic, not the ANSI sequence based reset logic.
2024-07-19 11:41:43 +02:00
Lennart Poettering 12f1b0134a terminal-util: remove reset_terminal() as it is unused 2024-07-19 11:41:43 +02:00
Lennart Poettering 841eb9c186 terminal-util: don't issue "ESC c" sequence on reset, but only when erasing the screen
ESC c is a (vaguely defined) "reset to initial state" ANSI sequence.
Many terminals clear the screen in this case, but that's a bit drastic I
think for most resets.

ESC c was added to the reset logic in
00bc83a275 (i.e. very recently), and I
don't think the effect was clear at that time.

Let's keep the ESC c in place however when we actually want to clear the
screen. Hence move it from reset_terminal_fd() into vt_disallocate().

Fixes: #33689
2024-07-19 11:41:43 +02:00
Lennart Poettering cfac09083b terminal-util: add new helper terminal_reset_defensive() that combines reset-by-ioctl and reset-by-sequence reasonably 2024-07-19 11:41:43 +02:00
Lennart Poettering ce3a1593bc terminal-util: add terminal_is_pty_fd() helper
The helper checks if an fd references a pty
2024-07-19 11:41:43 +02:00
Lennart Poettering 2736295ddb terminal-util: unify code that resets /dev/console in common helper
We have pretty much the same code at two places, let's make it one.
2024-07-19 11:41:43 +02:00
Lennart Poettering 963e25c23b terminal-util: reset /dev/console via ansi seq also in make_console_stdio()
This appears to have been the intention of
00bc83a275, judging by the comments on
that.
2024-07-19 11:41:43 +02:00
Lennart Poettering f6927e3c98 terminal-util: try to initialize rows/cols via ansi sequence in make_console_stdio()
Let's hook this up.
2024-07-19 11:41:43 +02:00