summaryrefslogtreecommitdiff
path: root/src/basic/path-util.c
Commit message (Collapse)AuthorAgeFilesLines
* path-util: use _cleanup_David Tardon2023-04-271-5/+3
|
* chase: replace path_prefix_root_cwd() with chaseat_prefix_root()Yu Watanabe2023-04-191-28/+0
| | | | | | | | | | | | | | 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.
* path-util: introduce path_prefix_root_cwd()Yu Watanabe2023-04-111-0/+28
|
* path-util: make iterator for path_find_last_component() always finish with ↵Yu Watanabe2023-04-101-0/+8
| | | | the beginning of the buffer
* path-util: introduce path_compare_filename()Yu Watanabe2023-04-081-16/+24
|
* chase-symlinks: Rename chase_symlinks() to chase()Daan De Meyer2023-03-241-8/+5
| | | | | | | | | Chasing symlinks is a core function that's used in a lot of places so it deservers a less verbose names so let's rename it to chase() and chaseat(). We also slightly change the pattern used for the chaseat() helpers so we get chase_and_openat() and similar.
* basic: reword some commentsZbigniew Jędrzejewski-Szmek2023-02-011-6/+6
| | | | Without commas, the sentences can be hard to parse.
* path-util: rework file_in_same_dir() on top of path_extract_directory()Lennart Poettering2023-01-241-17/+21
| | | | | | | | | | | | | | 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.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-2/+2
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* path-util: Drop path_make_relative_cwd()Daan De Meyer2022-11-111-27/+0
| | | | Function is unused
* path-util: Add path_make_relative_cwd()Daan De Meyer2022-11-091-0/+27
|
* generator: skip fsck if fsck command is missingJonas Kümmerlin2022-09-301-1/+10
| | | | | | | | | | | 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.
* path-util: add examples for path_make_relative() and path_make_relative_parent()Yu Watanabe2022-09-191-1/+11
| | | | Addresses https://github.com/systemd/systemd/pull/24646#discussion_r973691797.
* tree-wide: use ASSERT_PTR moreDavid Tardon2022-09-131-3/+1
|
* path-util: introduce path_make_relative_parent()Yu Watanabe2022-09-031-0/+18
|
* path-util: return error if fnmatch() failsLennart Poettering2022-08-311-1/+4
|
* path-util: drop the now unused dirname_malloc()Lennart Poettering2022-08-231-27/+0
|
* path-util: introduce path_glob_can_match()Yu Watanabe2022-08-171-0/+62
|
* tree-wide: trivial tweaksLennart Poettering2022-07-111-2/+2
|
* Move path_simplify_and_warn() to new shared/parse-helpers.cZbigniew Jędrzejewski-Szmek2022-04-071-47/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Move systemd_installation_has_version() to src/nspawn/Zbigniew Jędrzejewski-Szmek2022-04-071-71/+0
| | | | | | | | 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.
* path-util: use STR_IN_SET() where appropriateLennart Poettering2022-04-011-3/+4
|
* process-util: refactor APIs for reading /proc/self/xyz symlinksLennart Poettering2022-04-011-5/+5
| | | | | | | | | | | | | The three functions for reading cwd, exe and root symlinks of processes already share a common core: get_process_link_contents(). Let's refactor that a bit, and move formatting of the /proc/self/ path into this helper function instead of doing that in the caller, thus sharing more code. While we are at it, make the return parameters optional, in case the information if the links are readable is interesting, but the contents is not. (This also means safe_getcwd() and readlinkat_malloc() are updated to make the return parameter optional, as these are called by the relevant three functions)
* path-util: use PTR_SUB1() macro in path_find_last_component()Yu Watanabe2022-03-231-9/+7
|
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-13/+7
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* basic: adjust wording and wrapping of commentsZbigniew Jędrzejewski-Szmek2022-01-031-19/+19
|
* basic: spit out chase_symlinks() from fs-util.[ch] → chase-symlinks.[ch]Lennart Poettering2021-10-051-0/+1
|
* core: Add ExecSearchPath parameter to specify the directory relative to ↵alexlzhu2021-09-281-3/+23
| | | | | | | | | | | | | 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
* path-util: make find_executable() work without /proc mountedYu Watanabe2021-08-241-1/+5
| | | | | | Follow-up for 888f65ace6296ed61285d31db846babf1c11885e. Hopefully fixes #20514.
* path-util: split out common part in find_executable_full()Yu Watanabe2021-08-241-56/+37
|
* path-util: teach find_executable_full how to look into the root directoryMaanya Goenka2021-08-101-1/+37
| | | | | | | | | 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.
* path-util: make path_compare() accept NULLLennart Poettering2021-07-081-2/+4
|
* path-util: make path_equal() an inline wrapper around path_compare()Lennart Poettering2021-06-181-4/+0
| | | | | | 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.
* various: don't say that the timestamp 'changed' on initial loadZbigniew Jędrzejewski-Szmek2021-06-021-3/+5
| | | | | | | | | | | | | | | | I always found this a bit annoying. With the patch: $ SYSTEMD_LOG_LEVEL=debug build/udevadm test /sys/class/block/dm-1 ... Loaded timestamp for '/etc/systemd/network'. Loaded timestamp for '/usr/lib/systemd/network'. Parsed configuration file /usr/lib/systemd/network/99-default.link Parsed configuration file /etc/systemd/network/10-eth0.link Created link configuration context. Loaded timestamp for '/etc/udev/rules.d'. Loaded timestamp for '/usr/lib/udev/rules.d'. ...
* path-util: add missing varargs cleanupYu Watanabe2021-05-281-2/+3
| | | | Fixes CID#1453293.
* path-util: make path_simplify() use path_find_first_component()Yu Watanabe2021-05-281-37/+27
|
* tree-wide: always drop unnecessary dot in pathYu Watanabe2021-05-281-9/+9
|
* path-util: make path_extract_filename/directory() handle "." gracefullyYu Watanabe2021-05-281-40/+39
| | | | | | 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.
* path-util: introduce path_find_last_component()Yu Watanabe2021-05-281-0/+103
|
* path-util: use path_equal() in empty_or_root()Yu Watanabe2021-05-281-3/+3
|
* path-util: make path_compare() and path_hash_func() ignore "."Yu Watanabe2021-05-281-23/+28
| | | | | | | | This also makes path_compare() may return arbitrary integer as it now simply pass the result of strcmp() or memcmp(). This changes the behavior of path_extract_filename/directory() when e.g. "/." or "/./" are input. But the change should be desired.
* path-util: use path_find_first_component() in path_make_relative()Yu Watanabe2021-05-281-60/+63
| | | | This also makes the function checks the result is a valid path or not.
* path-util: use path_find_first_component() in path_startswith()Yu Watanabe2021-05-281-15/+12
| | | | | This makes path_startswith() stricter. If one of the path component in arguments is longer than NAME_MAX, it returns NULL.
* path-util: use path_is_safe() in path_is_normalized()Yu Watanabe2021-05-281-9/+2
|
* path-util: introduce path_is_safe()Yu Watanabe2021-05-281-2/+2
| | | | | The function is similar to path_is_valid(), but it refuses paths which contain ".." component.
* path-util: use path_find_first_component() in path_is_valid()Yu Watanabe2021-05-281-12/+5
|
* path-util: introduce path_find_first_component()Yu Watanabe2021-05-281-0/+84
| | | | The function may be useful to iterate on each path component.
* path-util: fix off by one issue to detect slash at the end in path_extend()Yu Watanabe2021-05-281-1/+1
|
* tree-wide: make use of path_extend() at many placesLennart Poettering2021-05-271-5/+4
| | | | This is not a comprehensive port, but mostly some low-hanging fruit.
* path-util: add path_extend(), inspired by strextend(), but using path_join()Lennart Poettering2021-05-271-19/+34
|