diff options
author | Jakub Filak <jfilak@redhat.com> | 2014-11-19 11:01:19 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-11-21 00:32:02 +0100 |
commit | ad450c3e0418fe23e2896e581575cb06564ca29a (patch) | |
tree | 3f85df33ef5f286f750f904c5b6dc05aa336c838 /src/shared/util.c | |
parent | 1c6eb4e36bf88015d0bbe8fae417622e6132b864 (diff) |
util: add functions getting proc cwd and root
/proc/[pid]/cwd and /proc/[pid]/root are symliks to corresponding
directories
The added functions returns values of that symlinks.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index eeced4769a..01660526e4 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -797,19 +797,30 @@ int get_process_capeff(pid_t pid, char **capeff) { return get_status_field(p, "\nCapEff:", capeff); } +static int get_process_link_contents(const char *proc_file, char **name) { + int r; + + assert(proc_file); + assert(name); + + r = readlink_malloc(proc_file, name); + if (r < 0) + return r == -ENOENT ? -ESRCH : r; + + return 0; +} + int get_process_exe(pid_t pid, char **name) { const char *p; char *d; int r; assert(pid >= 0); - assert(name); p = procfs_file_alloca(pid, "exe"); - - r = readlink_malloc(p, name); + r = get_process_link_contents(p, name); if (r < 0) - return r == -ENOENT ? -ESRCH : r; + return r; d = endswith(*name, " (deleted)"); if (d) @@ -861,6 +872,26 @@ int get_process_gid(pid_t pid, gid_t *gid) { return get_process_id(pid, "Gid:", gid); } +int get_process_cwd(pid_t pid, char **cwd) { + const char *p; + + assert(pid >= 0); + + p = procfs_file_alloca(pid, "cwd"); + + return get_process_link_contents(p, cwd); +} + +int get_process_root(pid_t pid, char **root) { + const char *p; + + assert(pid >= 0); + + p = procfs_file_alloca(pid, "root"); + + return get_process_link_contents(p, root); +} + char *strnappend(const char *s, const char *suffix, size_t b) { size_t a; char *r; |