LCOV - code coverage report
Current view: top level - libsystemd/sd-bus - bus-container.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 0 53 0.0 %
Date: 2019-08-22 15:41:25 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <fcntl.h>
       4             : #include <unistd.h>
       5             : 
       6             : #include "bus-container.h"
       7             : #include "bus-internal.h"
       8             : #include "bus-socket.h"
       9             : #include "fd-util.h"
      10             : #include "namespace-util.h"
      11             : #include "process-util.h"
      12             : #include "util.h"
      13             : 
      14           0 : int bus_container_connect_socket(sd_bus *b) {
      15           0 :         _cleanup_close_pair_ int pair[2] = { -1, -1 };
      16           0 :         _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
      17           0 :         int r, error_buf = 0;
      18             :         pid_t child;
      19             :         ssize_t n;
      20             : 
      21           0 :         assert(b);
      22           0 :         assert(b->input_fd < 0);
      23           0 :         assert(b->output_fd < 0);
      24           0 :         assert(b->nspid > 0 || b->machine);
      25             : 
      26           0 :         if (b->nspid <= 0) {
      27           0 :                 r = container_get_leader(b->machine, &b->nspid);
      28           0 :                 if (r < 0)
      29           0 :                         return r;
      30             :         }
      31             : 
      32           0 :         r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &usernsfd, &rootfd);
      33           0 :         if (r < 0)
      34           0 :                 return r;
      35             : 
      36           0 :         b->input_fd = socket(b->sockaddr.sa.sa_family, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
      37           0 :         if (b->input_fd < 0)
      38           0 :                 return -errno;
      39             : 
      40           0 :         b->input_fd = fd_move_above_stdio(b->input_fd);
      41             : 
      42           0 :         b->output_fd = b->input_fd;
      43             : 
      44           0 :         bus_socket_setup(b);
      45             : 
      46           0 :         if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, pair) < 0)
      47           0 :                 return -errno;
      48             : 
      49           0 :         r = namespace_fork("(sd-buscntrns)", "(sd-buscntr)", NULL, 0, FORK_RESET_SIGNALS|FORK_DEATHSIG,
      50             :                            pidnsfd, mntnsfd, -1, usernsfd, rootfd, &child);
      51           0 :         if (r < 0)
      52           0 :                 return r;
      53           0 :         if (r == 0) {
      54           0 :                 pair[0] = safe_close(pair[0]);
      55             : 
      56           0 :                 r = connect(b->input_fd, &b->sockaddr.sa, b->sockaddr_size);
      57           0 :                 if (r < 0) {
      58             :                         /* Try to send error up */
      59           0 :                         error_buf = errno;
      60           0 :                         (void) write(pair[1], &error_buf, sizeof(error_buf));
      61           0 :                         _exit(EXIT_FAILURE);
      62             :                 }
      63             : 
      64           0 :                 _exit(EXIT_SUCCESS);
      65             :         }
      66             : 
      67           0 :         pair[1] = safe_close(pair[1]);
      68             : 
      69           0 :         r = wait_for_terminate_and_check("(sd-buscntrns)", child, 0);
      70           0 :         if (r < 0)
      71           0 :                 return r;
      72           0 :         if (r != EXIT_SUCCESS)
      73           0 :                 return -EPROTO;
      74             : 
      75           0 :         n = read(pair[0], &error_buf, sizeof(error_buf));
      76           0 :         if (n < 0)
      77           0 :                 return -errno;
      78             : 
      79           0 :         if (n > 0) {
      80           0 :                 if (n != sizeof(error_buf))
      81           0 :                         return -EIO;
      82             : 
      83           0 :                 if (error_buf < 0)
      84           0 :                         return -EIO;
      85             : 
      86           0 :                 if (error_buf == EINPROGRESS)
      87           0 :                         return 1;
      88             : 
      89           0 :                 if (error_buf > 0)
      90           0 :                         return -error_buf;
      91             :         }
      92             : 
      93           0 :         return bus_socket_start_auth(b);
      94             : }

Generated by: LCOV version 1.14