summaryrefslogtreecommitdiff
path: root/src/basic/path-util.c
Commit message (Collapse)AuthorAgeFilesLines
* path-util: add new path_is_valid() helperLennart Poettering2018-10-171-5/+13
|
* path-util: fix path_simplify() with kill_dots and "."Thomas Haller2018-10-051-7/+15
| | | | | | | | | | Previously, together with kill_dots true, patch like ".", "./.", ".//.//" would all return an empty string. That is wrong. There must be one "." left to reference the current directory. Also, the comment with examples was wrong.
* trivial: fix spelling in code commentsThomas Haller2018-09-301-1/+1
| | | | Based-on-patch-by: Rafael Fontenelle <rafaelff@gnome.org>
* path-util: make use of path_join() in path_make_absolute_cwd()Franck Bui2018-07-301-4/+1
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: use PATH_STARTSWITH_SET() at two more placesLennart Poettering2018-06-111-4/+2
|
* core: rework how we validate DeviceAllow= settingsLennart Poettering2018-06-111-4/+25
| | | | | Let's make sure we don't validate "char-*" and "block-*" expressions as paths.
* basic/path-util: fix ordering in error messageZbigniew Jędrzejewski-Szmek2018-06-111-3/+3
| | | | | | Jun 11 14:29:12 krowka systemd[1]: /etc/systemd/system/workingdir.service:6: = path is not normalizedWorkingDirectory: /../../etc ↓ Jun 11 14:32:12 krowka systemd[1]: /etc/systemd/system/workingdir.service:6: WorkingDirectory= path is not normalized: /../../etc
* basic/path-util: use FLAGS_SET in one more placeZbigniew Jędrzejewski-Szmek2018-06-041-4/+2
|
* path-util: introduce path_simplify_and_warn()Yu Watanabe2018-06-031-0/+50
|
* path-util: make path_make_relative() support path including dotsYu Watanabe2018-06-031-36/+32
|
* path-util: introduce path_simplify()Yu Watanabe2018-06-031-18/+34
| | | | | | | | The function is similar to path_kill_slashes() but also removes initial './', trailing '/.', and '/./' in the path. When the second argument of path_simplify() is false, then it behaves as the same as path_kill_slashes(). Hence, this also replaces path_kill_slashes() with path_simplify().
* Merge pull request #8993 from keszybz/sd-resolve-coverity-and-related-fixesLennart Poettering2018-05-181-1/+1
|\ | | | | sd-resolve coverity and related fixes
| * tree-wide: do not wrap assert_se in extra parenthesesZbigniew Jędrzejewski-Szmek2018-05-141-1/+1
| | | | | | | | | | | | We were inconsitently using them in some cases, but in majority not. Using assignment in assert_se is very common, not an exception like in 'if', so let's drop the extra parens everywhere.
* | path-util: one more empty_or_root() changeLennart Poettering2018-05-171-1/+2
|/
* util-lib: introduce new empty_or_root() helper (#8746)Lennart Poettering2018-04-181-1/+12
| | | | | | | We check the same condition at various places. Let's add a trivial, common helper for this, and use it everywhere. It's not going to make things much faster or much shorter, but I think a lot more readable
* path-util: document a few other special cases for last_path_component()Lennart Poettering2018-04-121-4/+11
|
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-2/+1
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* path-util: don't insert duplicate "/" in path_make_absolute_cwd()Lennart Poettering2018-01-171-1/+4
| | | | | When the working directory is "/" it's prettier not to insert a second "/" in the path, even though it is technically correct.
* tree-wide: port all code to use safe_getcwd()Lennart Poettering2018-01-171-3/+4
|
* path-util: introduce new safe_getcwd() wrapperLennart Poettering2018-01-171-0/+18
| | | | | | | It's like get_current_dir_name() but protects us from CVE-2018-1000001-style exploits: https://www.halfdog.net/Security/2017/LibcRealpathBufferUnderflow/
* path-util: don't add extra "/" when prefix already is suffixed by slashLennart Poettering2018-01-171-1/+4
| | | | | No need to insert duplicate "/" if we can avoid it. This is particularly relevant if the prefix passed in is the root directory.
* path-util: do something useful if the prefix is "" in path_make_absolute()Lennart Poettering2018-01-171-1/+1
| | | | | Do not insert a "/" if the prefix we shall use is empty. It's a corner case we should probably take care of.
* tree-wide: drop a few == NULL and != NULL comparisonLennart Poettering2017-12-111-1/+1
| | | | | | | Our CODING_STYLE suggests not comparing with NULL, but relying on C's downgrade-to-bool feature for that. Fix up some code to match these guidelines. (This is not comprehensive, the coccinelle output for this is unfortunately kinda borked)
* Merge pull request #7419 from keszybz/tmpfiles-fixesLennart Poettering2017-12-061-2/+2
|\ | | | | Tmpfiles --user mode and various fixes
| * util-lib: kill duplicate slashes in lookup pathsZbigniew Jędrzejewski-Szmek2017-12-061-2/+2
| | | | | | | | | | Since we're munging the array anyway, we can make the output a bit nicer too.
* | path-util: when checking systemd versions, check both lib and lib64Lennart Poettering2017-12-051-1/+3
|/ | | | We need to check both to be compatible with multilib images.
* util-lib: handle empty string in last_path_componentZbigniew Jędrzejewski-Szmek2017-11-301-0/+3
| | | | | | Now the function returns an empty string when given an empty string. Not sure if this is the best option (maybe this should be an error?), but at least the behaviour is well defined.
* util-lib: use trailing slash in chase_symlinks, fd_is_mount_point, ↵Zbigniew Jędrzejewski-Szmek2017-11-301-0/+28
| | | | | | | | | | | | | | | | | | | | | | | path_is_mount_point The kernel will reply with -ENOTDIR when we try to access a non-directory under a name which ends with a slash. But our functions would strip the trailing slash under various circumstances. Keep the trailing slash, so that path_is_mount_point("/path/to/file/") return -ENOTDIR when /path/to/file/ is a file. Tests are added for this change in behaviour. Also, when called with a trailing slash, path_is_mount_point() would get "" from basename(), and call name_to_handle_at(3, "", ...), and always return -ENOENT. Now it'll return -ENOTDIR if the mount point is a file, and true if it is a directory and a mount point. v2: - use strip_trailing_chars() v3: - instead of stripping trailing chars(), do the opposite — preserve them.
* Merge pull request #7198 from poettering/stdin-stdoutLennart Poettering2017-11-191-2/+1
|\ | | | | Add StandardInput=data, StandardInput=file:... and more
| * fs-util: rename path_is_safe() → path_is_normalized()Lennart Poettering2017-11-171-2/+1
| | | | | | | | | | | | | | | | | | | | | | Already, path_is_safe() refused paths container the "." dir. Doing that isn't strictly necessary to be "safe" by most definitions of the word. But it is necessary in order to consider a path "normalized". Hence, "path_is_safe()" is slightly misleading a name, but "path_is_normalize()" is more descriptive, hence let's rename things accordingly. No functional changes.
* | Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
|/ | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* path-util: some updates to path_make_relative()Lennart Poettering2017-10-021-8/+17
| | | | | | | | | | Don't miscount number of "../" to generate, if we "." is included in an input path. Also, refuse if we encounter "../" since we can't possibly follow that up properly, without file system access. Some other modernizations.
* basic/path-util: allow flags for path_equal_or_files_sameZbigniew Jędrzejewski-Szmek2017-06-171-2/+2
| | | | | No functional change, just a new parameters and the tests that AT_SYMLINK_NOFOLLOW works as expected.
* fs-util: unify code we use to check if dirent's d_name is "." or ".."Lennart Poettering2017-02-021-6/+19
| | | | | We use different idioms at different places. Let's replace this is the one true new idiom, that is even a bit faster...
* fs-util: add flags parameter to chase_symlinks()Lennart Poettering2016-12-011-1/+1
| | | | | | Let's remove chase_symlinks_prefix() and instead introduce a flags parameter to chase_symlinks(), with a flag CHASE_PREFIX_ROOT that exposes the behaviour of chase_symlinks_prefix().
* tree-wide: stop using canonicalize_file_name(), use chase_symlinks() insteadLennart Poettering2016-12-011-23/+22
| | | | | | | | Let's use chase_symlinks() everywhere, and stop using GNU canonicalize_file_name() everywhere. For most cases this should not change behaviour, however increase exposure of our function to get better tested. Most importantly in a few cases (most notably nspawn) it can take the correct root directory into account when chasing symlinks.
* Merge pull request #4510 from keszybz/tree-wide-cleanupsLennart Poettering2016-11-031-7/+5
|\ | | | | Tree wide cleanups
| * tree-wide: drop NULL sentinel from strjoinZbigniew Jędrzejewski-Szmek2016-10-231-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | This makes strjoin and strjoina more similar and avoids the useless final argument. spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c) git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/' This might have missed a few cases (spatch has a really hard time dealing with _cleanup_ macros), but that's no big issue, they can always be fixed later.
* | tests: clarify test_path_startswith return value (#4508)Zbigniew Jędrzejewski-Szmek2016-10-301-0/+10
|/ | | A pendant for #4481.
* tree-wide: introduce free_and_replace helperZbigniew Jędrzejewski-Szmek2016-10-161-3/+1
| | | | | | It's a common pattern, so add a helper for it. A macro is necessary because a function that takes a pointer to a pointer would be type specific, similarly to cleanup functions. Seems better to use a macro.
* Allow block and char classes in DeviceAllow bus properties (#4353)Zbigniew Jędrzejewski-Szmek2016-10-121-3/+8
| | | | | | | | | | Allowed paths are unified betwen the configuration file parses and the bus property checker. The biggest change is that the bus code now allows "block-" and "char-" classes. In addition, path_startswith("/dev") was used in the bus code, and startswith("/dev") was used in the config file code. It seems reasonable to use path_startswith() which allows a slightly broader class of strings. Fixes #3935.
* path-util: add a function to peek into a container and guess systemd versionZbigniew Jędrzejewski-Szmek2016-10-081-0/+68
| | | | | This is a bit crude and only works for new systemd versions which have libsystemd-shared.
* path-util: also support ".old" and ".new" suffixes and recommend themZbigniew Jędrzejewski-Szmek2016-04-291-3/+5
| | | | | | | | | ~ suffix works fine, but looks to much like it the file is supposed to be automatically cleaned up. For new versions of configuration files installers might want to using something that looks more permanent like foobar.new. So let's add treat ".old" and ".new" as special. Update test to match.
* path-util: document that we shouldn't add further entries to ↵Lennart Poettering2016-04-291-1/+15
| | | | | | | hidden_or_backup_file() And let's add ".bak" as a generic suffix for backups, that people can use without having to register their stuff in our list.
* tree-wide: rename hidden_file to hidden_or_backup_file and optimizeZbigniew Jędrzejewski-Szmek2016-04-281-26/+26
| | | | | | | | | | | In standard linux parlance, "hidden" usually means that the file name starts with ".", and nothing else. Rename the function to convey what the function does better to casual readers. Stop exposing hidden_file_allow_backup which is rather ugly and rewrite hidden_file to extract the suffix first. Note that hidden_file_allow_backup excluded files with "~" at the end, which is quite confusing. Let's get rid of it before it gets used in the wrong place.
* path-util: Add hidden suffixes for ucf (#3131)Martin Pitt2016-04-271-0/+3
| | | | | | | | ucf is a standard Debian helper for managing configuration file upgrades which need more interaction or elaborate merging than conffiles managed by dpkg. Ignore its temporary and backup files similarly to the *.dpkg-* ones to avoid creating units for them in generators. https://bugs.debian.org/775903
* tree-wide: introduce PATH_IN_SET macroZbigniew Jędrzejewski-Szmek2016-04-161-4/+4
|