]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Move path_simplify_and_warn() to new shared/parse-helpers.c
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Apr 2022 11:43:18 +0000 (13:43 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Apr 2022 16:25:55 +0000 (18:25 +0200)
This is a high-level function, and it belongs in libsystemd-shared. This way we
don't end up linking a separate copy into various binaries. It would even end
up in libsystemd, where it is not needed. (Maybe it'd be removed in some
optimization phase, but it's better to not rely on that.)

$ grep -l -r -a 'path is not absolute%s' build/
build/libnss_systemd.so.2
build/pam_systemd_home.so
build/test-dlopen
build/src/basic/libbasic.a.p/path-util.c.o
build/src/basic/libbasic.a
build/src/shared/libsystemd-shared-249.so
build/test-bus-error
build/libnss_mymachines.so.2
build/pam_systemd.so
build/libnss_resolve.so.2
build/libnss_myhostname.so.2
build/libsystemd.so.0.32.0
build/libudev.so.1.7.2

$ grep -l -r -a 'path is not absolute%s' build/
build/src/shared/libsystemd-shared-251.a.p/parse-helpers.c.o
build/src/shared/libsystemd-shared-251.a
build/src/shared/libsystemd-shared-251.so

No functional change.

12 files changed:
src/basic/path-util.c
src/basic/path-util.h
src/core/load-fragment.c
src/journal-remote/journal-upload.c
src/network/netdev/macsec.c
src/network/netdev/wireguard.c
src/partition/repart.c
src/shared/conf-parser.c
src/shared/meson.build
src/shared/parse-helpers.c [new file with mode: 0644]
src/shared/parse-helpers.h [new file with mode: 0644]
src/sysupdate/sysupdate-transfer.c

index 979c6f2c9dfd02f39bdc6cb107c5f6e37b0c0fbe..94527eff4caa48fb3f954cc09a60f920d6c115c5 100644 (file)
@@ -24,7 +24,6 @@
 #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;
@@ -373,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);
index 2f55b3abb160a32b390f1acf3d3167d8ec9889ef..553aa4fb58631db69e7740634267feb838b96832 100644 (file)
@@ -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));
 }
index 66e0c01c2324f22765d9bc3019d0edf471683407..b81db4617ba2b9cd0af5e80f7e9354a5aaf36465 100644 (file)
@@ -50,6 +50,7 @@
 #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"
index db6cedfb163f5034817da7959994f9a5da1a74dc..2ad175c2483b4858c74f1b2a47b3d7b1c0f5368c 100644 (file)
@@ -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"
index ac626495bc1f327f57c24310cbb0d1dfb570ff76..03ac92daaf17f2b0cd7286ea76de470ebc60fd10 100644 (file)
@@ -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"
index 32525e6200c7c9799b4319400663048dd5c4acbb..fc2c6288ae95b0d316cf5acd283cc3414ae90677 100644 (file)
@@ -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"
index 118ab6c7d08bf21c898283529c6d694029d4e9c1..b6ac17c75e52b20e5a53297cd28a2367ca37329b 100644 (file)
@@ -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"
index aeea0a02d52d62407751330479117cee912c7553..6c105e7fd27fd21b096ff178259e317e55f6879a 100644 (file)
@@ -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"
index 4333c9a0a90b5f6f0c662e9e5079cff5063a5b52..8f1f3b40a9b6dd4cfdfe1339a2775b87d1d3bbd0 100644 (file)
@@ -245,6 +245,8 @@ shared_sources = files(
         'pager.h',
         'parse-argument.c',
         'parse-argument.h',
+        'parse-helpers.c',
+        'parse-helpers.h',
         'parse-socket-bind-item.c',
         'parse-socket-bind-item.h',
         'pcre2-dlopen.c',
diff --git a/src/shared/parse-helpers.c b/src/shared/parse-helpers.c
new file mode 100644 (file)
index 0000000..5ebe366
--- /dev/null
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "log.h"
+#include "parse-helpers.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;
+}
diff --git a/src/shared/parse-helpers.h b/src/shared/parse-helpers.h
new file mode 100644 (file)
index 0000000..8b1d334
--- /dev/null
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+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);
index a9fceed601197ad486bac9c390dd6509b8a2f4ff..e5bbbadc162f68fd7b793d237b9c5c9cb018c7d1 100644 (file)
@@ -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"