Commit Graph
132 Commits
Author SHA1 Message Date
Daan De Meyer f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Zbigniew Jędrzejewski-Szmek e63917abe1 core: allow split /usr/local/s?sbin with merged /usr/s?bin
Previously, we used either the fully split path or the fully merged path,
treating "split sbin" as a boolean condition. The idea was that conversion to
to merged bin would be a single event, so we don't need to care about the
details of the transition. But it turns out that some systems may be converted
in disparate steps. In https://bugzilla.redhat.com/show_bug.cgi?id=2400220,
there was a lengthy discussion about a coreos system where
/usr/local/{bin,sbin} were created as separate directories. Since /usr/local is
not part of the packaged system, it might remain split for a longer time. So
check /usr/local/s?bin separately and stop adding /usr/sbin to $PATH if only
/usr/local/s?bin is split. (I don't think it makes sense to handle the reverse
case, i.e. only /usr/s?bin being split, since that should be much rarer.)

Inspired by https://bugzilla.redhat.com/show_bug.cgi?id=2400220.
2025-10-14 18:30:06 +02:00
Yu Watanabe 8ce463639a path-util: move empty_or_root_to_null() from chase.c
And rename it to empty_or_root_harder_to_null(), as it also checks if
the input path effectively points to the root by calling path_is_root().
This also adds simple test cases for the function.
2025-06-30 03:45:29 +09:00
Mike Yuan 180341e732 basic,shared: mark eligible functions with _pure_/_const_
Following the recent witch hunt done to static inline functions
I figure we should at least give the compiler some more hint
on optimizations.
2025-05-26 20:26:58 +02:00
Daan De Meyer 0c15577abe basic + fundamental: Clean up includes
Split out of #37344.
2025-05-25 10:06:07 +02:00
Lennart Poettering ceed11e465 path-util: invert PATH_STARTSWITH_ACCEPT_DOT_DOT flag
As requested: https://github.com/systemd/systemd/pull/37572#pullrequestreview-2861928094
2025-05-23 06:51:45 +02:00
Lennart Poettering ee19edbb9f path-util: add flavour of path_startswith() that leaves a leading slash in place 2025-05-23 06:50:30 +02:00
Mike Yuan 398b3e4472 path-util: introduce filename_or_absolute_path_is_valid() helper 2025-05-07 18:32:19 +02:00
Daan De Meyer d9ccf6b349 path-util: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Daan De Meyer 1fbfbe81b5 tree-wide: Get rid of prefix_roota() in favor of path_join()
We deprecated prefix_roota() in favor of chase() and path_join().
Let's finish the removal by replacing the few remaining call sites
with path_join().
2025-05-06 17:40:33 +02:00
Mike Yuan 326d60a9d0 path-util: generalize open_and_check_executable() 2025-04-06 02:32:47 +02:00
Mike Yuan 51b271ead7 path-util: trivial cleanup for find_executable_full() 2024-07-23 18:48:15 +02:00
Zbigniew Jędrzejewski-Szmek bfd5a0687f various: move const ptr indicator to return value 2024-06-19 16:28:28 +02:00
Mike Yuan 63a0e57724 path-util: take char* const* for strv where appropriate 2024-05-09 17:02:19 +08:00
Luca Boccassi c3411932b1 Merge pull request #32389 from keszybz/bin-sbin-merge
Try PATH without sbin even if compiled with split-bin=true
2024-04-22 13:07:48 +02:00
Zbigniew Jędrzejewski-Szmek 0f36a4c897 Try path without sbin even if compiled with split-bin=true
I'm working on the transition to merged sbin in Fedora. While the transition is
happening (and probably for a while after), we need to compile systemd with
split-bin=true to support systems upgraded from previous versions. But when the
system has been upgraded and already has /usr/sbin that is a symlink, be nice
and give $PATH without sbin.

We check for both /usr/sbin and /usr/local/sbin. If either exists and is not a
symlink to ./bin, we retain previous behaviour. This means that if both are
converted, we get the same behaviour as split-bin=false, and otherwise we
get the same behaviour as before.

