summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-12 00:12:08 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-12 00:12:44 +0100
commit2b5c5383e48137d748681645ad7176f02b50ba30 (patch)
treebea52c637dc4dd99e5420b0a081c1a717f944016 /src/libsystemd-bus
parent7b0b392f7bce4bb1b17fec54d1baf27daa85777f (diff)
bus: beautify bus_message_dump() output a bit
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/bus-message.c266
-rw-r--r--src/libsystemd-bus/bus-message.h1
-rw-r--r--src/libsystemd-bus/busctl.c1
-rw-r--r--src/libsystemd-bus/test-bus-kernel.c1
-rw-r--r--src/libsystemd-bus/test-bus-marshal.c1
-rw-r--r--src/libsystemd-bus/test-bus-zero-copy.c1
6 files changed, 4 insertions, 267 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index d7774db09a..4f21db56e2 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -4205,272 +4205,6 @@ _public_ int sd_bus_message_set_destination(sd_bus_message *m, const char *desti
return message_append_field_string(m, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination);
}
-int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
- const char *u = NULL, *uu = NULL, *s = NULL;
- char **cmdline = NULL;
- unsigned level = 1;
- int r;
- uid_t owner, audit_loginuid;
- uint32_t audit_sessionid;
-
- assert(m);
-
- if (!f)
- f = stdout;
-
- if (with_header) {
- fprintf(f,
- "Message %p\n"
- "\tn_ref=%u\n"
- "\tendian=%c\n"
- "\ttype=%i\n"
- "\tflags=%u\n"
- "\tversion=%u\n"
- "\tserial=%u\n"
- "\tfields_size=%u\n"
- "\tbody_size=%u\n"
- "\tpath=%s\n"
- "\tinterface=%s\n"
- "\tmember=%s\n"
- "\tdestination=%s\n"
- "\tsender=%s\n"
- "\tsignature=%s\n"
- "\treply_serial=%u\n"
- "\tsealed=%s\n"
- "\tn_body_parts=%u\n",
- m,
- m->n_ref,
- m->header->endian,
- m->header->type,
- m->header->flags,
- m->header->version,
- BUS_MESSAGE_SERIAL(m),
- BUS_MESSAGE_FIELDS_SIZE(m),
- BUS_MESSAGE_BODY_SIZE(m),
- strna(m->path),
- strna(m->interface),
- strna(m->member),
- strna(m->destination),
- strna(m->sender),
- strna(m->root_container.signature),
- m->reply_serial,
- yes_no(m->sealed),
- m->n_body_parts);
-
- if (sd_bus_error_is_set(&m->error))
- fprintf(f,
- "\terror.name=%s\n"
- "\terror.message=%s\n",
- strna(m->error.name),
- strna(m->error.message));
-
- if (m->pid != 0)
- fprintf(f, "\tpid=%lu\n", (unsigned long) m->pid);
- if (m->tid != 0)
- fprintf(f, "\ttid=%lu\n", (unsigned long) m->tid);
- if (m->uid_valid)
- fprintf(f, "\tuid=%lu\n", (unsigned long) m->uid);
- if (m->gid_valid)
- fprintf(f, "\tgid=%lu\n", (unsigned long) m->gid);
- if (m->pid_starttime != 0)
- fprintf(f, "\tpid_starttime=%llu\n", (unsigned long long) m->pid_starttime);
- if (m->monotonic != 0)
- fprintf(f, "\tmonotonic=%llu\n", (unsigned long long) m->monotonic);
- if (m->realtime != 0)
- fprintf(f, "\trealtime=%llu\n", (unsigned long long) m->realtime);
- if (m->exe)
- fprintf(f, "\texe=[%s]\n", m->exe);
- if (m->comm)
- fprintf(f, "\tcomm=[%s]\n", m->comm);
- if (m->tid_comm)
- fprintf(f, "\ttid_comm=[%s]\n", m->tid_comm);
- if (m->label)
- fprintf(f, "\tlabel=[%s]\n", m->label);
- if (m->cgroup)
- fprintf(f, "\tcgroup=[%s]\n", m->cgroup);
-
- sd_bus_message_get_unit(m, &u);
- if (u)
- fprintf(f, "\tunit=[%s]\n", u);
- sd_bus_message_get_user_unit(m, &uu);
- if (uu)
- fprintf(f, "\tuser_unit=[%s]\n", uu);
- sd_bus_message_get_session(m, &s);
- if (s)
- fprintf(f, "\tsession=[%s]\n", s);
- if (sd_bus_message_get_owner_uid(m, &owner) >= 0)
- fprintf(f, "\towner_uid=%lu\n", (unsigned long) owner);
- if (sd_bus_message_get_audit_loginuid(m, &audit_loginuid) >= 0)
- fprintf(f, "\taudit_loginuid=%lu\n", (unsigned long) audit_loginuid);
- if (sd_bus_message_get_audit_sessionid(m, &audit_sessionid) >= 0)
- fprintf(f, "\taudit_sessionid=%lu\n", (unsigned long) audit_sessionid);
-
- r = sd_bus_message_has_effective_cap(m, 5);
- if (r >= 0)
- fprintf(f, "\tCAP_KILL=%s\n", yes_no(r));
-
- if (sd_bus_message_get_cmdline(m, &cmdline) >= 0) {
- char **c;
-
- fputs("\tcmdline=[", f);
- STRV_FOREACH(c, cmdline) {
- if (c != cmdline)
- fputc(' ', f);
-
- fputs(*c, f);
- }
-
- fputs("]\n", f);
- }
- }
-
- r = sd_bus_message_rewind(m, true);
- if (r < 0) {
- log_error("Failed to rewind: %s", strerror(-r));
- return r;
- }
-
- fprintf(f, "MESSAGE \"%s\" {\n", strempty(m->root_container.signature));
-
- for(;;) {
- _cleanup_free_ char *prefix = NULL;
- const char *contents = NULL;
- char type;
- union {
- uint8_t u8;
- uint16_t u16;
- int16_t s16;
- uint32_t u32;
- int32_t s32;
- uint64_t u64;
- int64_t s64;
- double d64;
- const char *string;
- int i;
- } basic;
-
- r = sd_bus_message_peek_type(m, &type, &contents);
- if (r < 0) {
- log_error("Failed to peek type: %s", strerror(-r));
- return r;
- }
-
- if (r == 0) {
- if (level <= 1)
- break;
-
- r = sd_bus_message_exit_container(m);
- if (r < 0) {
- log_error("Failed to exit container: %s", strerror(-r));
- return r;
- }
-
- level--;
-
- prefix = strrep("\t", level);
- if (!prefix)
- return log_oom();
-
- fprintf(f, "%s};\n", prefix);
- continue;
- }
-
- prefix = strrep("\t", level);
- if (!prefix)
- return log_oom();
-
- if (bus_type_is_container(type) > 0) {
- r = sd_bus_message_enter_container(m, type, contents);
- if (r < 0) {
- log_error("Failed to enter container: %s", strerror(-r));
- return r;
- }
-
- if (type == SD_BUS_TYPE_ARRAY)
- fprintf(f, "%sARRAY \"%s\" {\n", prefix, contents);
- else if (type == SD_BUS_TYPE_VARIANT)
- fprintf(f, "%sVARIANT \"%s\" {\n", prefix, contents);
- else if (type == SD_BUS_TYPE_STRUCT)
- fprintf(f, "%sSTRUCT \"%s\" {\n", prefix, contents);
- else if (type == SD_BUS_TYPE_DICT_ENTRY)
- fprintf(f, "%sDICT_ENTRY \"%s\" {\n", prefix, contents);
-
- level ++;
-
- continue;
- }
-
- r = sd_bus_message_read_basic(m, type, &basic);
- if (r < 0) {
- log_error("Failed to get basic: %s", strerror(-r));
- return r;
- }
-
- assert(r > 0);
-
- switch (type) {
-
- case SD_BUS_TYPE_BYTE:
- fprintf(f, "%sBYTE %u;\n", prefix, basic.u8);
- break;
-
- case SD_BUS_TYPE_BOOLEAN:
- fprintf(f, "%sBOOLEAN %s;\n", prefix, yes_no(basic.i));
- break;
-
- case SD_BUS_TYPE_INT16:
- fprintf(f, "%sINT16 %i;\n", prefix, basic.s16);
- break;
-
- case SD_BUS_TYPE_UINT16:
- fprintf(f, "%sUINT16 %u;\n", prefix, basic.u16);
- break;
-
- case SD_BUS_TYPE_INT32:
- fprintf(f, "%sINT32 %i;\n", prefix, basic.s32);
- break;
-
- case SD_BUS_TYPE_UINT32:
- fprintf(f, "%sUINT32 %u;\n", prefix, basic.u32);
- break;
-
- case SD_BUS_TYPE_INT64:
- fprintf(f, "%sINT64 %lli;\n", prefix, (long long) basic.s64);
- break;
-
- case SD_BUS_TYPE_UINT64:
- fprintf(f, "%sUINT64 %llu;\n", prefix, (unsigned long long) basic.u64);
- break;
-
- case SD_BUS_TYPE_DOUBLE:
- fprintf(f, "%sDOUBLE %g;\n", prefix, basic.d64);
- break;
-
- case SD_BUS_TYPE_STRING:
- fprintf(f, "%sSTRING \"%s\";\n", prefix, basic.string);
- break;
-
- case SD_BUS_TYPE_OBJECT_PATH:
- fprintf(f, "%sOBJECT_PATH \"%s\";\n", prefix, basic.string);
- break;
-
- case SD_BUS_TYPE_SIGNATURE:
- fprintf(f, "%sSIGNATURE \"%s\";\n", prefix, basic.string);
- break;
-
- case SD_BUS_TYPE_UNIX_FD:
- fprintf(f, "%sUNIX_FD %i;\n", prefix, basic.i);
- break;
-
- default:
- assert_not_reached("Unknown basic type.");
- }
- }
-
- fprintf(f, "};\n");
- return 0;
-}
-
int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
size_t total;
void *p, *e;
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index d0f11d8f64..aec6f75857 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -190,7 +190,6 @@ static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) {
}
int bus_message_seal(sd_bus_message *m, uint64_t serial);
-int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header);
int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
int bus_message_read_strv_extend(sd_bus_message *m, char ***l);
diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c
index d5ac2fe0f2..b9b3305e93 100644
--- a/src/libsystemd-bus/busctl.c
+++ b/src/libsystemd-bus/busctl.c
@@ -31,6 +31,7 @@
#include "bus-message.h"
#include "bus-internal.h"
#include "bus-util.h"
+#include "bus-dump.h"
static bool arg_no_pager = false;
static char *arg_address = NULL;
diff --git a/src/libsystemd-bus/test-bus-kernel.c b/src/libsystemd-bus/test-bus-kernel.c
index e498801210..511c547852 100644
--- a/src/libsystemd-bus/test-bus-kernel.c
+++ b/src/libsystemd-bus/test-bus-kernel.c
@@ -29,6 +29,7 @@
#include "bus-error.h"
#include "bus-kernel.h"
#include "bus-util.h"
+#include "bus-dump.h"
int main(int argc, char *argv[]) {
_cleanup_close_ int bus_ref = -1;
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index 8f36a71d4b..cbf5e1a0fa 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -37,6 +37,7 @@
#include "sd-bus.h"
#include "bus-message.h"
#include "bus-util.h"
+#include "bus-dump.h"
int main(int argc, char *argv[]) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL, *copy = NULL;
diff --git a/src/libsystemd-bus/test-bus-zero-copy.c b/src/libsystemd-bus/test-bus-zero-copy.c
index 0c07a33735..032449a5d8 100644
--- a/src/libsystemd-bus/test-bus-zero-copy.c
+++ b/src/libsystemd-bus/test-bus-zero-copy.c
@@ -30,6 +30,7 @@
#include "bus-message.h"
#include "bus-error.h"
#include "bus-kernel.h"
+#include "bus-dump.h"
#define FIRST_ARRAY 17
#define SECOND_ARRAY 33