]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: print debugging information if bus_container_connect_socket() fails
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 7 Jul 2021 16:01:03 +0000 (18:01 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Jul 2021 09:18:21 +0000 (11:18 +0200)
We would return the errno, but there are many steps, and without some
debugging info it's hard to figure out what exactly failed.

src/libsystemd/sd-bus/bus-container.c

index b11ebb3f65f146b6a4929628db2c02c18e53a9d5..1159af46cdf25ebb98764e7634d6b4bd7cfdecfd 100644 (file)
@@ -37,11 +37,11 @@ int bus_container_connect_socket(sd_bus *b) {
 
         r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &usernsfd, &rootfd);
         if (r < 0)
-                return r;
+                return log_debug_errno(r, "Failed to open namespace of PID "PID_FMT": %m", b->nspid);
 
         b->input_fd = socket(b->sockaddr.sa.sa_family, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
         if (b->input_fd < 0)
-                return -errno;
+                return log_debug_errno(errno, "Failed to create a socket: %m");
 
         b->input_fd = fd_move_above_stdio(b->input_fd);
 
@@ -50,12 +50,12 @@ int bus_container_connect_socket(sd_bus *b) {
         bus_socket_setup(b);
 
         if (socketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0, pair) < 0)
-                return -errno;
+                return log_debug_errno(errno, "Failed to create a socket pair: %m");
 
         r = namespace_fork("(sd-buscntrns)", "(sd-buscntr)", NULL, 0, FORK_RESET_SIGNALS|FORK_DEATHSIG,
                            pidnsfd, mntnsfd, -1, usernsfd, rootfd, &child);
         if (r < 0)
-                return r;
+                return log_debug_errno(r, "Failed to create namespace for (sd-buscntr): %m");
         if (r == 0) {
                 pair[0] = safe_close(pair[0]);
 
@@ -80,20 +80,22 @@ int bus_container_connect_socket(sd_bus *b) {
 
         n = read(pair[0], &error_buf, sizeof(error_buf));
         if (n < 0)
-                return -errno;
+                return log_debug_errno(errno, "Failed to read error status from (sd-buscntr): %m");
 
         if (n > 0) {
                 if (n != sizeof(error_buf))
-                        return -EIO;
+                        return log_debug_errno(SYNTHETIC_ERRNO(EIO),
+                                               "Read error status of unexpected length %zd from (sd-buscntr): %m", n);
 
                 if (error_buf < 0)
-                        return -EIO;
+                        return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+                                               "Got unexpected error status from (sd-buscntr): %m");
 
                 if (error_buf == EINPROGRESS)
                         return 1;
 
                 if (error_buf > 0)
-                        return -error_buf;
+                        return log_debug_errno(error_buf, "Got error from (sd-buscntr): %m");
         }
 
         return bus_socket_start_auth(b);