diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-04-08 03:22:25 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-04-08 03:22:25 +0200 |
commit | 7072ced8274274cd1b0fa085dd4118462e03884e (patch) | |
tree | 5eadaf1eed7dd8180017cc27c058f81025e05872 /util.c | |
parent | a90ebccc072efa17313fe68c737b3507247c37dd (diff) |
manager: print process name for all SIGCHLD received
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -438,6 +438,33 @@ finish: return r; } +char *truncate_nl(char *s) { + assert(s); + + s[strcspn(s, NEWLINE)] = 0; + return s; +} + +int get_process_name(pid_t pid, char **name) { + char *p; + int r; + + assert(pid >= 1); + assert(name); + + if (asprintf(&p, "/proc/%llu/comm", (unsigned long long) pid) < 0) + return -ENOMEM; + + r = read_one_line_file(p, name); + free(p); + + if (r < 0) + return r; + + truncate_nl(*name); + return 0; +} + char *strappend(const char *s, const char *suffix) { size_t a, b; char *r; |