summaryrefslogtreecommitdiff
path: root/src/basic/path-util.c
Commit message (Collapse)AuthorAge
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | 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-08-24
| | | | | | | | | | | | | | | | 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-08-24
|
* core: rework how we validate DeviceAllow= settingsLennart Poettering2018-08-24
| | | | | 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-08-24
| | | | | | 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-08-24
|
* path-util: introduce path_simplify_and_warn()Yu Watanabe2018-08-24
|
* path-util: make path_make_relative() support path including dotsYu Watanabe2018-08-24
|
* path-util: introduce path_simplify()Yu Watanabe2018-08-24
| | | | | | | | 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().
* tree-wide: do not wrap assert_se in extra parenthesesZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | 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-08-24
|
* util-lib: introduce new empty_or_root() helper (#8746)Lennart Poettering2018-08-24
| | | | | | | | 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-08-24
|
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | 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-08-24
| | | | | | | | | | | | | | | | 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-05-30
| | | | | 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-05-30
|
* path-util: introduce new safe_getcwd() wrapperLennart Poettering2018-05-30
| | | | | | | 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-05-30
| | | | | 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-05-30
| | | | | Do not insert a "/" if the prefix we shall use is empty. It's a corner case we should probably take care of.
* Prep v236 : Add missing SPDX-License-Identifier (2/9) src/basicSven Eden2018-03-26
|
* tree-wide: drop a few == NULL and != NULL comparisonLennart Poettering2017-12-08
| | | | | | | 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)
* util-lib: kill duplicate slashes in lookup pathsZbigniew Jędrzejewski-Szmek2017-11-23
| | | | | Since we're munging the array anyway, we can make the output a bit nicer too.
* Fix various build failures with the latest systemd updates.Sven Eden2017-12-08
|
* Apply updates from upstreamSven Eden2017-12-07
|
* path-util: some updates to path_make_relative()Lennart Poettering2017-11-22
| | | | | | | | | | 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-07-25
| | | | | No functional change, just a new parameters and the tests that AT_SYMLINK_NOFOLLOW works as expected.
* Prep v233.3: Unmask various functions for future coverage tests.Sven Eden2017-07-19
| | | | | These functions, although not used by elogind itself, are mostly tiny and crucial for important tests to work.
* Prep v233: Unmask now needed functions in src/basicSven Eden2017-07-17
|
* fs-util: unify code we use to check if dirent's d_name is "." or ".."Lennart Poettering2017-07-17
| | | | | 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 Poettering2017-07-17
| | | | | | 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 Poettering2017-07-17
| | | | | | | | 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.
* tree-wide: drop NULL sentinel from strjoinZbigniew Jędrzejewski-Szmek2017-07-17
| | | | | | | | | | | | | 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/elogind -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libelogind/sd-bus -I ./src/libelogind/sd-event -I ./src/libelogind/sd-login -I ./src/libelogind/sd-netlink -I ./src/libelogind/sd-network -I ./src/libelogind/sd-hwdb -I ./src/libelogind/sd-device -I ./src/libelogind/sd-id128 -I ./src/libelogind-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.
* Prep v232: Mask new functions that are unneeded by elogindSven Eden2017-07-05
|
* Prep v232: Add missing includesSven Eden2017-07-05
|
* tests: clarify test_path_startswith return value (#4508)Zbigniew Jędrzejewski-Szmek2017-07-05
| | | | A pendant for #4481.
* tree-wide: introduce free_and_replace helperZbigniew Jędrzejewski-Szmek2017-07-05
| | | | | | 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-Szmek2017-07-05
| | | | | | | | | | | 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 elogind versionZbigniew Jędrzejewski-Szmek2017-07-05
| | | | | This is a bit crude and only works for new elogind versions which have libelogind-shared.
* Prep v230: Apply missing upstream fixes and updates (2/8) src/basic.Sven Eden2017-06-16
|
* path-util: Add hidden suffixes for ucf (#3131)Martin Pitt2017-06-16
| | | | | | | | | 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-Szmek2017-06-16
|
* Prep v229: Remove remaining emacs settings [1/6] src/basicSven Eden2017-05-17
|
* basic: re-sort includesThomas Hindoe Paaboel Andersen2017-05-17
| | | | | My previous patch to only include what we use accidentially placed the added inlcudes in non-sorted order.
* basic: include only what we useThomas Hindoe Paaboel Andersen2017-05-17
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* Prep v228: Full diff to master revealed more functions that are unused.Sven Eden2017-04-26
|
* Prep v228: Condense elogind source masks (2/5)Sven Eden2017-04-26
|
* Prep v228: Clean up the new src/basic/*-util-[hc] files:Sven Eden2017-04-26
| | | | | | | | | | | | | - src/basic/capability-util.[hc] - src/basic/cgroup-util.[hc] - src/basic/fd-util.[hc] - src/basic/fs-util.[hc] - src/basic/memfd-util.[hc] - src/basic/path-util.[hc] - src/basic/socket-util.[hc] - src/basic/terminal-util.[hc] - src/basic/user-util.[hc] - src/basic/xattr-util.[hc]
* Prep v228: Add remaining updates from upstream (2/3)Sven Eden2017-04-26
| | | | | Apply remaining fixes and the performed move of utility functions into their own foo-util.[hc] files on libbasic.
* path-util: minor coding style fixLennart Poettering2017-04-26
| | | | | | We usually avoid relying on C's degrade-to-boolean functionality when comparing numerical variables with 0. We use it only for pointers and actual booleans.