Commit 4a875b61 authored by Lennart Poettering's avatar Lennart Poettering

kdbus: parse cgroup meta data, too

parent c62e11ce
......@@ -447,7 +447,9 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
else if (d->type == KDBUS_MSG_SRC_CMDLINE) {
m->cmdline = d->str;
m->cmdline_length = l;
} else
} else if (d->type == KDBUS_MSG_SRC_CGROUP)
m->cgroup = d->str;
else
log_debug("Got unknown field from kernel %llu", d->type);
}
......@@ -553,7 +555,7 @@ int bus_kernel_create(const char *name, char **s) {
make->flags = KDBUS_ACCESS_WORLD | KDBUS_POLICY_OPEN;
make->bus_flags = 0;
make->bloom_size = BLOOM_SIZE;
make->cgroup_id = 1;
assert_cc(BLOOM_SIZE % 8 == 0);
p = strjoin("/dev/kdbus/", make->name, "/bus", NULL);
......
......@@ -657,8 +657,10 @@ const sd_bus_error *sd_bus_message_get_error(sd_bus_message *m) {
int sd_bus_message_get_uid(sd_bus_message *m, uid_t *uid) {
if (!m)
return -EINVAL;
if (!uid)
return -EINVAL;
if (!m->uid_valid)
return -ENOENT;
return -ESRCH;
*uid = m->uid;
return 0;
......@@ -667,8 +669,10 @@ int sd_bus_message_get_uid(sd_bus_message *m, uid_t *uid) {
int sd_bus_message_get_gid(sd_bus_message *m, gid_t *gid) {
if (!m)
return -EINVAL;
if (!gid)
return -EINVAL;
if (!m->gid_valid)
return -ENOENT;
return -ESRCH;
*gid = m->gid;
return 0;
......@@ -677,8 +681,10 @@ int sd_bus_message_get_gid(sd_bus_message *m, gid_t *gid) {
int sd_bus_message_get_pid(sd_bus_message *m, pid_t *pid) {
if (!m)
return -EINVAL;
if (!pid)
return -EINVAL;
if (m->pid <= 0)
return -ENOENT;
return -ESRCH;
*pid = m->pid;
return 0;
......@@ -687,8 +693,10 @@ int sd_bus_message_get_pid(sd_bus_message *m, pid_t *pid) {
int sd_bus_message_get_tid(sd_bus_message *m, pid_t *tid) {
if (!m)
return -EINVAL;
if (!tid)
return -EINVAL;
if (m->tid <= 0)
return -ENOENT;
return -ESRCH;
*tid = m->tid;
return 0;
......@@ -697,26 +705,32 @@ int sd_bus_message_get_tid(sd_bus_message *m, pid_t *tid) {
int sd_bus_message_get_pid_starttime(sd_bus_message *m, uint64_t *usec) {
if (!m)
return -EINVAL;
if (!usec)
return -EINVAL;
if (m->pid_starttime <= 0)
return -ENOENT;
return -ESRCH;
*usec = m->pid_starttime;
return 0;
}
const char *sd_bus_message_get_selinux_context(sd_bus_message *m) {
int sd_bus_message_get_selinux_context(sd_bus_message *m, const char **ret) {
if (!m)
return NULL;
return -EINVAL;
if (!m->label)
return -ESRCH;
return m->label;
*ret = m->label;
return 0;
}
int sd_bus_message_get_monotonic_timestamp(sd_bus_message *m, uint64_t *usec) {
if (!m)
return -EINVAL;
if (!usec)
return -EINVAL;
if (m->monotonic <= 0)
return -ENOENT;
return -ESRCH;
*usec = m->monotonic;
return 0;
......@@ -725,33 +739,61 @@ int sd_bus_message_get_monotonic_timestamp(sd_bus_message *m, uint64_t *usec) {
int sd_bus_message_get_realtime_timestamp(sd_bus_message *m, uint64_t *usec) {
if (!m)
return -EINVAL;
if (!usec)
return -EINVAL;
if (m->realtime <= 0)
return -ENOENT;
return -ESRCH;
*usec = m->realtime;
return 0;
}
const char *sd_bus_message_get_comm(sd_bus_message *m) {
int sd_bus_message_get_comm(sd_bus_message *m, const char **ret) {
if (!m)
return NULL;
return -EINVAL;
if (!ret)
return -EINVAL;
if (!m->comm)
return -ESRCH;
return m->comm;
*ret = m->comm;
return 0;
}
const char *sd_bus_message_get_tid_comm(sd_bus_message *m) {
int sd_bus_message_get_tid_comm(sd_bus_message *m, const char **ret) {
if (!m)
return NULL;
return -EINVAL;
if (!ret)
return -EINVAL;
if (!m->tid_comm)
return -ESRCH;
return m->tid_comm;
*ret = m->tid_comm;
return 0;
}
const char *sd_bus_message_get_exe(sd_bus_message *m) {
int sd_bus_message_get_exe(sd_bus_message *m, const char **ret) {
if (!m)
return NULL;
return -EINVAL;
if (!ret)
return -EINVAL;
if (!m->exe)
return -ESRCH;
return m->exe;
*ret = m->exe;
return 0;
}
int sd_bus_message_get_cgroup(sd_bus_message *m, const char **ret) {
if (!m)
return -EINVAL;
if (!ret)
return -EINVAL;
if (!m->cgroup)
return -ESRCH;
*ret = m->cgroup;
return 0;
}
int sd_bus_message_get_cmdline(sd_bus_message *m, char ***cmdline) {
......@@ -3029,6 +3071,8 @@ int bus_message_dump(sd_bus_message *m) {
printf("\ttid_comm=[%s]\n", m->tid_comm);
if (m->label)
printf("\tlabel=[%s]\n", m->label);
if (m->cgroup)
printf("\tcgroup=[%s]\n", m->cgroup);
if (sd_bus_message_get_cmdline(m, &cmdline) >= 0) {
char **c;
......
......@@ -110,10 +110,10 @@ struct sd_bus_message {
const char *exe;
const char *comm;
const char *tid_comm;
const char *cgroup;
const char *cmdline;
size_t cmdline_length;
char **cmdline_array;
};
......
......@@ -136,6 +136,7 @@ static int server(sd_bus *bus) {
while (!client1_gone || !client2_gone) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
pid_t pid = 0;
const char *label = NULL;
r = sd_bus_process(bus, &m);
if (r < 0) {
......@@ -157,7 +158,11 @@ static int server(sd_bus *bus) {
continue;
sd_bus_message_get_pid(m, &pid);
log_info("Got message! member=%s pid=%lu label=%s", strna(sd_bus_message_get_member(m)), (unsigned long) pid, strna(sd_bus_message_get_selinux_context(m)));
sd_bus_message_get_selinux_context(m, &label);
log_info("Got message! member=%s pid=%lu label=%s",
strna(sd_bus_message_get_member(m)),
(unsigned long) pid,
strna(label));
/* bus_message_dump(m); */
/* sd_bus_message_rewind(m, true); */
......
......@@ -130,10 +130,11 @@ int sd_bus_message_get_gid(sd_bus_message *m, gid_t *gid);
int sd_bus_message_get_pid(sd_bus_message *m, pid_t *pid);
int sd_bus_message_get_tid(sd_bus_message *m, pid_t *tid);
int sd_bus_message_get_pid_starttime(sd_bus_message *m, uint64_t *usec);
const char *sd_bus_message_get_selinux_context(sd_bus_message *m);
const char *sd_bus_message_get_comm(sd_bus_message *m);
const char *sd_bus_message_get_tid_comm(sd_bus_message *m);
const char *sd_bus_message_get_exe(sd_bus_message *m);
int sd_bus_message_get_selinux_context(sd_bus_message *m, const char **r);
int sd_bus_message_get_comm(sd_bus_message *m, const char **r);
int sd_bus_message_get_tid_comm(sd_bus_message *m, const char **r);
int sd_bus_message_get_exe(sd_bus_message *m, const char **r);
int sd_bus_message_get_cgroup(sd_bus_message *m, const char **r);
int sd_bus_message_get_cmdline(sd_bus_message *m, char ***cmdline);
int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment