summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-04-08 15:43:09 +0200
committerGitHub <noreply@github.com>2022-04-08 15:43:09 +0200
commit492f9e74ff2b7b07d0999a7241c16ed5e767fdeb (patch)
tree646bf40bdd3b0c710d1dd2dddbef284767805f6a
parent15ac2a62f2f0ad9f3bc04c4a7c980ea8f7e832b5 (diff)
parent6eb32c7f2e0a66154832dda2d5b9e8329eba9320 (diff)
downloadsystemd-492f9e74ff2b7b07d0999a7241c16ed5e767fdeb.tar.gz
Merge pull request #23009 from keszybz/fix-detection-of-libsystemd-shared-with-suffix
Fix detection of libsystemd-shared with suffix
-rw-r--r--README1
-rw-r--r--src/basic/missing_syscall_def.h1
-rw-r--r--src/basic/missing_syscalls.py1
-rw-r--r--src/basic/path-util.c118
-rw-r--r--src/basic/path-util.h10
-rw-r--r--src/basic/syscall-list.txt1
-rw-r--r--src/basic/syscalls-alpha.txt1
-rw-r--r--src/basic/syscalls-arc.txt1
-rw-r--r--src/basic/syscalls-arm.txt1
-rw-r--r--src/basic/syscalls-arm64.txt1
-rw-r--r--src/basic/syscalls-i386.txt1
-rw-r--r--src/basic/syscalls-ia64.txt1
-rw-r--r--src/basic/syscalls-loongarch64.txt1
-rw-r--r--src/basic/syscalls-m68k.txt1
-rw-r--r--src/basic/syscalls-mips64.txt1
-rw-r--r--src/basic/syscalls-mips64n32.txt1
-rw-r--r--src/basic/syscalls-mipso32.txt1
-rw-r--r--src/basic/syscalls-powerpc.txt1
-rw-r--r--src/basic/syscalls-powerpc64.txt1
-rw-r--r--src/basic/syscalls-riscv32.txt1
-rw-r--r--src/basic/syscalls-riscv64.txt1
-rw-r--r--src/basic/syscalls-s390.txt1
-rw-r--r--src/basic/syscalls-s390x.txt1
-rw-r--r--src/basic/syscalls-sparc.txt1
-rw-r--r--src/basic/syscalls-x86_64.txt1
-rw-r--r--src/boot/efi/xbootldr.h1
-rw-r--r--src/core/load-fragment.c2
-rw-r--r--src/core/locale-setup.c3
-rw-r--r--src/journal-remote/journal-upload.c3
-rw-r--r--src/network/netdev/macsec.c2
-rw-r--r--src/network/netdev/wireguard.c2
-rw-r--r--src/network/networkd-wiphy.h1
-rw-r--r--src/nspawn/meson.build7
-rw-r--r--src/nspawn/nspawn-util.c69
-rw-r--r--src/nspawn/nspawn-util.h4
-rw-r--r--src/nspawn/nspawn.c6
-rw-r--r--src/nspawn/test-nspawn-util.c22
-rw-r--r--src/partition/repart.c3
-rw-r--r--src/shared/bus-unit-util.c2
-rw-r--r--src/shared/conf-parser.c1
-rw-r--r--src/shared/meson.build4
-rw-r--r--src/shared/parse-helpers.c (renamed from src/shared/parse-socket-bind-item.c)51
-rw-r--r--src/shared/parse-helpers.h25
-rw-r--r--src/shared/parse-socket-bind-item.h12
-rw-r--r--src/sysupdate/sysupdate-transfer.c2
-rw-r--r--src/test/meson.build2
-rw-r--r--src/test/test-parse-helpers.c (renamed from src/test/test-parse-socket-bind-item.c)2
-rw-r--r--src/test/test-path-util.c15
48 files changed, 218 insertions, 174 deletions
diff --git a/README b/README
index 6eaba9b0f1..109c093a6c 100644
--- a/README
+++ b/README
@@ -37,6 +37,7 @@ REQUIREMENTS:
≥ 4.10 for cgroup-bpf egress and ingress hooks
≥ 4.15 for cgroup-bpf device hook and cpu controller in cgroup v2
≥ 4.17 for cgroup-bpf socket address hooks
+ ≥ 4.20 for PSI (used by systemd-oomd)
≥ 5.3 for bounded loops in BPF program
≥ 5.4 for signed Verity images
≥ 5.7 for BPF links and the BPF LSM hook
diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h
index d078bf70df..88df92db61 100644
--- a/src/basic/missing_syscall_def.h
+++ b/src/basic/missing_syscall_def.h
@@ -4,6 +4,7 @@
* Use 'ninja -C build update-syscall-tables' to download new syscall tables,
* and 'ninja -C build update-syscall-header' to regenerate this file.
*/
+#pragma once
/* Note: if this code looks strange, this is because it is derived from the same
* template as the per-syscall blocks below. */
diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py
index 2694e83b98..83199bb1d7 100644
--- a/src/basic/missing_syscalls.py
+++ b/src/basic/missing_syscalls.py
@@ -142,6 +142,7 @@ def print_syscall_defs(syscalls, tables, out):
* Use 'ninja -C build update-syscall-tables' to download new syscall tables,
* and 'ninja -C build update-syscall-header' to regenerate this file.
*/
+#pragma once
''',
file=out)
print(ARCH_CHECK, file=out)
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index 5d93e107a7..94527eff4c 100644
--- a/src/basic/path-util.c
+++ b/src/basic/path-util.c
@@ -17,17 +17,13 @@
#include "extract-word.h"
#include "fd-util.h"
#include "fs-util.h"
-#include "glob-util.h"
#include "log.h"
#include "macro.h"
-#include "nulstr-util.h"
-#include "parse-util.h"
#include "path-util.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
-#include "utf8.h"
int path_split_and_make_absolute(const char *p, char ***ret) {
char **l;
@@ -376,52 +372,6 @@ char *path_simplify(char *path) {
return path;
}
-int path_simplify_and_warn(
- char *path,
- unsigned flag,
- const char *unit,
- const char *filename,
- unsigned line,
- const char *lvalue) {
-
- bool fatal = flag & PATH_CHECK_FATAL;
-
- assert(!FLAGS_SET(flag, PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE));
-
- if (!utf8_is_valid(path))
- return log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, path);
-
- if (flag & (PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE)) {
- bool absolute;
-
- absolute = path_is_absolute(path);
-
- if (!absolute && (flag & PATH_CHECK_ABSOLUTE))
- return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
- "%s= path is not absolute%s: %s",
- lvalue, fatal ? "" : ", ignoring", path);
-
- if (absolute && (flag & PATH_CHECK_RELATIVE))
- return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
- "%s= path is absolute%s: %s",
- lvalue, fatal ? "" : ", ignoring", path);
- }
-
- path_simplify(path);
-
- if (!path_is_valid(path))
- return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
- "%s= path has invalid length (%zu bytes)%s.",
- lvalue, strlen(path), fatal ? "" : ", ignoring");
-
- if (!path_is_normalized(path))
- return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
- "%s= path is not normalized%s: %s",
- lvalue, fatal ? "" : ", ignoring", path);
-
- return 0;
-}
-
char *path_startswith_full(const char *path, const char *prefix, bool accept_dot_dot) {
assert(path);
assert(prefix);
@@ -1314,74 +1264,6 @@ bool valid_device_allow_pattern(const char *path) {
return valid_device_node_path(path);
}
-int systemd_installation_has_version(const char *root, unsigned minimal_version) {
- const char *pattern;
- int r;
-
- /* Try to guess if systemd installation is later than the specified version. This
- * is hacky and likely to yield false negatives, particularly if the installation
- * is non-standard. False positives should be relatively rare.
- */
-
- NULSTR_FOREACH(pattern,
- /* /lib works for systems without usr-merge, and for systems with a sane
- * usr-merge, where /lib is a symlink to /usr/lib. /usr/lib is necessary
- * for Gentoo which does a merge without making /lib a symlink.
- */
- "lib/systemd/libsystemd-shared-*.so\0"
- "lib64/systemd/libsystemd-shared-*.so\0"
- "usr/lib/systemd/libsystemd-shared-*.so\0"
- "usr/lib64/systemd/libsystemd-shared-*.so\0") {
-
- _cleanup_strv_free_ char **names = NULL;
- _cleanup_free_ char *path = NULL;
- char *c;
-
- path = path_join(root, pattern);
- if (!path)
- return -ENOMEM;
-
- r = glob_extend(&names, path, 0);
- if (r == -ENOENT)
- continue;
- if (r < 0)
- return r;
-
- assert_se(c = endswith(path, "*.so"));
- *c = '\0'; /* truncate the glob part */
-
- STRV_FOREACH(name, names) {
- /* This is most likely to run only once, hence let's not optimize anything. */
- char *t, *t2;
- unsigned version;
-
- t = startswith(*name, path);
- if (!t)
- continue;
-
- t2 = endswith(t, ".so");
- if (!t2)
- continue;
-
- t2[0] = '\0'; /* truncate the suffix */
-
- r = safe_atou(t, &version);
- if (r < 0) {
- log_debug_errno(r, "Found libsystemd shared at \"%s.so\", but failed to parse version: %m", *name);
- continue;
- }
-
- log_debug("Found libsystemd shared at \"%s.so\", version %u (%s).",
- *name, version,
- version >= minimal_version ? "OK" : "too old");
- if (version >= minimal_version)
- return true;
- }
- }
-
- return false;
-}
-
bool dot_or_dot_dot(const char *path) {
if (!path)
return false;
diff --git a/src/basic/path-util.h b/src/basic/path-util.h
index 518f3340bf..553aa4fb58 100644
--- a/src/basic/path-util.h
+++ b/src/basic/path-util.h
@@ -77,14 +77,6 @@ char* path_extend_internal(char **x, ...);
char* path_simplify(char *path);
-enum {
- PATH_CHECK_FATAL = 1 << 0, /* If not set, then error message is appended with 'ignoring'. */
- PATH_CHECK_ABSOLUTE = 1 << 1,
- PATH_CHECK_RELATIVE = 1 << 2,
-};
-
-int path_simplify_and_warn(char *path, unsigned flag, const char *unit, const char *filename, unsigned line, const char *lvalue);
-
static inline bool path_equal_ptr(const char *a, const char *b) {
return !!a == !!b && (!a || path_equal(a, b));
}
@@ -181,8 +173,6 @@ bool is_device_path(const char *path);
bool valid_device_node_path(const char *path);
bool valid_device_allow_pattern(const char *path);
-int systemd_installation_has_version(const char *root, unsigned minimal_version);
-
bool dot_or_dot_dot(const char *path);
static inline const char *skip_dev_prefix(const char *p) {
diff --git a/src/basic/syscall-list.txt b/src/basic/syscall-list.txt
index 4e70907ade..fbc5566a65 100644
--- a/src/basic/syscall-list.txt
+++ b/src/basic/syscall-list.txt
@@ -473,6 +473,7 @@ sendmmsg
sendmsg
sendto
set_mempolicy
+set_mempolicy_home_node
set_robust_list
set_thread_area
set_tid_address
diff --git a/src/basic/syscalls-alpha.txt b/src/basic/syscalls-alpha.txt
index 5aef86b09e..38988407fc 100644
--- a/src/basic/syscalls-alpha.txt
+++ b/src/basic/syscalls-alpha.txt
@@ -473,6 +473,7 @@ sendmmsg 503
sendmsg 114
sendto 133
set_mempolicy 431
+set_mempolicy_home_node 560
set_robust_list 466
set_thread_area
set_tid_address 411
diff --git a/src/basic/syscalls-arc.txt b/src/basic/syscalls-arc.txt
index f275f104bf..801f551c25 100644
--- a/src/basic/syscalls-arc.txt
+++ b/src/basic/syscalls-arc.txt
@@ -473,6 +473,7 @@ sendmmsg 269
sendmsg 211
sendto 206
set_mempolicy 237
+set_mempolicy_home_node 450
set_robust_list 99
set_thread_area
set_tid_address 96
diff --git a/src/basic/syscalls-arm.txt b/src/basic/syscalls-arm.txt
index 9037b28384..94bbcbf703 100644
--- a/src/basic/syscalls-arm.txt
+++ b/src/basic/syscalls-arm.txt
@@ -473,6 +473,7 @@ sendmmsg 374
sendmsg 296
sendto 290
set_mempolicy 321
+set_mempolicy_home_node 450
set_robust_list 338
set_thread_area
set_tid_address 256
diff --git a/src/basic/syscalls-arm64.txt b/src/basic/syscalls-arm64.txt
index e91d7cfca4..207c43937e 100644
--- a/src/basic/syscalls-arm64.txt
+++ b/src/basic/syscalls-arm64.txt
@@ -473,6 +473,7 @@ sendmmsg 269
sendmsg 211
sendto 206
set_mempolicy 237
+set_mempolicy_home_node 450
set_robust_list 99
set_thread_area
set_tid_address 96
diff --git a/src/basic/syscalls-i386.txt b/src/basic/syscalls-i386.txt
index 6b57d6f05d..4c0c99368e 100644
--- a/src/basic/syscalls-i386.txt
+++ b/src/basic/syscalls-i386.txt
@@ -473,6 +473,7 @@ sendmmsg 345
sendmsg 370
sendto 369
set_mempolicy 276
+set_mempolicy_home_node 450
set_robust_list 311
set_thread_area 243
set_tid_address 258
diff --git a/src/basic/syscalls-ia64.txt b/src/basic/syscalls-ia64.txt
index 3d646f6d17..9346b2e0d1 100644
--- a/src/basic/syscalls-ia64.txt
+++ b/src/basic/syscalls-ia64.txt
@@ -473,6 +473,7 @@ sendmmsg 1331
sendmsg 1205
sendto 1199
set_mempolicy 1261
+set_mempolicy_home_node 1474
set_robust_list 1298
set_thread_area
set_tid_address 1233
diff --git a/src/basic/syscalls-loongarch64.txt b/src/basic/syscalls-loongarch64.txt
index 8b10af64db..848e9e90aa 100644
--- a/src/basic/syscalls-loongarch64.txt
+++ b/src/basic/syscalls-loongarch64.txt
@@ -473,6 +473,7 @@ sendmmsg 269
sendmsg 211
sendto 206
set_mempolicy 237
+set_mempolicy_home_node 450
set_robust_list 99
set_thread_area
set_tid_address 96
diff --git a/src/basic/syscalls-m68k.txt b/src/basic/syscalls-m68k.txt
index ef7295db2f..f5a95685f6 100644
--- a/src/basic/syscalls-m68k.txt
+++ b/src/basic/syscalls-m68k.txt
@@ -473,6 +473,7 @@ sendmmsg 372
sendmsg 367
sendto 366
set_mempolicy 270
+set_mempolicy_home_node 450
set_robust_list 304
set_thread_area 334
set_tid_address 253
diff --git a/src/basic/syscalls-mips64.txt b/src/basic/syscalls-mips64.txt
index 1f7ff567be..7d0b9976b0 100644
--- a/src/basic/syscalls-mips64.txt
+++ b/src/basic/syscalls-mips64.txt
@@ -473,6 +473,7 @@ sendmmsg 5302
sendmsg 5045
sendto 5043
set_mempolicy 5229
+set_mempolicy_home_node 5450
set_robust_list 5268
set_thread_area 5242
set_tid_address 5212
diff --git a/src/basic/syscalls-mips64n32.txt b/src/basic/syscalls-mips64n32.txt
index 7e1ad9637d..2e15c66124 100644
--- a/src/basic/syscalls-mips64n32.txt
+++ b/src/basic/syscalls-mips64n32.txt
@@ -473,6 +473,7 @@ sendmmsg 6307
sendmsg 6045
sendto 6043
set_mempolicy 6233
+set_mempolicy_home_node 6450
set_robust_list 6272
set_thread_area 6246
set_tid_address 6213
diff --git a/src/basic/syscalls-mipso32.txt b/src/basic/syscalls-mipso32.txt
index c0c262fd1a..a8d95e3e35 100644
--- a/src/basic/syscalls-mipso32.txt
+++ b/src/basic/syscalls-mipso32.txt
@@ -473,6 +473,7 @@ sendmmsg 4343
sendmsg 4179
sendto 4180
set_mempolicy 4270
+set_mempolicy_home_node 4450
set_robust_list 4309
set_thread_area 4283
set_tid_address 4252
diff --git a/src/basic/syscalls-powerpc.txt b/src/basic/syscalls-powerpc.txt
index 2f085161e1..ad68616e25 100644
--- a/src/basic/syscalls-powerpc.txt
+++ b/src/basic/syscalls-powerpc.txt
@@ -473,6 +473,7 @@ sendmmsg 349
sendmsg 341
sendto 335
set_mempolicy 261
+set_mempolicy_home_node 450
set_robust_list 300
set_thread_area
set_tid_address 232
diff --git a/src/basic/syscalls-powerpc64.txt b/src/basic/syscalls-powerpc64.txt
index 85e53422ee..9e8dc6dd8c 100644
--- a/src/basic/syscalls-powerpc64.txt
+++ b/src/basic/syscalls-powerpc64.txt
@@ -473,6 +473,7 @@ sendmmsg 349
sendmsg 341
sendto 335
set_mempolicy 261
+set_mempolicy_home_node 450
set_robust_list 300
set_thread_area
set_tid_address 232
diff --git a/src/basic/syscalls-riscv32.txt b/src/basic/syscalls-riscv32.txt
index 013e38189b..2a4aceff94 100644
--- a/src/basic/syscalls-riscv32.txt
+++ b/src/basic/syscalls-riscv32.txt
@@ -473,6 +473,7 @@ sendmmsg 269
sendmsg 211
sendto 206
set_mempolicy 237
+set_mempolicy_home_node 450
set_robust_list 99
set_thread_area
set_tid_address 96
diff --git a/src/basic/syscalls-riscv64.txt b/src/basic/syscalls-riscv64.txt
index 104a2d9dfa..07d1d4253a 100644
--- a/src/basic/syscalls-riscv64.txt
+++ b/src/basic/syscalls-riscv64.txt
@@ -473,6 +473,7 @@ sendmmsg 269
sendmsg 211
sendto 206
set_mempolicy 237
+set_mempolicy_home_node 450
set_robust_list 99
set_thread_area
set_tid_address 96
diff --git a/src/basic/syscalls-s390.txt b/src/basic/syscalls-s390.txt
index a25093c7be..bbc824c005 100644
--- a/src/basic/syscalls-s390.txt
+++ b/src/basic/syscalls-s390.txt
@@ -473,6 +473,7 @@ sendmmsg 358
sendmsg 370
sendto 369
set_mempolicy 270
+set_mempolicy_home_node 450
set_robust_list 304
set_thread_area
set_tid_address 252
diff --git a/src/basic/syscalls-s390x.txt b/src/basic/syscalls-s390x.txt
index b4b798f9df..bc385eabad 100644
--- a/src/basic/syscalls-s390x.txt
+++ b/src/basic/syscalls-s390x.txt
@@ -473,6 +473,7 @@ sendmmsg 358
sendmsg 370
sendto 369
set_mempolicy 270
+set_mempolicy_home_node 450
set_robust_list 304
set_thread_area
set_tid_address 252
diff --git a/src/basic/syscalls-sparc.txt b/src/basic/syscalls-sparc.txt
index a382e75c24..6c39ad86f4 100644
--- a/src/basic/syscalls-sparc.txt
+++ b/src/basic/syscalls-sparc.txt
@@ -473,6 +473,7 @@ sendmmsg 336
sendmsg 114
sendto 133
set_mempolicy 305
+set_mempolicy_home_node 450
set_robust_list 300
set_thread_area
set_tid_address 166
diff --git a/src/basic/syscalls-x86_64.txt b/src/basic/syscalls-x86_64.txt
index 5bc9c58a2a..2942c2e489 100644
--- a/src/basic/syscalls-x86_64.txt
+++ b/src/basic/syscalls-x86_64.txt
@@ -473,6 +473,7 @@ sendmmsg 307
sendmsg 46
sendto 44
set_mempolicy 238
+set_mempolicy_home_node 450
set_robust_list 273
set_thread_area 205
set_tid_address 218
diff --git a/src/boot/efi/xbootldr.h b/src/boot/efi/xbootldr.h
index 4cb370af29..205ce71edf 100644
--- a/src/boot/efi/xbootldr.h
+++ b/src/boot/efi/xbootldr.h
@@ -1,4 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
#include <efi.h>
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 66e0c01c23..74c41335ca 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -49,7 +49,7 @@
#include "missing_ioprio.h"
#include "mountpoint-util.h"
#include "nulstr-util.h"
-#include "parse-socket-bind-item.h"
+#include "parse-helpers.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c
index 59ddb9c487..716febbefa 100644
--- a/src/core/locale-setup.c
+++ b/src/core/locale-setup.c
@@ -16,7 +16,6 @@
int locale_setup(char ***environment) {
_cleanup_(locale_variables_freep) char *variables[_VARIABLE_LC_MAX] = {};
_cleanup_strv_free_ char **add = NULL;
- LocaleVariable i;
int r;
r = proc_cmdline_get_key_many(PROC_CMDLINE_STRIP_RD_PREFIX,
@@ -58,7 +57,7 @@ int locale_setup(char ***environment) {
log_warning_errno(r, "Failed to read /etc/locale.conf: %m");
}
- for (i = 0; i < _VARIABLE_LC_MAX; i++) {
+ for (LocaleVariable i = 0; i < _VARIABLE_LC_MAX; i++) {
char *s;
if (!variables[i])
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index db6cedfb16..2ad175c248 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -23,8 +23,7 @@
#include "main-func.h"
#include "mkdir.h"
#include "parse-argument.h"
-#include "parse-util.h"
-#include "path-util.h"
+#include "parse-helpers.h"
#include "pretty-print.h"
#include "process-util.h"
#include "rlimit-util.h"
diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c
index ac626495bc..03ac92daaf 100644
--- a/src/network/netdev/macsec.c
+++ b/src/network/netdev/macsec.c
@@ -14,7 +14,7 @@
#include "memory-util.h"
#include "netlink-util.h"
#include "networkd-manager.h"
-#include "path-util.h"
+#include "parse-helpers.h"
#include "socket-util.h"
#include "string-table.h"
#include "string-util.h"
diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c
index 32525e6200..fc2c6288ae 100644
--- a/src/network/netdev/wireguard.c
+++ b/src/network/netdev/wireguard.c
@@ -23,8 +23,8 @@
#include "networkd-route-util.h"
#include "networkd-route.h"
#include "networkd-util.h"
+#include "parse-helpers.h"
#include "parse-util.h"
-#include "path-util.h"
#include "random-util.h"
#include "resolve-private.h"
#include "string-util.h"
diff --git a/src/network/networkd-wiphy.h b/src/network/networkd-wiphy.h
index 072a7e5fdd..b40354704b 100644
--- a/src/network/networkd-wiphy.h
+++ b/src/network/networkd-wiphy.h
@@ -1,4 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
#include <inttypes.h>
diff --git a/src/nspawn/meson.build b/src/nspawn/meson.build
index a42e16dd99..f6cca7099b 100644
--- a/src/nspawn/meson.build
+++ b/src/nspawn/meson.build
@@ -28,6 +28,8 @@ libnspawn_core_sources = files(
'nspawn-setuid.h',
'nspawn-stub-pid1.c',
'nspawn-stub-pid1.h',
+ 'nspawn-util.c',
+ 'nspawn-util.h',
'nspawn.h',
)
@@ -58,6 +60,11 @@ tests += [
libshared],
[libseccomp]],
+ [files('test-nspawn-util.c'),
+ [libnspawn_core,
+ libshared],
+ [libseccomp]],
+
[files('test-patch-uid.c'),
[libnspawn_core,
libshared],
diff --git a/src/nspawn/nspawn-util.c b/src/nspawn/nspawn-util.c
new file mode 100644
index 0000000000..402554fa38
--- /dev/null
+++ b/src/nspawn/nspawn-util.c
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "alloc-util.h"
+#include "glob-util.h"
+#include "log.h"
+#include "nspawn-util.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "string-util.h"
+
+int systemd_installation_has_version(const char *root, const char *minimal_version) {
+ int r;
+
+ /* Try to guess if systemd installation is later than the specified version. This
+ * is hacky and likely to yield false negatives, particularly if the installation
+ * is non-standard. False positives should be relatively rare.
+ */
+
+ FOREACH_STRING(pattern,
+ /* /lib works for systems without usr-merge, and for systems with a sane
+ * usr-merge, where /lib is a symlink to /usr/lib. /usr/lib is necessary
+ * for Gentoo which does a merge without making /lib a symlink.
+ */
+ "/lib/systemd/libsystemd-shared-*.so",
+ "/lib64/systemd/libsystemd-shared-*.so",
+ "/usr/lib/systemd/libsystemd-shared-*.so",
+ "/usr/lib64/systemd/libsystemd-shared-*.so") {
+
+ _cleanup_strv_free_ char **names = NULL;
+ _cleanup_free_ char *path = NULL;
+ char *c;
+
+ path = path_join(root, pattern);
+ if (!path)
+ return -ENOMEM;
+
+ r = glob_extend(&names, path, 0);
+ if (r == -ENOENT)
+ continue;
+ if (r < 0)
+ return r;
+
+ assert_se(c = endswith(path, "*.so"));
+ *c = '\0'; /* truncate the glob part */
+
+ STRV_FOREACH(name, names) {
+ /* This is most likely to run only once, hence let's not optimize anything. */
+ char *t, *t2;
+
+ t = startswith(*name, path);
+ if (!t)
+ continue;
+
+ t2 = endswith(t, ".so");
+ if (!t2)
+ continue;
+ *t2 = '\0';
+
+ r = strverscmp_improved(t, minimal_version);
+ log_debug("Found libsystemd shared at \"%s.so\", version %s (%s).",
+ *name, t,
+ r >= 0 ? "OK" : "too old");
+ if (r >= 0)
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/src/nspawn/nspawn-util.h b/src/nspawn/nspawn-util.h
new file mode 100644
index 0000000000..e83cd564da
--- /dev/null
+++ b/src/nspawn/nspawn-util.h
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+int systemd_installation_has_version(const char *root, const char *minimal_version);
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index aa7367c5c9..a5b8265303 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -78,13 +78,13 @@
#include "nspawn-settings.h"
#include "nspawn-setuid.h"
#include "nspawn-stub-pid1.h"
+#include "nspawn-util.h"
#include "nspawn.h"
#include "nulstr-util.h"
#include "os-util.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
-#include "path-util.h"
#include "pretty-print.h"
#include "process-util.h"
#include "ptyfwd.h"
@@ -509,7 +509,7 @@ static int detect_unified_cgroup_hierarchy_from_image(const char *directory) {
if (r > 0) {
/* Unified cgroup hierarchy support was added in 230. Unfortunately the detection
* routine only detects 231, so we'll have a false negative here for 230. */
- r = systemd_installation_has_version(directory, 230);
+ r = systemd_installation_has_version(directory, "230");
if (r < 0)
return log_error_errno(r, "Failed to determine systemd version in container: %m");
if (r > 0)
@@ -518,7 +518,7 @@ static int detect_unified_cgroup_hierarchy_from_image(const char *directory) {
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
} else if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0) {
/* Mixed cgroup hierarchy support was added in 233 */
- r = systemd_installation_has_version(directory, 233);
+ r = systemd_installation_has_version(directory, "233");
if (r < 0)
return log_error_errno(r, "Failed to determine systemd version in container: %m");
if (r > 0)
diff --git a/src/nspawn/test-nspawn-util.c b/src/nspawn/test-nspawn-util.c
new file mode 100644
index 0000000000..08c8050dc5
--- /dev/null
+++ b/src/nspawn/test-nspawn-util.c
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "nspawn-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "tests.h"
+
+TEST(systemd_installation_has_version) {
+ int r;
+
+ FOREACH_STRING(version, "0", "231", STRINGIFY(PROJECT_VERSION), "999") {
+ r = systemd_installation_has_version(saved_argv[1], version);
+ assert_se(r >= 0);
+ log_info("%s has systemd >= %s: %s",
+ saved_argv[1] ?: "Current installation", version, yes_no(r));
+ }
+}
+
+/* This program can be called with a path to an installation root.
+ * For example: build/test-nspawn-util /var/lib/machines/rawhide
+ */
+DEFINE_TEST_MAIN(LOG_DEBUG);
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 118ab6c7d0..b6ac17c75e 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -46,8 +46,7 @@
#include "mount-util.h"
#include "mountpoint-util.h"
#include "parse-argument.h"
-#include "parse-util.h"
-#include "path-util.h"
+#include "parse-helpers.h"
#include "pretty-print.h"
#include "proc-cmdline.h"
#include "process-util.h"
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index 95ef3230b4..4f02c2c373 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -29,7 +29,7 @@
#include "mountpoint-util.h"
#include "nsflags.h"
#include "numa-util.h"
-#include "parse-socket-bind-item.h"
+#include "parse-helpers.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index aeea0a02d5..6c105e7fd2 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -24,6 +24,7 @@
#include "macro.h"
#include "missing_network.h"
#include "nulstr-util.h"
+#include "parse-helpers.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
diff --git a/src/shared/meson.build b/src/shared/meson.build
index 4333c9a0a9..1d4e4a07c0 100644
--- a/src/shared/meson.build
+++ b/src/shared/meson.build
@@ -245,8 +245,8 @@ shared_sources = files(
'pager.h',
'parse-argument.c',
'parse-argument.h',
- 'parse-socket-bind-item.c',
- 'parse-socket-bind-item.h',
+ 'parse-helpers.c',
+ 'parse-helpers.h',
'pcre2-dlopen.c',
'pcre2-dlopen.h',
'pe-header.h',
diff --git a/src/shared/parse-socket-bind-item.c b/src/shared/parse-helpers.c
index 3c92467632..a9bb58715e 100644
--- a/src/shared/parse-socket-bind-item.c
+++ b/src/shared/parse-helpers.c
@@ -3,8 +3,57 @@
#include "af-list.h"
#include "extract-word.h"
#include "ip-protocol-list.h"
-#include "parse-socket-bind-item.h"
+#include "log.h"
+#include "parse-helpers.h"
#include "parse-util.h"
+#include "path-util.h"
+#include "utf8.h"
+
+int path_simplify_and_warn(
+ char *path,
+ unsigned flag,
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *lvalue) {
+
+ bool fatal = flag & PATH_CHECK_FATAL;
+
+ assert(!FLAGS_SET(flag, PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE));
+
+ if (!utf8_is_valid(path))
+ return log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, path);
+
+ if (flag & (PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE)) {
+ bool absolute;
+
+ absolute = path_is_absolute(path);
+
+ if (!absolute && (flag & PATH_CHECK_ABSOLUTE))
+ return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
+ "%s= path is not absolute%s: %s",
+ lvalue, fatal ? "" : ", ignoring", path);
+
+ if (absolute && (flag & PATH_CHECK_RELATIVE))
+ return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
+ "%s= path is absolute%s: %s",
+ lvalue, fatal ? "" : ", ignoring", path);
+ }
+
+ path_simplify(path);
+
+ if (!path_is_valid(path))
+ return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
+ "%s= path has invalid length (%zu bytes)%s.",
+ lvalue, strlen(path), fatal ? "" : ", ignoring");
+
+ if (!path_is_normalized(path))
+ return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
+ "%s= path is not normalized%s: %s",
+ lvalue, fatal ? "" : ", ignoring", path);
+
+ return 0;
+}
static int parse_af_token(
const char *token,
diff --git a/src/shared/parse-helpers.h b/src/shared/parse-helpers.h
new file mode 100644
index 0000000000..49da2815fb
--- /dev/null
+++ b/src/shared/parse-helpers.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <stdint.h>
+
+enum {
+ PATH_CHECK_FATAL = 1 << 0, /* If not set, then error message is appended with 'ignoring'. */
+ PATH_CHECK_ABSOLUTE = 1 << 1,
+ PATH_CHECK_RELATIVE = 1 << 2,
+};
+
+int path_simplify_and_warn(
+ char *path,
+ unsigned flag,
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *lvalue);
+
+int parse_socket_bind_item(
+ const char *str,
+ int *address_family,
+ int *ip_protocol,
+ uint16_t *nr_ports,
+ uint16_t *port_min);
diff --git a/src/shared/parse-socket-bind-item.h b/src/shared/parse-socket-bind-item.h
deleted file mode 100644
index c8cff8d730..0000000000
--- a/src/shared/parse-socket-bind-item.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#pragma once
-
-#include <stdint.h>
-
-int parse_socket_bind_item(
- const char *str,
- int *address_family,
- int *ip_protocol,
- uint16_t *nr_ports,
- uint16_t *port_min);
diff --git a/src/sysupdate/sysupdate-transfer.c b/src/sysupdate/sysupdate-transfer.c
index a9fceed601..e5bbbadc16 100644
--- a/src/sysupdate/sysupdate-transfer.c
+++ b/src/sysupdate/sysupdate-transfer.c
@@ -12,8 +12,8 @@
#include "gpt.h"
#include "hexdecoct.h"
#include "install-file.h"
+#include "parse-helpers.h"
#include "parse-util.h"
-#include "path-util.h"
#include "process-util.h"
#include "rm-rf.h"
#include "specifier.h"
diff --git a/src/test/meson.build b/src/test/meson.build
index 11517c990b..6e7fe1a3bb 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -261,7 +261,7 @@ tests += [
[files('test-parse-argument.c')],
- [files('test-parse-socket-bind-item.c')],
+ [files('test-parse-helpers.c')],
[files('test-parse-util.c')],
diff --git a/src/test/test-parse-socket-bind-item.c b/src/test/test-parse-helpers.c
index 6bca27265c..052e2514f4 100644
--- a/src/test/test-parse-socket-bind-item.c
+++ b/src/test/test-parse-helpers.c
@@ -5,7 +5,7 @@
#include <stdio.h>
#include "macro.h"
-#include "parse-socket-bind-item.h"
+#include "parse-helpers.h"
#include "tests.h"
static void test_valid_item(
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index d40febef5f..4c56a7d520 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -960,21 +960,6 @@ TEST(hidden_or_backup_file) {
assert_se(!hidden_or_backup_file("test.dpkg-old.foo"));
}
-TEST(systemd_installation_has_version) {
- int r;
- const unsigned versions[] = {0, 231, PROJECT_VERSION, 999};
- unsigned i;
-
- log_info("/* %s */", __func__);
-
- for (i = 0; i < ELEMENTSOF(versions); i++) {
- r = systemd_installation_has_version(saved_argv[1], versions[i]);
- assert_se(r >= 0);
- log_info("%s has systemd >= %u: %s",
- saved_argv[1] ?: "Current installation", versions[i], yes_no(r));
- }
-}
-
TEST(skip_dev_prefix) {
assert_se(streq(skip_dev_prefix("/"), "/"));
assert_se(streq(skip_dev_prefix("/dev"), ""));