Commit Graph

6158 Commits

Author SHA1 Message Date
Luca Boccassi
656b0f5031 Merge pull request #32559 from poettering/varlink-comments
varlink: add nice commenting to our varlink IDL data
2024-06-17 18:53:11 +01:00
Mike Yuan
f3d7ceb5c5 Merge pull request #32872 from YHNdnzj/pidref-inode
pidref: record pidfd inode number in PidRef struct
2024-06-17 18:47:44 +02:00
Luca Boccassi
9981bc210a Merge pull request #33355 from YHNdnzj/shutdown-cad
shutdown: re-enable CAD handling in kernel at start, several other cleanups
2024-06-17 09:19:08 +01:00
Lennart Poettering
aca093018c strv: add new helper strv_rebreak_lines() with a simple line breaking algorithm 2024-06-17 09:20:21 +02:00
Lennart Poettering
9632f8b465 utf8: export utf8_char_console_width() 2024-06-17 09:20:21 +02:00
Mike Yuan
e2b812c804 string-util: introduce string_is_safe_ascii helper 2024-06-16 19:07:35 +02:00
Mike Yuan
4d06bf5922 basic/utf8: modernize ascii_is_valid_n, make ascii_is_valid static inline 2024-06-16 19:07:35 +02:00
Mike Yuan
7ff7161044 basic/utf8: modernize utf8_is_valid_n a bit 2024-06-16 19:07:34 +02:00
Luca Boccassi
2a00e92598 Merge pull request #33352 from YHNdnzj/freeconp-void
Trivial follow-ups for recent PRs
2024-06-15 19:57:13 +01:00
Mike Yuan
c1bf0571c0 string-util: modernize first_word a bit 2024-06-15 19:19:39 +02:00
Lennart Poettering
4d6222b6a4 random-util: add crypto_random_bytes_allocate_iovec()
Just a simple helper that allocates some memory, initializes it
randomly, and places this in a struct iovec.
2024-06-15 12:43:37 +01:00
Mike Yuan
c89d1e425a missing_loop: add missing assertions for fallback values 2024-06-15 13:05:50 +02:00
Mike Yuan
609bc3ae16 Merge pull request #33037 from keszybz/dlopen-open-code-definitions
Make dlopen macros more explicit and drop mac_selinux_free()
2024-06-15 12:49:59 +02:00
Lennart Poettering
bba55185de utf8: let utf8_console_width() handle NULL strings somewhat reasonably 2024-06-15 00:46:42 +01:00
Luca Boccassi
78fb0ca46d Merge pull request #33325 from poettering/vsock-ret-optional
socket-util: make return parameter for socket_address_parse_vsock() o…
2024-06-15 00:45:28 +01:00
Raphaël Mélotte
56ab1c5449 src/basic/missing_loop.h: fix missing LOOP_SET_BLOCK_SIZE
Builds with kernels headers < 4.14 fail with:

../src/shared/loop-util.c: In function ‘loop_configure_fallback’:
../src/shared/loop-util.c:237:31: error: ‘LOOP_SET_BLOCK_SIZE’ undeclared (first use in this function); did you mean ‘LOOP_SET_DIRECT_IO’?
                 if (ioctl(fd, LOOP_SET_BLOCK_SIZE, (unsigned long) c->block_size) < 0)
                               ^~~~~~~~~~~~~~~~~~~
                               LOOP_SET_DIRECT_IO

