Commit Graph

5993 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
4eb3ec63b0 basic/socket-util: use strdup_to() in sockaddr_pretty()
The function was written to support ret==NULL, but the only caller always
passes ret, and sockaddr_pretty() also requires ret to be set, so that
half-implemented code wasn't very useful.
2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek
94b75cdb06 basic/fileio: use strdup_to_full() in read_stripped_line()
The return value of read_stripped_line() is changed. Before we'd return the
number of characters read, but that number was not meaningful after we called
strstrip(). So just return 0 if nothing was read (EOF), and 1 if something was
read (not EOF). All the callers were only checking for <0 or ==0.
2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek
4f77ddca59 various: also use strdup_to() in cases where we don't return immediately 2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek
418b936d47 various: use strdup_to() after getenv() 2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek
454318d3e8 various: use strdup_to() in various obvious cases
strdup_to() returns 0 on success and here we convert obvious blocks
which either return -ENOMEM or 0.
2024-03-20 15:13:44 +01:00
Zbigniew Jędrzejewski-Szmek
8922a728f7 basic/cgroup-util: use strdup_to() and strdup_to_full() as appropriate 2024-03-20 15:13:44 +01:00
Zbigniew Jędrzejewski-Szmek
892c5902ae src/basic: add yet another strdup helper
It's a bit ugly to have both strdup_to() and strdup_to_full(). I initially
started with one variant, but then in some functions we want the additional
info, while in many other places, having 1 instead of 0 causes the return
value of whole chains of functions to be changed. It *probably* wouldn't cause
any difference, but there is at least of bunch of tests that would need to be
updated, so in the end it seems to have the two variants.

The output param is first to match free_and_strdup() and other similar
functions.
2024-03-20 15:12:12 +01:00
Abraham Samuel Adekunle
fcf38e2cb3 Add unittest file for basic:label 2024-03-18 11:04:42 +00:00
Yu Watanabe
d30d44883f stat-util: expose fd_is_read_only_fs()
Currently it is not used, but the fucntion is already quite generic and
useful.
2024-03-14 23:45:27 +08:00
Yu Watanabe
cdafb51ab4 Merge pull request #31754 from YHNdnzj/journal-fd-namespace
journal/cat: allow connecting output to specific journal namespace
2024-03-14 19:59:19 +09:00
Lennart Poettering
837eda0522 Merge pull request #31770 from poettering/linkat-replace
introduce linkat_replace() helper, and port various things over to it
2024-03-14 11:03:59 +01:00
Yu Watanabe
f03caa0d3e stat-util: fix typo
Follow-up for 7cff2b79f0.
2024-03-14 17:37:50 +09:00
Lennart Poettering
ccec206498 tmpfile-util: port link_tmpfile_at() over to linkat_replace() 2024-03-14 09:22:09 +01:00
Lennart Poettering
1f27e7b724 fs-util: add new helper linkat_replace() 2024-03-14 09:22:09 +01:00
Lennart Poettering
0b8e36f064 fs-util: move link_fd() from tmpfile-util.c into generic fs-util.c
It's a generically useful call, let's move it so that we can use it at
more places.
2024-03-14 09:17:46 +01:00
Lennart Poettering
dd92ba8a7a path-util: add helper that checks if a path definitely refers to a dir 2024-03-14 09:17:46 +01:00
Mike Yuan
baaca3db6a path-util: introduce skip_leading_slash and use it where appropriate 2024-03-14 14:25:52 +08:00
Lennart Poettering
95db87ffed Merge pull request #31731 from poettering/stat-is-set
stat-util: add explicit helpers for checking if stat/statx is initialized
2024-03-13 10:37:15 +01:00
Mike Yuan
a793133963 Merge pull request #31727 from YHNdnzj/homed-followup
data-fd-util: some cleanups
2024-03-13 13:10:34 +08:00
Lars Ellenberg
b8e25bff38 fs-utils: new wrapper fd_reopen_propagate_append_and_position()
We may want to propagate O_APPEND, or (try to) keep the current file position,
even if we use fd_reopen() to re-initialize (and "unshare") other file
description status.

For now, used only with --pty to keep/propagate O_APPEND (and/or) position
if set on stdin/stdout.

If we re-open stdout and "drop" the O_APPEND,
we get rather "unexpected" behavior,
for example with repeated "systemd-run --pty >> some-log".

If someone carefully pre-positioned the passed in original file descriptors,
we avoid surprises if we do not reset file postition to zero.

fcntl F_GETFL first, and propagate O_APPEND if present in the existing flags.

Then use lseek to propagate the file position.
2024-03-12 19:01:00 +01:00
Lennart Poettering
7cff2b79f0 stat-util: make sure inode_type_to_string() handles anonymous inodes in a reasonable way 2024-03-12 10:45:24 +01:00
Lennart Poettering
1c248d7fb7 stat-util: add explicit helpers for checking if stat/statx is initialized
This is a follow-up for 945a8210c7 and
makes the st_dev check generic, so that we can reuse it some other
places. It also incorporates the non-NULL check now, to be a
comprehensive one-stop solution.

The helper is static inline so that compilers can optimize the redundant
checks away in case it is combined with other checks.
2024-03-12 10:25:48 +01:00
Mike Yuan
faadc90c33 fileio,data-fd-util: use U64_* more 2024-03-12 16:42:48 +08:00
Mike Yuan
8b8edb512a env-util: remove unneeded DISABLE_WARNING_FORMAT_NONLITERAL
_printf_ is used, so this shouldn't emit a warning
in the first place.
2024-03-12 15:41:51 +08:00
Mike Yuan
18eebde33a Merge pull request #31713 from YHNdnzj/pidref-equal
pidref: use fd_inode_same to compare pidfds
2024-03-12 14:15:36 +08:00
Yu Watanabe
3ecd6fa98b time-util: expose map_clock_usec_internal() as map_clock_usec_raw()
This will be used later.
2024-03-12 01:57:17 +09:00
Mike Yuan
2f41f10bcd pidref: use fd_inode_same to compare pidfds 2024-03-11 22:57:50 +08:00
Mike Yuan
945a8210c7 stat-util: struct stat could be initialized with (st_mode & S_IFMT == 0)
For anonymous inodes, the result would be 0, but
the struct stat is initialized obviously.
So let's switch to st_dev for the check, which
is guaranteed to be non-zero.

