chiark / gitweb /
bus-proxy: set custom thread names
authorDavid Herrmann <dh.herrmann@gmail.com>
Sat, 17 Jan 2015 13:32:58 +0000 (14:32 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Sat, 17 Jan 2015 13:32:58 +0000 (14:32 +0100)
Set thread-names to "p$PIDu$UID" and suffix with '*' if truncated. This
helps debugging bus-proxy issues if we want to figure out which
connections are currently open.

src/bus-proxyd/bus-proxyd.c

index 702f021a6bdcfed8df3082e4a7a53394b80fc546..15a79fc427946b7e5b6026792fa53d5aa948431e 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/poll.h>
 #include <string.h>
 #include <errno.h>
 #include <sys/poll.h>
+#include <sys/prctl.h>
 #include <stddef.h>
 #include <getopt.h>
 #include <pthread.h>
 #include <stddef.h>
 #include <getopt.h>
 #include <pthread.h>
@@ -91,12 +92,19 @@ static int client_context_new(ClientContext **out, int fd) {
 static void *run_client(void *userdata) {
         _cleanup_(client_context_freep) ClientContext *c = userdata;
         _cleanup_(proxy_freep) Proxy *p = NULL;
 static void *run_client(void *userdata) {
         _cleanup_(client_context_freep) ClientContext *c = userdata;
         _cleanup_(proxy_freep) Proxy *p = NULL;
+        char comm[16];
         int r;
 
         r = proxy_new(&p, c->fd, c->fd, arg_address);
         if (r < 0)
                 goto exit;
 
         int r;
 
         r = proxy_new(&p, c->fd, c->fd, arg_address);
         if (r < 0)
                 goto exit;
 
+        /* set comm to "p$PIDu$UID" and suffix with '*' if truncated */
+        r = snprintf(comm, sizeof(comm), "p" PID_FMT "u" UID_FMT, p->local_creds.pid, p->local_creds.uid);
+        if (r >= (ssize_t)sizeof(comm))
+                comm[sizeof(comm) - 2] = '*';
+        (void) prctl(PR_SET_NAME, comm);
+
         r = proxy_load_policy(p, arg_configuration);
         if (r < 0)
                 goto exit;
         r = proxy_load_policy(p, arg_configuration);
         if (r < 0)
                 goto exit;