]> err.no Git - systemd/commitdiff
manager: print process name for all SIGCHLD received
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Apr 2010 01:22:25 +0000 (03:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Apr 2010 01:22:25 +0000 (03:22 +0200)
manager.c
util.c
util.h

index 7adaa4ed0b429e3964eadd366b1f283b201eedb6..9e4fbbbaeddd0d70973817bc0c76433de776dcf4 100644 (file)
--- a/manager.c
+++ b/manager.c
@@ -1414,8 +1414,6 @@ unsigned manager_dispatch_dbus_queue(Manager *m) {
 static int manager_dispatch_sigchld(Manager *m) {
         assert(m);
 
-        log_debug("dispatching SIGCHLD");
-
         for (;;) {
                 siginfo_t si;
                 Unit *u;
@@ -1469,9 +1467,16 @@ static int manager_process_signal_fd(Manager *m, bool *quit) {
 
                 switch (sfsi.ssi_signo) {
 
-                case SIGCHLD:
+                case SIGCHLD: {
+                        char *name = NULL;
+
+                        get_process_name(sfsi.ssi_pid, &name);
+                        log_debug("Got SIGCHLD for process %llu (%s)", (unsigned long long) sfsi.ssi_pid, strna(name));
+                        free(name);
+
                         sigchld = true;
                         break;
+                }
 
                 case SIGINT:
                 case SIGTERM:
diff --git a/util.c b/util.c
index 69a26a2d08ddecb8aef5a3fa955a4a06377ff820..b4d6eefbd265f160eddfe38e0f07f88954aafc4d 100644 (file)
--- 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;
diff --git a/util.h b/util.h
index 14f1a7a177d9b7a677b942d46c6ccccf6bf29cab..30a0616d542060d8c98aa3028c0eab95a914d727 100644 (file)
--- a/util.h
+++ b/util.h
@@ -39,6 +39,7 @@ typedef uint64_t usec_t;
 
 /* What is interpreted as whitespace? */
 #define WHITESPACE " \t\n\r"
+#define NEWLINE "\n\r"
 
 usec_t now(clockid_t clock);
 
@@ -130,10 +131,13 @@ int reset_all_signal_handlers(void);
 
 char *strstrip(char *s);
 char *delete_chars(char *s, const char *bad);
+char *truncate_nl(char *s);
 
 char *file_in_same_dir(const char *path, const char *filename);
 int mkdir_parents(const char *path, mode_t mode);
 
+int get_process_name(pid_t pid, char **name);
+
 char hexchar(int x);
 int unhexchar(char c);
 char octchar(int x);