sd-path uses the same logic. This is not a hot path, so I got rid of the nulstr
macros that duplicated the logic.
2024-04-22 09:53:24 +02:00
Krzesimir Nowak 581d8a1470 path-util: Add a helper for checking paths
The difference with the already existing path_equal_or_inode_same function is
that the new one does not swallow errors.
2024-04-19 08:30:40 +02:00
Zbigniew Jędrzejewski-Szmek 1934242b72 Drop unnecessary path_equal_ptr() wrapper
path_equal already works with NULL pointers.
2024-03-23 13:21:06 +01: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 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
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Zbigniew Jędrzejewski-Szmek 660087dc9c tree-wide: add path_simplify_alloc() and use it
path_simplify_full()/path_simplify() are changed to allow a NULL path, for
which a NULL is returned. Generally, callers have already asserted before that
the argument is nonnull. This way path_simplify_full()/path_simplify() and
path_simplify_alloc() behave consistently.

In sd-device.c, logging in device_set_syspath() is intentionally dropped: other
branches don't log.

In mount-tool.c, logging in parse_argv() is changed to log the user-specified
value, not the simplified string. In an error message, we should show the
actual argument we got, not some transformed version.
2023-09-22 08:13:34 +02:00
Zbigniew Jędrzejewski-Szmek 00d811a548 basic/path-util: change 'char *func' to 'char* func'
Both styles were mixed in the file, but I find the latter much nicer,
because it's not the func that is the pointer, but the return type.
2023-09-18 14:09:34 +02:00
Daan De Meyer 4541d045b2 path-util: Add path_simplify_full()
Sometimes its useful to keep a trailing slash in the path so let's
add path_simplify_full() and a flag to do just that.
2023-08-17 13:23:36 +02:00
Luca Boccassi b0d3095fd6 Drop split-usr and unmerged-usr support
As previously announced, execute order 66:

https://lists.freedesktop.org/archives/systemd-devel/2022-September/048352.html

The meson options split-usr, rootlibdir and rootprefix become no-ops
that print a warning if they are set to anything other than the
default values. We can remove them in a future release.
2023-07-28 19:34:03 +01:00
Mike Yuan e3c9e09383 path-util: make path_equal_or_inode_same static inline
No functional change, just refactoring.
2023-07-11 18:01:49 +08:00
Lennart Poettering ec926463c0 path-util: split filename_is_valid() in two
Add a helper filename_part_is_valid() which does half of what
filename_is_valid() does: it checks for valid chars and length, but does
not filter out ".", ".." and "", as these are OK as parts of filenames,
just not alone.
2023-06-20 18:45:01 +02:00
Lennart Poettering 563e684689 stat-util: rename files_same() → inode_same()
Let's be more accurate about what this function does: it checks whether
the underlying reported inode is the same. Internally, this already uses
a better named stat_inode_same() call, hence let's similarly name the
wrapping function following the same logic.

Similar for files_same_at() and path_equal_or_same_files().

No code changes, just some renaming.
2023-05-19 17:42:41 +02:00
Yu Watanabe 60e761d8f3 chase: replace path_prefix_root_cwd() with chaseat_prefix_root()
The function path_prefix_root_cwd() was introduced for prefixing the
result from chaseat() with root, but
- it is named slightly generic,
- the logic is different from what chase() does.

This makes the name more explanative and specific for the result of the
chaseat(), and make the logic consistent with chase().

Fixes https://github.com/systemd/systemd/pull/27199#issuecomment-1511387731.

Follow-up for #27199.
2023-04-19 03:38:59 +09:00
Yu Watanabe 75cc8d7c42 path-util: introduce path_prefix_root_cwd() 2023-04-11 06:27:05 +09:00
Yu Watanabe 6808e00463 path-util: introduce path_compare_filename() 2023-04-08 05:08:51 +09:00
Lennart Poettering 162f6477c6 path-util: rework file_in_same_dir() on top of path_extract_directory()
Let's port one more over.

Note that this changes behaviour of file_in_same_dir() in some regards.
Specifically, a trailing slash of the input path will be treated
differently: previously we'd operate below that dir then, instead of the
parent. I think that makes little sense however, and I think the code
using this function doesn't expect that either.

