From aad3a64d63db22db3e506de973f9577d8205554d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Nov 2019 14:55:50 +0100 Subject: process-util: tweak get_process_cwd() when calling for own process Let's bypass /proc if we can. --- src/basic/process-util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/basic/process-util.c') diff --git a/src/basic/process-util.c b/src/basic/process-util.c index aaec6a6a99..842c879c4e 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -21,8 +21,8 @@ #include "alloc-util.h" #include "architecture.h" -#include "escape.h" #include "env-util.h" +#include "escape.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -34,6 +34,7 @@ #include "missing_sched.h" #include "missing_syscall.h" #include "namespace-util.h" +#include "path-util.h" #include "process-util.h" #include "raw-clone.h" #include "rlimit-util.h" @@ -500,6 +501,9 @@ int get_process_cwd(pid_t pid, char **cwd) { assert(pid >= 0); + if (pid == 0 || pid == getpid_cached()) + return safe_getcwd(cwd); + p = procfs_file_alloca(pid, "cwd"); return get_process_link_contents(p, cwd); -- cgit v1.2.3