Commit acb5a3cb authored by Lennart Poettering's avatar Lennart Poettering

bus: parse and expose kdbus message timestamps

parent 8323bc1f
...@@ -225,6 +225,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess ...@@ -225,6 +225,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
struct bus_header *h = NULL; struct bus_header *h = NULL;
size_t total, n_bytes = 0, idx = 0; size_t total, n_bytes = 0, idx = 0;
struct kdbus_creds *creds = NULL; struct kdbus_creds *creds = NULL;
uint64_t nsec = 0;
int r; int r;
assert(bus); assert(bus);
...@@ -266,6 +267,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess ...@@ -266,6 +267,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
} else if (d->type == KDBUS_MSG_SRC_CREDS) } else if (d->type == KDBUS_MSG_SRC_CREDS)
creds = &d->creds; creds = &d->creds;
else if (d->type == KDBUS_MSG_TIMESTAMP)
nsec = d->ts_ns;
} }
if (!h) if (!h)
...@@ -313,6 +316,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess ...@@ -313,6 +316,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
m->uid_valid = m->gid_valid = true; m->uid_valid = m->gid_valid = true;
} }
m->timestamp = nsec / NSEC_PER_USEC;
r = bus_message_parse_fields(m); r = bus_message_parse_fields(m);
if (r < 0) { if (r < 0) {
sd_bus_message_unref(m); sd_bus_message_unref(m);
......
...@@ -709,6 +709,17 @@ const char *sd_bus_message_get_label(sd_bus_message *m) { ...@@ -709,6 +709,17 @@ const char *sd_bus_message_get_label(sd_bus_message *m) {
return m->label; return m->label;
} }
int sd_bus_message_get_timestamp(sd_bus_message *m, uint64_t *usec) {
if (!m)
return -EINVAL;
if (m->timestamp <= 0)
return -ENOENT;
*usec = m->timestamp;
return 0;
}
int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member) { int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member) {
if (!m) if (!m)
return -EINVAL; return -EINVAL;
...@@ -2922,6 +2933,8 @@ int bus_message_dump(sd_bus_message *m) { ...@@ -2922,6 +2933,8 @@ int bus_message_dump(sd_bus_message *m) {
printf("\tgid=%lu\n", (unsigned long) m->gid); printf("\tgid=%lu\n", (unsigned long) m->gid);
if (m->pid_starttime != 0) if (m->pid_starttime != 0)
printf("\tpid_starttime=%llu\n", (unsigned long long) m->pid_starttime); printf("\tpid_starttime=%llu\n", (unsigned long long) m->pid_starttime);
if (m->timestamp)
printf("\ttimestamp=%llu\n", (unsigned long long) m->timestamp);
r = sd_bus_message_rewind(m, true); r = sd_bus_message_rewind(m, true);
if (r < 0) { if (r < 0) {
......
...@@ -68,6 +68,7 @@ struct sd_bus_message { ...@@ -68,6 +68,7 @@ struct sd_bus_message {
pid_t pid; pid_t pid;
pid_t tid; pid_t tid;
usec_t pid_starttime; usec_t pid_starttime;
usec_t timestamp;
bool sealed:1; bool sealed:1;
bool dont_send:1; bool dont_send:1;
......
...@@ -127,6 +127,7 @@ int sd_bus_message_get_pid(sd_bus_message *m, pid_t *pid); ...@@ -127,6 +127,7 @@ 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_tid(sd_bus_message *m, pid_t *tid);
int sd_bus_message_get_pid_starttime(sd_bus_message *m, uint64_t *usec); int sd_bus_message_get_pid_starttime(sd_bus_message *m, uint64_t *usec);
const char *sd_bus_message_get_label(sd_bus_message *m); const char *sd_bus_message_get_label(sd_bus_message *m);
int sd_bus_message_get_timestamp(sd_bus_message *m, uint64_t *usec);
int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member); int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member);
int sd_bus_message_is_method_call(sd_bus_message *m, const char *interface, const char *member); int sd_bus_message_is_method_call(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