1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 /* When we include libgen.h because we need dirname() we immediately
10 * undefine basename() since libgen.h defines it as a macro to the
11 * POSIX version which is really broken. We prefer GNU basename(). */
15 #include "alloc-util.h"
16 #include "chase-symlinks.h"
17 #include "extract-word.h"
20 #include "glob-util.h"
23 #include "nulstr-util.h"
24 #include "parse-util.h"
25 #include "path-util.h"
26 #include "stat-util.h"
27 #include "string-util.h"
29 #include "time-util.h"
32 int path_split_and_make_absolute(const char *p
, char ***ret
) {
39 l
= strv_split(p
, ":");
43 r
= path_strv_make_absolute_cwd(l
);
53 char *path_make_absolute(const char *p
, const char *prefix
) {
56 /* Makes every item in the list an absolute path by prepending
57 * the prefix, if specified and necessary */
59 if (path_is_absolute(p
) || isempty(prefix
))
62 return path_join(prefix
, p
);
65 int safe_getcwd(char **ret
) {
68 cwd
= get_current_dir_name();
70 return negative_errno();
72 /* Let's make sure the directory is really absolute, to protect us from the logic behind
83 int path_make_absolute_cwd(const char *p
, char **ret
) {
90 /* Similar to path_make_absolute(), but prefixes with the
91 * current working directory. */
93 if (path_is_absolute(p
))
96 _cleanup_free_
char *cwd
= NULL
;
98 r
= safe_getcwd(&cwd
);
102 c
= path_join(cwd
, p
);
111 int path_make_relative(const char *from
, const char *to
, char **ret
) {
112 _cleanup_free_
char *result
= NULL
;
122 /* Strips the common part, and adds ".." elements as necessary. */
124 if (!path_is_absolute(from
) || !path_is_absolute(to
))
128 r
= path_find_first_component(&from
, true, &f
);
132 k
= path_find_first_component(&to
, true, &t
);
139 /* from and to are equivalent. */
140 result
= strdup(".");
144 /* 'to' is inside of 'from'. */
149 path_simplify(result
);
151 if (!path_is_valid(result
))
155 *ret
= TAKE_PTR(result
);
159 if (r
!= k
|| !strneq(f
, t
, r
))
163 /* If we're here, then "from_dir" has one or more elements that need to
164 * be replaced with "..". */
166 for (n_parents
= 1;; n_parents
++) {
167 /* If this includes ".." we can't do a simple series of "..". */
168 r
= path_find_first_component(&from
, false, &f
);
175 if (isempty(t
) && n_parents
* 3 > PATH_MAX
)
176 /* PATH_MAX is counted *with* the trailing NUL byte */
179 result
= new(char, n_parents
* 3 + !isempty(t
) + strlen_ptr(t
));
183 for (p
= result
; n_parents
> 0; n_parents
--)
184 p
= mempcpy(p
, "../", 3);
187 /* Remove trailing slash and terminate string. */
189 *ret
= TAKE_PTR(result
);
195 path_simplify(result
);
197 if (!path_is_valid(result
))
200 *ret
= TAKE_PTR(result
);
204 char* path_startswith_strv(const char *p
, char **set
) {
207 STRV_FOREACH(s
, set
) {
208 t
= path_startswith(p
, *s
);
216 int path_strv_make_absolute_cwd(char **l
) {
220 /* Goes through every item in the string list and makes it
221 * absolute. This works in place and won't rollback any
222 * changes on failure. */
227 r
= path_make_absolute_cwd(*s
, &t
);
232 free_and_replace(*s
, t
);
238 char **path_strv_resolve(char **l
, const char *root
) {
247 /* Goes through every item in the string list and canonicalize
248 * the path. This works in place and won't rollback any
249 * changes on failure. */
252 _cleanup_free_
char *orig
= NULL
;
255 if (!path_is_absolute(*s
)) {
262 t
= path_join(root
, orig
);
270 r
= chase_symlinks(t
, root
, 0, &u
, NULL
);
288 x
= path_startswith(u
, root
);
290 /* restore the slash if it was lost */
291 if (!startswith(x
, "/"))
302 /* canonicalized path goes outside of
303 * prefix, keep the original path instead */
304 free_and_replace(u
, orig
);
320 char **path_strv_resolve_uniq(char **l
, const char *root
) {
325 if (!path_strv_resolve(l
, root
))
331 char *path_simplify(char *path
) {
332 bool add_slash
= false;
338 /* Removes redundant inner and trailing slashes. Also removes unnecessary dots.
339 * Modifies the passed string in-place.
341 * ///foo//./bar/. becomes /foo/bar
342 * .//./foo//./bar/. becomes foo/bar
348 if (path_is_absolute(path
))
351 for (const char *p
= f
;;) {
354 r
= path_find_first_component(&p
, true, &e
);
362 /* if path is invalid, then refuse to simplify remaining part. */
363 memmove(f
, p
, strlen(p
) + 1);
373 /* Special rule, if we stripped everything, we need a "." for the current directory. */
381 int path_simplify_and_warn(
385 const char *filename
,
387 const char *lvalue
) {
389 bool fatal
= flag
& PATH_CHECK_FATAL
;
391 assert(!FLAGS_SET(flag
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_RELATIVE
));
393 if (!utf8_is_valid(path
))
394 return log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, path
);
396 if (flag
& (PATH_CHECK_ABSOLUTE
| PATH_CHECK_RELATIVE
)) {
399 absolute
= path_is_absolute(path
);
401 if (!absolute
&& (flag
& PATH_CHECK_ABSOLUTE
))
402 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
403 "%s= path is not absolute%s: %s",
404 lvalue
, fatal
? "" : ", ignoring", path
);
406 if (absolute
&& (flag
& PATH_CHECK_RELATIVE
))
407 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
408 "%s= path is absolute%s: %s",
409 lvalue
, fatal
? "" : ", ignoring", path
);
414 if (!path_is_valid(path
))
415 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
416 "%s= path has invalid length (%zu bytes)%s.",
417 lvalue
, strlen(path
), fatal
? "" : ", ignoring");
419 if (!path_is_normalized(path
))
420 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
421 "%s= path is not normalized%s: %s",
422 lvalue
, fatal
? "" : ", ignoring", path
);
427 char *path_startswith_full(const char *path
, const char *prefix
, bool accept_dot_dot
) {
431 /* Returns a pointer to the start of the first component after the parts matched by
433 * - both paths are absolute or both paths are relative,
435 * - each component in prefix in turn matches a component in path at the same position.
436 * An empty string will be returned when the prefix and path are equivalent.
438 * Returns NULL otherwise.
441 if ((path
[0] == '/') != (prefix
[0] == '/'))
448 r
= path_find_first_component(&path
, accept_dot_dot
, &p
);
452 k
= path_find_first_component(&prefix
, accept_dot_dot
, &q
);
457 return (char*) (p
?: path
);
462 if (!strneq(p
, q
, r
))
467 int path_compare(const char *a
, const char *b
) {
470 /* Order NULL before non-NULL */
475 /* A relative path and an absolute path must not compare as equal.
476 * Which one is sorted before the other does not really matter.
477 * Here a relative path is ordered before an absolute path. */
478 r
= CMP(path_is_absolute(a
), path_is_absolute(b
));
486 j
= path_find_first_component(&a
, true, &aa
);
487 k
= path_find_first_component(&b
, true, &bb
);
489 if (j
< 0 || k
< 0) {
490 /* When one of paths is invalid, order invalid path after valid one. */
491 r
= CMP(j
< 0, k
< 0);
495 /* fallback to use strcmp() if both paths are invalid. */
499 /* Order prefixes first: "/foo" before "/foo/bar" */
508 /* Alphabetical sort: "/foo/aaa" before "/foo/b" */
509 r
= memcmp(aa
, bb
, MIN(j
, k
));
513 /* Sort "/foo/a" before "/foo/aaa" */
520 bool path_equal_or_files_same(const char *a
, const char *b
, int flags
) {
521 return path_equal(a
, b
) || files_same(a
, b
, flags
) > 0;
524 bool path_equal_filename(const char *a
, const char *b
) {
525 _cleanup_free_
char *a_basename
= NULL
, *b_basename
= NULL
;
531 r
= path_extract_filename(a
, &a_basename
);
533 log_debug_errno(r
, "Failed to parse basename of %s: %m", a
);
536 r
= path_extract_filename(b
, &b_basename
);
538 log_debug_errno(r
, "Failed to parse basename of %s: %m", b
);
542 return path_equal(a_basename
, b_basename
);
545 char* path_extend_internal(char **x
, ...) {
552 /* Joins all listed strings until the sentinel and places a "/" between them unless the strings end/begin
553 * already with one so that it is unnecessary. Note that slashes which are already duplicate won't be
554 * removed. The string returned is hence always equal to or longer than the sum of the lengths of each
557 * The first argument may be an already allocated string that is extended via realloc() if
558 * non-NULL. path_extend() and path_join() are macro wrappers around this function, making use of the
559 * first parameter to distinguish the two operations.
561 * Note: any listed empty string is simply skipped. This can be useful for concatenating strings of which some
566 * path_join("foo", "bar") → "foo/bar"
567 * path_join("foo/", "bar") → "foo/bar"
568 * path_join("", "foo", "", "bar", "") → "foo/bar" */
570 sz
= old_sz
= x
? strlen_ptr(*x
) : 0;
572 while ((p
= va_arg(ap
, char*)) != POINTER_MAX
) {
579 if (sz
> SIZE_MAX
- add
) { /* overflow check */
588 nx
= realloc(x
? *x
: NULL
, GREEDY_ALLOC_ROUND_UP(sz
+1));
595 slash
= nx
[old_sz
-1] == '/';
598 slash
= true; /* no need to generate a slash anymore */
604 while ((p
= va_arg(ap
, char*)) != POINTER_MAX
) {
608 if (!slash
&& p
[0] != '/')
612 slash
= endswith(p
, "/");
619 static int check_x_access(const char *path
, int *ret_fd
) {
620 _cleanup_close_
int fd
= -1;
623 /* We need to use O_PATH because there may be executables for which we have only exec
624 * permissions, but not read (usually suid executables). */
625 fd
= open(path
, O_PATH
|O_CLOEXEC
);
629 r
= fd_verify_regular(fd
);
633 r
= access_fd(fd
, X_OK
);
635 /* /proc is not mounted. Fallback to access(). */
636 if (access(path
, X_OK
) < 0)
642 *ret_fd
= TAKE_FD(fd
);
647 static int find_executable_impl(const char *name
, const char *root
, char **ret_filename
, int *ret_fd
) {
648 _cleanup_close_
int fd
= -1;
649 _cleanup_free_
char *path_name
= NULL
;
654 /* Function chase_symlinks() is invoked only when root is not NULL, as using it regardless of
655 * root value would alter the behavior of existing callers for example: /bin/sleep would become
656 * /usr/bin/sleep when find_executables is called. Hence, this function should be invoked when
657 * needed to avoid unforeseen regression or other complicated changes. */
659 r
= chase_symlinks(name
,
663 /* ret_fd= */ NULL
); /* prefix root to name in case full paths are not specified */
670 r
= check_x_access(name
, ret_fd
? &fd
: NULL
);
675 r
= path_make_absolute_cwd(name
, ret_filename
);
681 *ret_fd
= TAKE_FD(fd
);
686 int find_executable_full(const char *name
, const char *root
, char **exec_search_path
, bool use_path_envvar
, char **ret_filename
, int *ret_fd
) {
687 int last_error
= -ENOENT
, r
= 0;
688 const char *p
= NULL
;
693 return find_executable_impl(name
, root
, ret_filename
, ret_fd
);
696 /* Plain getenv, not secure_getenv, because we want to actually allow the user to pick the
702 if (exec_search_path
) {
705 STRV_FOREACH(element
, exec_search_path
) {
706 _cleanup_free_
char *full_path
= NULL
;
707 if (!path_is_absolute(*element
))
709 full_path
= path_join(*element
, name
);
713 r
= find_executable_impl(full_path
, root
, ret_filename
, ret_fd
);
724 /* Resolve a single-component name to a full path */
726 _cleanup_free_
char *element
= NULL
;
728 r
= extract_first_word(&p
, &element
, ":", EXTRACT_RELAX
|EXTRACT_DONT_COALESCE_SEPARATORS
);
734 if (!path_is_absolute(element
))
737 if (!path_extend(&element
, name
))
740 r
= find_executable_impl(element
, root
, ret_filename
, ret_fd
);
742 /* PATH entries which we don't have access to are ignored, as per tradition. */
755 bool paths_check_timestamp(const char* const* paths
, usec_t
*timestamp
, bool update
) {
756 bool changed
= false, originally_unset
;
757 const char* const* i
;
764 originally_unset
= *timestamp
== 0;
766 STRV_FOREACH(i
, paths
) {
770 if (stat(*i
, &stats
) < 0)
773 u
= timespec_load(&stats
.st_mtim
);
779 log_debug(originally_unset
? "Loaded timestamp for '%s'." : "Timestamp of '%s' changed.", *i
);
781 /* update timestamp */
792 static int executable_is_good(const char *executable
) {
793 _cleanup_free_
char *p
= NULL
, *d
= NULL
;
796 r
= find_executable(executable
, &p
);
802 /* An fsck that is linked to /bin/true is a non-existent fsck */
804 r
= readlink_malloc(p
, &d
);
805 if (r
== -EINVAL
) /* not a symlink */
810 return !PATH_IN_SET(d
, "true"
816 int fsck_exists(const char *fstype
) {
821 if (streq(fstype
, "auto"))
824 checker
= strjoina("fsck.", fstype
);
825 return executable_is_good(checker
);
828 char* dirname_malloc(const char *path
) {
829 char *d
, *dir
, *dir2
;
849 static const char *skip_slash_or_dot(const char *p
) {
850 for (; !isempty(p
); p
++) {
853 if (startswith(p
, "./")) {
862 int path_find_first_component(const char **p
, bool accept_dot_dot
, const char **ret
) {
863 const char *q
, *first
, *end_first
, *next
;
868 /* When a path is input, then returns the pointer to the first component and its length, and
869 * move the input pointer to the next component or nul. This skips both over any '/'
870 * immediately *before* and *after* the first component before returning.
873 * Input: p: "//.//aaa///bbbbb/cc"
874 * Output: p: "bbbbb///cc"
875 * ret: "aaa///bbbbb/cc"
876 * return value: 3 (== strlen("aaa"))
879 * Output: p: (pointer to NUL)
881 * return value: 3 (== strlen("aaa"))
883 * Input: p: "/", ".", ""
884 * Output: p: (pointer to NUL)
893 * Input: p: "(too long component)"
894 * Output: return value: -EINVAL
896 * (when accept_dot_dot is false)
897 * Input: p: "//..//aaa///bbbbb/cc"
898 * Output: return value: -EINVAL
903 first
= skip_slash_or_dot(q
);
904 if (isempty(first
)) {
910 if (streq(first
, ".")) {
917 end_first
= strchrnul(first
, '/');
918 len
= end_first
- first
;
922 if (!accept_dot_dot
&& len
== 2 && first
[0] == '.' && first
[1] == '.')
925 next
= skip_slash_or_dot(end_first
);
927 *p
= next
+ streq(next
, ".");
933 static const char *skip_slash_or_dot_backward(const char *path
, const char *q
) {
936 for (; q
>= path
; q
--) {
939 if (q
> path
&& strneq(q
- 1, "/.", 2))
946 int path_find_last_component(const char *path
, bool accept_dot_dot
, const char **next
, const char **ret
) {
947 const char *q
, *last_end
, *last_begin
;
950 /* Similar to path_find_first_component(), but search components from the end.
953 * Input: path: "//.//aaa///bbbbb/cc//././"
955 * Output: next: "/cc//././"
957 * return value: 2 (== strlen("cc"))
959 * Input: path: "//.//aaa///bbbbb/cc//././"
961 * Output: next: "///bbbbb/cc//././"
962 * ret: "bbbbb/cc//././"
963 * return value: 5 (== strlen("bbbbb"))
965 * Input: path: "/", ".", "", or NULL
966 * Output: next: equivalent to path
970 * Input: path: "(too long component)"
971 * Output: return value: -EINVAL
973 * (when accept_dot_dot is false)
974 * Input: path: "//..//aaa///bbbbb/cc/..//"
975 * Output: return value: -EINVAL
987 if (*next
< path
|| *next
> path
+ strlen(path
))
994 if (!IN_SET(**next
, '\0', '/'))
998 q
= path
+ strlen(path
) - 1;
1000 q
= skip_slash_or_dot_backward(path
, q
);
1001 if ((q
< path
) || /* the root directory */
1002 (q
== path
&& *q
== '.')) { /* path is "." or "./" */
1012 while (q
>= path
&& *q
!= '/')
1016 len
= last_end
- last_begin
;
1020 if (!accept_dot_dot
&& len
== 2 && strneq(last_begin
, "..", 2))
1024 q
= skip_slash_or_dot_backward(path
, q
);
1036 const char *last_path_component(const char *path
) {
1038 /* Finds the last component of the path, preserving the optional trailing slash that signifies a directory.
1051 * Also, the empty string is mapped to itself.
1053 * This is different than basename(), which returns "" when a trailing slash is present.
1055 * This always succeeds (except if you pass NULL in which case it returns NULL, too).
1063 l
= k
= strlen(path
);
1064 if (l
== 0) /* special case — an empty string */
1067 while (k
> 0 && path
[k
-1] == '/')
1070 if (k
== 0) /* the root directory */
1071 return path
+ l
- 1;
1073 while (k
> 0 && path
[k
-1] != '/')
1079 int path_extract_filename(const char *path
, char **ret
) {
1080 _cleanup_free_
char *a
= NULL
;
1081 const char *c
, *next
= NULL
;
1084 /* Extracts the filename part (i.e. right-most component) from a path, i.e. string that passes
1085 * filename_is_valid(). A wrapper around last_path_component(), but eats up trailing
1088 * -EINVAL → if the path is not valid
1089 * -EADDRNOTAVAIL → if only a directory was specified, but no filename, i.e. the root dir
1090 * itself or "." is specified
1091 * -ENOMEM → no memory
1093 * Returns >= 0 on success. If the input path has a trailing slash, returns O_DIRECTORY, to
1094 * indicate the referenced file must be a directory.
1096 * This function guarantees to return a fully valid filename, i.e. one that passes
1097 * filename_is_valid() – this means "." and ".." are not accepted. */
1099 if (!path_is_valid(path
))
1102 r
= path_find_last_component(path
, false, &next
, &c
);
1105 if (r
== 0) /* root directory */
1106 return -EADDRNOTAVAIL
;
1113 return strlen(c
) > (size_t)r
? O_DIRECTORY
: 0;
1116 int path_extract_directory(const char *path
, char **ret
) {
1117 _cleanup_free_
char *a
= NULL
;
1118 const char *c
, *next
= NULL
;
1121 /* The inverse of path_extract_filename(), i.e. returns the directory path prefix. Returns:
1123 * -EINVAL → if the path is not valid
1124 * -EDESTADDRREQ → if no directory was specified in the passed in path, i.e. only a filename was passed
1125 * -EADDRNOTAVAIL → if the passed in parameter had no filename but did have a directory, i.e.
1126 * the root dir itself or "." was specified
1127 * -ENOMEM → no memory (surprise!)
1129 * This function guarantees to return a fully valid path, i.e. one that passes path_is_valid().
1132 r
= path_find_last_component(path
, false, &next
, &c
);
1135 if (r
== 0) /* empty or root */
1136 return isempty(path
) ? -EINVAL
: -EADDRNOTAVAIL
;
1138 if (*path
!= '/') /* filename only */
1139 return -EDESTADDRREQ
;
1148 a
= strndup(path
, next
- path
);
1154 if (!path_is_valid(a
))
1161 bool filename_is_valid(const char *p
) {
1167 if (dot_or_dot_dot(p
))
1170 e
= strchrnul(p
, '/');
1174 if (e
- p
> NAME_MAX
) /* NAME_MAX is counted *without* the trailing NUL byte */
1180 bool path_is_valid_full(const char *p
, bool accept_dot_dot
) {
1184 for (const char *e
= p
;;) {
1187 r
= path_find_first_component(&e
, accept_dot_dot
, NULL
);
1191 if (e
- p
>= PATH_MAX
) /* Already reached the maximum length for a path? (PATH_MAX is counted
1192 * *with* the trailing NUL byte) */
1194 if (*e
== 0) /* End of string? Yay! */
1199 bool path_is_normalized(const char *p
) {
1200 if (!path_is_safe(p
))
1203 if (streq(p
, ".") || startswith(p
, "./") || endswith(p
, "/.") || strstr(p
, "/./"))
1206 if (strstr(p
, "//"))
1212 char *file_in_same_dir(const char *path
, const char *filename
) {
1219 /* This removes the last component of path and appends
1220 * filename, unless the latter is absolute anyway or the
1223 if (path_is_absolute(filename
))
1224 return strdup(filename
);
1226 e
= strrchr(path
, '/');
1228 return strdup(filename
);
1230 k
= strlen(filename
);
1231 ret
= new(char, (e
+ 1 - path
) + k
+ 1);
1235 memcpy(mempcpy(ret
, path
, e
+ 1 - path
), filename
, k
+ 1);
1239 bool hidden_or_backup_file(const char *filename
) {
1242 if (filename
[0] == '.' ||
1243 streq(filename
, "lost+found") ||
1244 streq(filename
, "aquota.user") ||
1245 streq(filename
, "aquota.group") ||
1246 endswith(filename
, "~"))
1249 const char *dot
= strrchr(filename
, '.');
1253 /* Please, let's not add more entries to the list below. If external projects think it's a good idea
1254 * to come up with always new suffixes and that everybody else should just adjust to that, then it
1255 * really should be on them. Hence, in future, let's not add any more entries. Instead, let's ask
1256 * those packages to instead adopt one of the generic suffixes/prefixes for hidden files or backups,
1257 * possibly augmented with an additional string. Specifically: there's now:
1259 * The generic suffixes "~" and ".bak" for backup files
1260 * The generic prefix "." for hidden files
1262 * Thus, if a new package manager "foopkg" wants its own set of ".foopkg-new", ".foopkg-old",
1263 * ".foopkg-dist" or so registered, let's refuse that and ask them to use ".foopkg.new",
1264 * ".foopkg.old" or ".foopkg~" instead.
1267 return STR_IN_SET(dot
+ 1,
1287 bool is_device_path(const char *path
) {
1289 /* Returns true for paths that likely refer to a device, either by path in sysfs or to something in
1292 return PATH_STARTSWITH_SET(path
, "/dev/", "/sys/");
1295 bool valid_device_node_path(const char *path
) {
1297 /* Some superficial checks whether the specified path is a valid device node path, all without
1298 * looking at the actual device node. */
1300 if (!PATH_STARTSWITH_SET(path
, "/dev/", "/run/systemd/inaccessible/"))
1303 if (endswith(path
, "/")) /* can't be a device node if it ends in a slash */
1306 return path_is_normalized(path
);
1309 bool valid_device_allow_pattern(const char *path
) {
1312 /* Like valid_device_node_path(), but also allows full-subsystem expressions like those accepted by
1313 * DeviceAllow= and DeviceDeny=. */
1315 if (STARTSWITH_SET(path
, "block-", "char-"))
1318 return valid_device_node_path(path
);
1321 int systemd_installation_has_version(const char *root
, unsigned minimal_version
) {
1322 const char *pattern
;
1325 /* Try to guess if systemd installation is later than the specified version. This
1326 * is hacky and likely to yield false negatives, particularly if the installation
1327 * is non-standard. False positives should be relatively rare.
1330 NULSTR_FOREACH(pattern
,
1331 /* /lib works for systems without usr-merge, and for systems with a sane
1332 * usr-merge, where /lib is a symlink to /usr/lib. /usr/lib is necessary
1333 * for Gentoo which does a merge without making /lib a symlink.
1335 "lib/systemd/libsystemd-shared-*.so\0"
1336 "lib64/systemd/libsystemd-shared-*.so\0"
1337 "usr/lib/systemd/libsystemd-shared-*.so\0"
1338 "usr/lib64/systemd/libsystemd-shared-*.so\0") {
1340 _cleanup_strv_free_
char **names
= NULL
;
1341 _cleanup_free_
char *path
= NULL
;
1344 path
= path_join(root
, pattern
);
1348 r
= glob_extend(&names
, path
, 0);
1354 assert_se(c
= endswith(path
, "*.so"));
1355 *c
= '\0'; /* truncate the glob part */
1357 STRV_FOREACH(name
, names
) {
1358 /* This is most likely to run only once, hence let's not optimize anything. */
1362 t
= startswith(*name
, path
);
1366 t2
= endswith(t
, ".so");
1370 t2
[0] = '\0'; /* truncate the suffix */
1372 r
= safe_atou(t
, &version
);
1374 log_debug_errno(r
, "Found libsystemd shared at \"%s.so\", but failed to parse version: %m", *name
);
1378 log_debug("Found libsystemd shared at \"%s.so\", version %u (%s).",
1380 version
>= minimal_version
? "OK" : "too old");
1381 if (version
>= minimal_version
)
1389 bool dot_or_dot_dot(const char *path
) {
1399 return path
[2] == 0;
1402 bool empty_or_root(const char *path
) {
1404 /* For operations relative to some root directory, returns true if the specified root directory is
1405 * redundant, i.e. either / or NULL or the empty string or any equivalent. */
1410 return path_equal(path
, "/");
1413 bool path_strv_contains(char **l
, const char *path
) {
1417 if (path_equal(*i
, path
))
1423 bool prefixed_path_strv_contains(char **l
, const char *path
) {
1426 STRV_FOREACH(i
, l
) {
1432 if (path_equal(j
, path
))