#include "bus-internal.h"
#include "bus-message.h"
+#define SNDBUF_SIZE (8*1024*1024)
+
static void iovec_advance(struct iovec iov[], unsigned *idx, size_t size) {
while (size > 0) {
return 1;
}
-int bus_socket_setup(sd_bus *b) {
+void bus_socket_setup(sd_bus *b) {
int enable;
- socklen_t l;
assert(b);
enable = !b->bus_client && (b->attach_flags & KDBUS_ATTACH_SECLABEL);
setsockopt(b->input_fd, SOL_SOCKET, SO_PASSSEC, &enable, sizeof(enable));
- /* Increase the buffers to a MB */
- fd_inc_rcvbuf(b->input_fd, 1024*1024);
- fd_inc_sndbuf(b->output_fd, 1024*1024);
+ /* Increase the buffers to 8 MB */
+ fd_inc_rcvbuf(b->input_fd, SNDBUF_SIZE);
+ fd_inc_sndbuf(b->output_fd, SNDBUF_SIZE);
+
+ b->is_kernel = false;
+ b->message_version = 1;
+ b->message_endian = 0;
+}
+
+static void bus_get_peercred(sd_bus *b) {
+ socklen_t l;
+
+ assert(b);
/* Get the peer for socketpair() sockets */
l = sizeof(b->ucred);
if (getsockopt(b->input_fd, SOL_SOCKET, SO_PEERCRED, &b->ucred, &l) >= 0 && l >= sizeof(b->ucred))
b->ucred_valid = b->ucred.pid > 0;
-
- return 0;
}
static int bus_socket_start_auth_client(sd_bus *b) {
int bus_socket_start_auth(sd_bus *b) {
assert(b);
+ bus_get_peercred(b);
+
b->state = BUS_AUTHENTICATING;
b->auth_timeout = now(CLOCK_MONOTONIC) + BUS_DEFAULT_TIMEOUT;
b->output_fd = b->input_fd;
- r = bus_socket_setup(b);
- if (r < 0)
- return r;
+ bus_socket_setup(b);
r = connect(b->input_fd, &b->sockaddr.sa, b->sockaddr_size);
if (r < 0) {
close_nointr_nofail(s[1]);
b->output_fd = b->input_fd = s[0];
+ bus_socket_setup(b);
+
return bus_socket_start_auth(b);
}
int bus_socket_take_fd(sd_bus *b) {
- int r;
assert(b);
- r = bus_socket_setup(b);
- if (r < 0)
- return r;
+ bus_socket_setup(b);
return bus_socket_start_auth(b);
}