summaryrefslogtreecommitdiffstats
path: root/src/basic/path-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-04-01 10:43:49 +0200
committerLennart Poettering <lennart@poettering.net>2022-04-01 15:22:27 +0200
commitaed3c5eca3f2ccc98e724c1f7f7460b8bd77738f (patch)
tree72893bc9a538fa825e5fa92d7627cd588d163221 /src/basic/path-util.c
parentMerge pull request #22872 from yuwata/udevadm-wait (diff)
downloadsystemd-aed3c5eca3f2ccc98e724c1f7f7460b8bd77738f.tar.xz
systemd-aed3c5eca3f2ccc98e724c1f7f7460b8bd77738f.zip
process-util: refactor APIs for reading /proc/self/xyz symlinks
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)
Diffstat (limited to 'src/basic/path-util.c')
-rw-r--r--src/basic/path-util.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index 0be2b9eec8..92ee3cee2d 100644
--- a/src/basic/path-util.c
+++ b/src/basic/path-util.c
@@ -63,7 +63,7 @@ char *path_make_absolute(const char *p, const char *prefix) {
}
int safe_getcwd(char **ret) {
- char *cwd;
+ _cleanup_free_ char *cwd = NULL;
cwd = get_current_dir_name();
if (!cwd)
@@ -71,12 +71,12 @@ int safe_getcwd(char **ret) {
/* Let's make sure the directory is really absolute, to protect us from the logic behind
* CVE-2018-1000001 */
- if (cwd[0] != '/') {
- free(cwd);
+ if (cwd[0] != '/')
return -ENOMEDIUM;
- }
- *ret = cwd;
+ if (ret)
+ *ret = TAKE_PTR(cwd);
+
return 0;
}