]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-util: introduce filename_or_absolute_path_is_valid() helper
authorMike Yuan <me@yhndnzj.com>
Mon, 5 May 2025 18:12:05 +0000 (20:12 +0200)
committerMike Yuan <me@yhndnzj.com>
Wed, 7 May 2025 16:32:19 +0000 (18:32 +0200)
src/basic/path-util.h
src/core/dbus-execute.c
src/core/load-fragment.c

index 647a884e39844f6ae19a2d99f09646ff05a10e10..671c1363c41acee7044aa572d11b6526cfc2975e 100644 (file)
@@ -145,6 +145,12 @@ static inline bool path_is_safe(const char *p) {
         return path_is_valid_full(p, /* accept_dot_dot= */ false);
 }
 bool path_is_normalized(const char *p) _pure_;
+static inline bool filename_or_absolute_path_is_valid(const char *p) {
+        if (path_is_absolute(p))
+                return path_is_valid(p);
+
+        return filename_is_valid(p);
+}
 
 int file_in_same_dir(const char *path, const char *filename, char **ret);
 
index 34511181bfe48351e5238b806ca9fd8e752395d8..560594d8a158835726c007f6377e6b416eacecc5 100644 (file)
@@ -1512,7 +1512,7 @@ int bus_set_transient_exec_command(
                 if (r < 0)
                         return r;
 
-                if (!path_is_absolute(path) && !filename_is_valid(path))
+                if (!filename_or_absolute_path_is_valid(path))
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
                                                  "\"%s\" is neither a valid executable name nor an absolute path",
                                                  path);
index e718dbc76b935c944f668a0ccf1ce668ada8e24c..ca95f334079114d85f71cd90e4a80711eace54ba 100644 (file)
@@ -974,7 +974,7 @@ int config_parse_exec(
                         return ignore ? 0 : -ENOEXEC;
                 }
 
-                if (!(path_is_absolute(path) ? path_is_valid(path) : filename_is_valid(path))) {
+                if (!filename_or_absolute_path_is_valid(path)) {
                         log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0,
                                    "Neither a valid executable name nor an absolute path%s: %s",
                                    ignore ? ", ignoring" : "", path);