Also this is completely unnecessary for statx(),
since we check stx_mask first and that on its own
denotes that the struct is initialized.
2024-03-11 22:57:50 +08:00
Mike Yuan
0cdb8df620 stat-util: introduce fd_inode_same 2024-03-11 22:53:08 +08:00
Lennart Poettering
9f65355b85 fd-util: beef up fd_verify_safe_flags() features
Let's make fd_verify_safe_flags() even more useful:

1. let's return the cleaned up flags (i.e. just the access mode) after
   validation, hiding all the noise, such as O_NOFOLLOW, O_LARGEFILE and
   similar.

2. let's add a "full" version of the call that allows passing additional
   flags that are OK to be set.
2024-03-11 14:49:51 +01:00
cpackham-atlnz
ed01b92e1c basic: add PIDFS magic (#31709)
Kernel commit cb12fd8e0dabb9a1c8aef55a6a41e2c255fcdf4b added pidfs.
Update filesystems-gperf.gperf and missing_magic.h accordingly.

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: PID_FS_MAGIC
```
2024-03-11 11:55:36 +00:00
Thomas Blume
fc5c6eccb4 units: make templates for quotaon and systemd-quotacheck service 2024-03-09 19:32:09 +00:00
Zbigniew Jędrzejewski-Szmek
ec596fe34e Merge pull request #30480 from keszybz/kernel-install-more-paths
Read kernel-install config from /run/kernel too
2024-03-08 08:25:07 +01:00
Zbigniew Jędrzejewski-Szmek
9bc7493098 strv: add helper to extend strv from both sides
Also, use the more correct type of 'const char* const*' for the input strv.
This requires adding the cast in a few places, but also allows to remove some
casts in others.
2024-03-07 18:49:44 +01:00
Zbigniew Jędrzejewski-Szmek
76d75d8b7b constants: drop duplicated CONF_PATHS defines
Follow-up for b0d3095fd6.
2024-03-07 18:47:50 +01:00
Mike Yuan
5ba6321d86 bus-unit-util: define FREEZE_BUS_CALL_TIMEOUT locally
Follow-up for f274f8bf25

We define *_SLOW_BUS_CALL_TIMEOUT in each component's
own file too. This one is no different and doesn't need
to be in constants.h IMO.
2024-03-08 01:09:01 +08:00
Luca Boccassi
5e418fe32a Merge pull request #31590 from YHNdnzj/install-cleanup
shared/install: several cleanups
2024-03-07 11:28:04 +00:00
Luca Boccassi
60cf40599a escape: fix operator precedence in overflow check
CID#1535100

Follow-up for c6342e35b0
2024-03-07 00:46:21 +00:00
Mike Yuan
7dfc71399d path-lookup: rename lookup_paths_free -> _done
This is stack-allocated, so update to match our usual rules.
2024-03-07 02:01:57 +08:00
Yu Watanabe
3d1279af79 meson: add missing dependency to libdl
Follow-up for 1c20c9f4fc.

Fixes https://github.com/systemd/systemd/pull/31550#issuecomment-1980458377.
2024-03-06 17:24:03 +00:00
Luca Boccassi
5e575e4d92 Merge pull request #31580 from poettering/resolved-naptr
resolved: properly decode NAPTR RRs
2024-03-06 14:14:11 +00:00
Lennart Poettering
d49dc7bbe7 string-util: allow taking SIZE_MAX as size to shorten to
This is useful for two reasons:

1. it addresses a potential overflow in a graceful way

2. Gives callers the ability to just pass SIZE_MAX for a NOP

Prompted by: #31341
2024-03-06 13:24:15 +00:00
Mike Yuan
771bf2274a basic: remove spuriously doubled newline and leftover separator
Follow-up for 3fc72d5413
2024-03-06 03:29:12 +08:00
Lennart Poettering
c6342e35b0 escape: teach octescape() to work with NUL terminated strings 2024-03-05 15:46:31 +01:00
Matteo Croce
3fc72d5413 dynamically load compression libraries
Dynamically load liblz4, libzstd and liblzma with dlopen().
This helps to reduce the size of the initrd image when these libraries
are not really needed.
2024-03-05 12:37:21 +01:00
Matteo Croce
1c20c9f4fc move dlfcn-util into basic
I'm going to dlopen_many_sym_or_warn() in src/basic/compress.c, this
will introduce a circular dependency because libshared already depends
from libbasic.
To avoid this, move dlfcn-util.c from libshared to libbasic.
2024-03-05 12:33:44 +01:00
Mike Yuan
2560dcbfe6 stat-util: generalize is_* and verify_* handling 2024-03-04 19:53:51 +00:00
Mike Yuan
4f49512695 extract-word: modernize extract_many_words 2024-03-03 19:01:00 +08:00
Lennart Poettering
e28b70a527 hashmap: reorder fields to pack structure better
When building with ENABLE_DEBUG_HASHMAP we can pack the hashmap iterator
structure a bit better.

Fixes: #31558
2024-03-02 11:47:34 +09:00
Lennart Poettering
71cb203a6e importctl: draw a pretty progress bar while downloading
Everybody loves pretty terminal progress bar.
2024-03-01 22:25:42 +01:00