bus-kernel.c revision 7211f918ba2b86e0041413b47d51d7593e73cf5d
/*-*- 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/>.
***/
#ifdef HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/memcheck.h>
#endif
#include <fcntl.h>
#include "util.h"
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-kernel.h"
#define KDBUS_MSG_FOREACH_DATA(d, k) \
for ((d) = (k)->data; \
int r;
assert(s);
if (!startswith(s, ":1."))
return 0;
if (r < 0)
return r;
return 1;
}
assert(d);
assert(p);
(*d)->type = KDBUS_MSG_PAYLOAD_VEC;
}
assert(d);
assert(d);
(*d)->type = KDBUS_MSG_DST_NAME;
}
static int bus_message_setup_kmsg(sd_bus_message *m) {
struct kdbus_msg_data *d;
bool well_known;
int r;
assert(m);
if (m->kdbus)
return 0;
if (m->destination) {
if (r < 0)
return r;
well_known = r == 0;
} else
well_known = false;
/* Add in fixed header, fields header, fields header padding and payload */
/* Add in well-known destination header */
if (well_known) {
}
if (!m->kdbus)
return -ENOMEM;
well_known ? 0 :
if (well_known)
if (m->fields) {
}
}
if (m->body)
m->free_kdbus = true;
return 0;
}
int bus_kernel_take_fd(sd_bus *b) {
struct kdbus_cmd_hello hello = {};
int r;
assert(b);
if (r < 0)
return -errno;
return -ENOMEM;
b->is_kernel = true;
r = bus_start_running(b);
if (r < 0)
return r;
return 1;
}
int bus_kernel_connect(sd_bus *b) {
assert(b);
if (b->input_fd < 0)
return -errno;
return bus_kernel_take_fd(b);
}
int r;
assert(m);
r = bus_message_setup_kmsg(m);
if (r < 0)
return r;
if (r < 0)
return 0;
}
static void close_kdbus_msg(struct kdbus_msg *k) {
struct kdbus_msg_data *d;
KDBUS_MSG_FOREACH_DATA(d, k) {
if (d->type != KDBUS_MSG_UNIX_FDS)
continue;
}
}
sd_bus_message *m = NULL;
struct kdbus_msg_data *d;
struct bus_header *h = NULL;
int r;
assert(k);
if (k->payload_type != KDBUS_PAYLOAD_DBUS1)
return 0;
KDBUS_MSG_FOREACH_DATA(d, k) {
size_t l;
if (d->type == KDBUS_MSG_PAYLOAD) {
if (!h) {
if (l < sizeof(struct bus_header))
return -EBADMSG;
h = (struct bus_header*) d->data;
}
n_payload++;
n_bytes += l;
} else if (d->type == KDBUS_MSG_UNIX_FDS) {
int *f;
unsigned j;
j = l / sizeof(int);
if (!f)
return -ENOMEM;
fds = f;
n_fds += j;
} else if (d->type == KDBUS_MSG_SRC_CREDS)
else if (d->type == KDBUS_MSG_TIMESTAMP)
}
if (!h)
return -EBADMSG;
r = bus_header_size(h, &total);
if (r < 0)
return r;
return -EBADMSG;
if (r < 0)
return r;
KDBUS_MSG_FOREACH_DATA(d, k) {
size_t l;
if (d->type != KDBUS_MSG_PAYLOAD)
continue;
if (idx == sizeof(struct bus_header) &&
l == BUS_MESSAGE_FIELDS_SIZE(m))
l == BUS_MESSAGE_BODY_SIZE(m))
else if (!(idx == 0 && l == sizeof(struct bus_header)) &&
return -EBADMSG;
}
idx += l;
}
if (creds) {
}
r = bus_message_parse_fields(m);
if (r < 0) {
return r;
}
/* We take possession of the kmsg struct now */
m->kdbus = k;
m->free_kdbus = true;
m->free_fds = true;
*ret = m;
return 1;
}
struct kdbus_msg *k;
int r;
assert(m);
for (;;) {
void *q;
if (!q)
return -errno;
/* Let's tell valgrind that there's really no need to
* initialize this fully. This should be removed again
* when valgrind learned the kdbus ioctls natively. */
if (r >= 0)
break;
return 0;
return -errno;
sz *= 2;
}
r = bus_kernel_make_message(bus, k, m);
if (r > 0)
else
close_kdbus_msg(k);
return r;
}
int bus_kernel_create(const char *name, char **s) {
struct kdbus_cmd_fname *fname;
size_t l;
int fd;
char *p;
assert(s);
if (fd < 0)
return -errno;
fname->user_flags = 0;
if (!p)
return -ENOMEM;
free(p);
return -errno;
}
if (s)
*s = p;
return fd;
}