Fixes: https://github.com/systemd/systemd/issues/33341

Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
2024-06-15 00:01:44 +01:00
Lennart Poettering
c29778a100 fs-util: add simple open_mkdir() wrapper 2024-06-14 23:50:59 +01:00
Lennart Poettering
b22635083a string-util: make sure strrepa() doesn't doubly evaluate expressions 2024-06-14 23:50:03 +01:00
Lennart Poettering
dc163cd40b fileio: add new helper write_base64_file_at() which encodes a binary object into base64 and writes it to a file 2024-06-14 22:50:33 +01:00
Lennart Poettering
b4aaba2bb0 utf8: assume tabs are 8 characters wide when written to console 2024-06-14 21:17:20 +01:00
Mike Yuan
15930d5d9f pidref: record pidfd inode number in PidRef struct
Besides internal comparisons, the inode number of pidfds
might be interesting directly to users, too. In the future
this field should also be exposed, so that it can serve as
a unique identifier of a process (but only for display,
as there's no method to map this back to a pid or pidfd).
2024-06-14 16:59:13 +02:00
Mike Yuan
1b6239632d pidref: introduce pidfd_inode_ids_supported helper
Also, correct the comment about pidfs (added in kernel 6.9
rather than 6.8).

Co-authored-by: Lennart Poettering <lennart@poettering.net>
2024-06-14 16:46:03 +02:00
Lennart Poettering
432977a0a4 iovec-util: add exported constant empty but valid (i.e. non-NULL) iovec
Also, make sure the NUL byte iovec becomes an exported constant too.

This is better than the previous situation where this was a macro
resolving to a compount expression, since the lifetime of the expression
is limited to its invoking scope. By turning this into a proper variable
the lifetime becomes unbounded, which makes it easier to use in various
scenarios, such as "if" blocks.
2024-06-14 12:42:07 +01:00
Lennart Poettering
59c8110ac6 socket-util: make return parameter for socket_address_parse_vsock() optional 2024-06-14 11:12:56 +02:00
Mike Yuan
0160a1dbbc io-util: move fputs_with_newline to fileio
Follow-up for cdf6f34a2f

We already have other fputs()-like helpers in fileio rather than
io-util. While at it, switch the order of params.
2024-06-13 15:56:02 +01:00
Lennart Poettering
cdf6f34a2f io-util: add new helper fputs_with_newline() 2024-06-13 09:33:13 +02:00
Zbigniew Jędrzejewski-Szmek
5c672e90a6 basic/dlfcn-util: deobfuscate macro definitions
When looking at how dlopen for various libs is implemented, I found that the
macros hide too much. I find it much easier to see what is going on if 'extern'
and '= NULL' are written explicitly. After all, we don't hide those for other
definitions, e.g. our style guide says that static variables should be
initialized with '= NULL'. With that change, it's much more obvious what is
a variable declaration and what is a variable initialization.
2024-06-12 15:21:15 +02:00
Luca Boccassi
aa6d1f16e8 Merge pull request #33284 from yuwata/hwdb-optimize
hwdb: improve performance
2024-06-12 14:02:25 +01:00
Yu Watanabe
21f51d877f Merge pull request #32961 from YHNdnzj/starttime-main
core/service: try to query for new main process's starttime
2024-06-12 19:12:37 +09:00
Yu Watanabe
707890d4ff Merge pull request #33074 from keszybz/bpf-fd-handling
Small cleanups in bpf code
2024-06-12 18:44:30 +09:00
Yu Watanabe
12c9ebbbe4 Merge pull request #32933 from YHNdnzj/faccessat-empty-path
fs-util: several cleanups
2024-06-12 18:35:13 +09:00
Yu Watanabe
29d5da5fef Merge pull request #32603 from YHNdnzj/install-basename
shared/install: modernize and eliminate the use of basename()
2024-06-12 18:22:10 +09:00
Yu Watanabe
3bc70f104e strbuf: make length for strbuf_add_string() optional 2024-06-12 18:19:29 +09:00
Yu Watanabe
34d4e6f32a strbuf: several cleanups for strbuf_add_string()
- add missing assertions,
- use GREEDY_REALLOC() at one more place,
- etc.

Before:
```
$ sudo time valgrind --leak-check=full ./systemd-hwdb update
==112572== Memcheck, a memory error detector
==112572== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==112572== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==112572== Command: ./systemd-hwdb update
==112572==
==112572==
==112572== HEAP SUMMARY:
==112572==     in use at exit: 0 bytes in 0 blocks
==112572==   total heap usage: 1,320,113 allocs, 1,320,113 frees, 70,614,501 bytes allocated
==112572==
==112572== All heap blocks were freed -- no leaks are possible
==112572==
==112572== For lists of detected and suppressed errors, rerun with: -s
==112572== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
21.94user 0.19system 0:22.23elapsed 99%CPU (0avgtext+0avgdata 229876maxresident)k
0inputs+25264outputs (0major+57275minor)pagefaults 0swaps
```

After:
```
$ sudo time valgrind --leak-check=full ./systemd-hwdb update
[sudo] password for watanabe:
==114732== Memcheck, a memory error detector
==114732== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==114732== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==114732== Command: ./systemd-hwdb update
==114732==
==114732==
==114732== HEAP SUMMARY:
==114732==     in use at exit: 0 bytes in 0 blocks
==114732==   total heap usage: 1,276,406 allocs, 1,276,406 frees, 68,500,491 bytes allocated
==114732==
==114732== All heap blocks were freed -- no leaks are possible
==114732==
==114732== For lists of detected and suppressed errors, rerun with: -s
==114732== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
21.91user 0.24system 0:22.26elapsed 99%CPU (0avgtext+0avgdata 233584maxresident)k
0inputs+25168outputs (0major+58237minor)pagefaults 0swaps
```
2024-06-12 18:17:46 +09:00
q66
621b10fe2c strbuf: use GREEDY_REALLOC to grow the buffer
This allows us to reserve a bunch of capacity ahead of time,
improving the performance of hwdb significantly thanks to not
having to reallocate so many times.

Before:
```
$ sudo time valgrind --leak-check=full ./systemd-hwdb update
==113297== Memcheck, a memory error detector
==113297== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==113297== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==113297== Command: ./systemd-hwdb update
==113297==
==113297==
==113297== HEAP SUMMARY:
==113297==     in use at exit: 0 bytes in 0 blocks
==113297==   total heap usage: 1,412,640 allocs, 1,412,640 frees, 117,920,009,195 bytes allocated
==113297==
==113297== All heap blocks were freed -- no leaks are possible
==113297==
==113297== For lists of detected and suppressed errors, rerun with: -s
==113297== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
132.44user 21.15system 2:35.61elapsed 98%CPU (0avgtext+0avgdata 228560maxresident)k
0inputs+25296outputs (0major+6886930minor)pagefaults 0swaps
```

After:
```
$ sudo time valgrind --leak-check=full ./systemd-hwdb update
==112572== Memcheck, a memory error detector
==112572== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==112572== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==112572== Command: ./systemd-hwdb update
==112572==
==112572==
==112572== HEAP SUMMARY:
==112572==     in use at exit: 0 bytes in 0 blocks
==112572==   total heap usage: 1,320,113 allocs, 1,320,113 frees, 70,614,501 bytes allocated
==112572==
==112572== All heap blocks were freed -- no leaks are possible
==112572==
==112572== For lists of detected and suppressed errors, rerun with: -s
==112572== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
21.94user 0.19system 0:22.23elapsed 99%CPU (0avgtext+0avgdata 229876maxresident)k
0inputs+25264outputs (0major+57275minor)pagefaults 0swaps
```

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2024-06-12 18:16:27 +09:00
Matthieu Baerts (NGI0)
3f69070598 core/socket: allow MPTCP protocol
Multipath TCP (MPTCP), standardized in RFC8684 [1], is a TCP extension
that enables a TCP connection to use different paths. It allows a device
to make use of multiple interfaces at once to send and receive TCP
packets over a single MPTCP connection. MPTCP can aggregate the
bandwidth of multiple interfaces or prefer the one with the lowest
latency, it also allows a fail-over if one path is down, and the traffic
is seamlessly re-injected on other paths.

To benefit from MPTCP, both the client and the server have to support
it. Multipath TCP is a backward-compatible TCP extension that is enabled
by default on recent Linux distributions (Debian, Ubuntu, Redhat, ...).
Multipath TCP is included in the Linux kernel since version 5.6 [2]. To
use it on Linux, an application must explicitly enable it when creating
the socket:

  int sd = socket(AF_INET(6), SOCK_STREAM, IPPROTO_MPTCP);

No need to change anything else in the application.

This patch allows MPTCP protocol in the Socket unit configuration. So
now, a <unit>.socket can contain this to use MPTCP instead of TCP:

  [Socket]
  SocketProtocol=mptcp

MPTCP support has been allowed similarly to what has been already done
to allow SCTP: just one line in core/socket.c, a very simple addition
thanks to the flexible architecture already in place.

On top of that, IPPROTO_MPTCP has also been added in the list of allowed
protocols in two other places, and in the doc. It has also been added to
the missing_network.h file, for systems with an old libc -- note that it
was also required to include <netinet/in.h> in this file to avoid
redefinition errors.

Link: https://www.rfc-editor.org/rfc/rfc8684.html [1]
Link: https://www.mptcp.dev [2]
2024-06-12 00:14:08 +01:00
Mike Yuan
178a71d970 unit-file,portable: replace streq + basename with path_equal_filename 2024-06-11 23:17:21 +01:00
Daan De Meyer
7efaab482a chase: Tighten "." and "./" check
Currently the check also succeeds if the input path starts with a dot, whereas
we only want it to succeed for "." and "./". Tighten the check and add a test.
2024-06-11 13:55:35 +01:00
Mike Gilbert
953c60e2f1 user-util: fix fgetxxent_sane on musl
musl's implementation does not set errno to ENOENT when the end of file
is reached. It returns NULL and leaves errno unchanged.
2024-06-10 11:41:55 +02:00
Luca Boccassi
bed6e7c8b4 Update syscalls tables
ninja -C build update-syscall-tables update-syscall-header
2024-06-06 17:56:12 +01:00
Luca Boccassi
67dfbe021c util: add keyring_describe helper and move to basic
So that it can be used from libsystemd. No external dependencies.
2024-06-06 11:39:56 +01:00
Chris Packham
201148b08d basic: Add BCACHEFS magic
Import magic.h from Linux 6.9 to get the definition of
BCACHEFS_SUPER_MAGIC. Update filesystems-gperf.gperf to add knowledge of
bcachefs.

This fixes the following error building against a bleeding edge kernel.
```
src/basic/meson.build:234:8: ERROR: Problem encountered: Unknown filesystems defined in kernel headers:

Filesystem found in kernel header but not in filesystems-gperf.gperf: BCACHEFS_SUPER_MAGIC
```
2024-05-31 11:14:37 +09:00
Luca Boccassi
0630069f0b Merge pull request #33081 from keszybz/networkctl-formatting
Fix formatting of speeds in networkctl
2024-05-30 16:33:38 +02:00
Zbigniew Jędrzejewski-Szmek
613b698eb4 basic/fd-util: drop report from fd_cloexec_many
fd_cloexec_many promised to report if work was done, but that code was
not effective, because it always reported true if any fds were open.
But no callers care about the return value, so let's just drop this.
2024-05-30 12:07:57 +02:00
Zbigniew Jędrzejewski-Szmek
4199866ac5 basic/fd-util: drop unnecessary {} 2024-05-30 12:07:57 +02:00
Zbigniew Jędrzejewski-Szmek
11226bf19b shared/format-table: do not print '.0'
This makes output a bit shorter and nicer. For us, shorter output is generally
better.

Also, drop unnecessary UINT64_C macros. The left operand is always uint64_t,
and C upcasting rules mean that it doesn't matter if the right operand is
narrower or signed, the operation is always done on the wider unsigned type.
2024-05-30 11:38:30 +02:00
Daan De Meyer
8783355fd9 cgroup-util: Don't try to open pidfd for pids from cgroup.threads
Opening pidfds for non thread group leaders only works from 6.9 onwards with PIDFD_THREAD. On
older kernels or without PIDFD_THREAD pidfd_open() fails with EINVAL. Since we might read non
thread group leader IDs from cgroup.threads, we introduce and set CGROUP_NO_PIDFD to avoid
trying open pidfd's for them and instead use the pid as is.
2024-05-30 10:30:36 +02:00
Daan De Meyer
9ac8450e7f basic: Add debug logging for pidref_set_pid() 2024-05-29 21:04:13 +02:00
Daan De Meyer
330ecca853 cgroup-util: Add debug logging for cg_kill_recursive() 2024-05-29 21:04:09 +02:00
Mike Yuan
1e1df05296 socket-util: use GREEDY_REALLOC_APPEND where appropriate
Also, previously GREEDY_REALLOC was used improperly,
causing the fds_array to be leaked when realloc() fails.
2024-05-28 15:42:14 +02:00