bus-container.c revision fbadf04511389c4a0687ba5e9baf0ecebdbb07f1
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <fcntl.h>
#include "util.h"
#include "fileio.h"
#include "bus-internal.h"
#include "bus-socket.h"
#include "bus-container.h"
int bus_container_connect_socket(sd_bus *b) {
int r;
assert(b);
if (r < 0)
return r;
if (r < 0)
return r;
if (b->input_fd < 0)
return -errno;
bus_socket_setup(b);
if (child < 0)
return -errno;
if (child == 0) {
if (r < 0)
_exit(255);
/* We just changed PID namespace, however it will only
* take effect on the children we now fork. Hence,
* let's fork another time, and connect from this
* grandchild, so that SO_PEERCRED of our connection
* comes from a process from within the container, and
* not outside of it */
grandchild = fork();
if (grandchild < 0)
_exit(255);
if (grandchild == 0) {
if (r < 0) {
if (errno == EINPROGRESS)
_exit(1);
_exit(255);
}
}
if (r < 0)
_exit(255);
_exit(255);
}
if (r < 0)
return r;
return -EIO;
return 1;
return -EIO;
return bus_socket_start_auth(b);
}
int bus_container_connect_kernel(sd_bus *b) {
union {
} control = {};
.msg_control = &control,
.msg_controllen = sizeof(control),
};
int r;
assert(b);
if (r < 0)
return r;
if (r < 0)
return r;
return -errno;
if (child < 0)
return -errno;
if (child == 0) {
close_nointr_nofail(pair[0]);
pair[0] = -1;
if (r < 0)
/* We just changed PID namespace, however it will only
* take effect on the children we now fork. Hence,
* let's fork another time, and connect from this
* grandchild, so that kdbus only sees the credentials
* of this process which comes from within the
* container, and not outside of it */
grandchild = fork();
if (grandchild < 0)
if (grandchild == 0) {
if (fd < 0)
}
if (r < 0)
}
if (r < 0)
return r;
return -EIO;
return -EIO;
return -errno;
int *fds;
unsigned n_fds;
if (n_fds != 1) {
return -EIO;
}
}
fd = -1;
return bus_kernel_take_fd(b);
}