summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-08 03:22:25 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-08 03:22:25 +0200
commit7072ced8274274cd1b0fa085dd4118462e03884e (patch)
tree5eadaf1eed7dd8180017cc27c058f81025e05872 /util.c
parenta90ebccc072efa17313fe68c737b3507247c37dd (diff)
manager: print process name for all SIGCHLD received
Diffstat (limited to 'util.c')
-rw-r--r--util.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/util.c b/util.c
index 69a26a2d08..b4d6eefbd2 100644
--- a/util.c
+++ b/util.c
@@ -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;