Moroever, addresses some corner cases if the path is specified as "/" or
".", i.e. where e cannot extract a parent. These will now be treated as
error, which I think is much cleaner.
2023-01-24 18:13:27 +01:00
Ludwig Nussel 2e76ca79b3 bootctl: honor $KERNEL_INSTALL_CONF_ROOT
Honor $KERNEL_INSTALL_CONF_ROOT for reading config files, as
kernel-install does.
2023-01-10 15:17:07 +01:00
Daan De Meyer 8c39e28191 path-util: Drop path_make_relative_cwd()
Function is unused
2022-11-11 09:50:50 +01:00
Daan De Meyer 15b4b4ed06 path-util: Add path_make_relative_cwd() 2022-11-09 11:14:10 +01:00
Jonas Kümmerlin 1355672437 generator: skip fsck if fsck command is missing
This is useful for systems which don't have any fsck.

We already skip emitting the fsck dependency when the fsck.$fstype helper
is missing, but fstab-generator doesn't necessarily know the fstype when
handling the root= parameter.

Previously, systemd-fsck was started for these mounts and then exited
immediately because it couldn't find the fsck.$fstype helper.
2022-09-30 15:01:41 +01:00
Yu Watanabe d4f60bdc11 path-util: introduce path_make_relative_parent() 2022-09-03 05:01:51 +09:00
Lennart Poettering e08c10a424 path-util: drop the now unused dirname_malloc() 2022-08-23 15:10:15 +02:00
Yu Watanabe 3b703fe269 path-util: introduce path_glob_can_match() 2022-08-17 14:30:20 +09:00
Lennart Poettering 39e419a2b5 tree-wide: trivial tweaks 2022-07-11 15:11:58 +02:00
Lennart Poettering 70980a39b8 path-util: NULL strings are definitely not valid paths
Let's make this functions that check validity of paths a bit more
friendly towards one specific kind of invalid path: a NULL pointer.

This follows similar logic in path_is_valid(), path_is_normalized() and
so on.
2022-07-08 11:35:00 +02:00
Zbigniew Jędrzejewski-Szmek c3eaba2d3d Move path_simplify_and_warn() to new shared/parse-helpers.c
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.
2022-04-07 18:25:55 +02:00
Zbigniew Jędrzejewski-Szmek c9394f4f93 Move systemd_installation_has_version() to src/nspawn/
This function implements a heuristic that is only used by nspawn. It doesn't
belong in basic. I opted for a new file "nspawn-utils.c", because it seems
likely that we'll need some other new utilities like that in the future.

No functional change.
2022-04-07 18:17:20 +02:00
alexlzhu 8c35c10d20 core: Add ExecSearchPath parameter to specify the directory relative to which binaries executed by Exec*= should be found
Currently there does not exist a way to specify a path relative to which
all binaries executed by Exec should be found. The only way is to
specify the absolute path.

This change implements the functionality to specify a path relative to which
binaries executed by Exec*= can be found.

Closes #6308
2021-09-28 14:52:27 +01:00
Maanya Goenka 36f4af0568 path-util: teach find_executable_full how to look into the root directory
When the root parameter in find_executable_full is set, chase_symlinks prefixes this root
to every check of the path name to find the complete path of the execuatble in case the
path provided is not absolute. This is only done for the non NULL root because otherwise
the chase_symlinks function would alter the behavior of some of the callers which would
in turn alter the outputs in a way that is undesirable. The find_execuatble_full function is
invoked by the verify_executable function in analyze-verify.
2021-08-10 10:14:01 -07:00
Lennart Poettering 1a27c323dd path-util: make path_equal() an inline wrapper around path_compare()
The two are completely identical, only the return code is inverted.
let's hence make it easy for the compiler to make it the same function
call even in lowest optimization modes.
2021-06-18 13:46:43 +09:00
Yu Watanabe 4ff361cc86 tree-wide: always drop unnecessary dot in path 2021-05-28 13:44:38 +09:00
Yu Watanabe 0195046449 path-util: make path_extract_filename/directory() handle "." gracefully
This makes the functions handle "xx/" and "xx/." as equivalent.
Moreover, now path_extract_directory() returns normalized path, that is
no redundant "/" or "/./" are contained.
2021-05-28 13:44:38 +09:00
Yu Watanabe 484cd43cae path-util: introduce path_find_last_component() 2021-05-28 13:44:38 +09:00