bus-dump.c revision 8752c5752f3b9023f9ce96a55d70c6e5fc31118f
/*-*- 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/>.
***/
#include "bus-dump.h"
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-type.h"
#include "cap-list.h"
#include "capability.h"
#include "fileio.h"
#include "formats-util.h"
#include "locale-util.h"
#include "macro.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
char *p;
unsigned n, i = 0;
n = 0;
level -= 1;
n += 2;
if (!p)
return NULL;
if (flags & BUS_MESSAGE_DUMP_WITH_HEADER) {
p[i++] = ' ';
p[i++] = ' ';
}
p[i + level*8] = 0;
return p;
}
unsigned level = 1;
int r;
assert(m);
if (!f)
f = stdout;
if (flags & BUS_MESSAGE_DUMP_WITH_HEADER) {
fprintf(f,
"%s%s%s Type=%s%s%s Endian=%c Flags=%u Version=%u Priority=%"PRIi64,
m->header->type != SD_BUS_MESSAGE_SIGNAL ? ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), ansi_normal(),
m->priority);
/* Display synthetic message serial number in a more readable
* format than (uint32_t) -1 */
if (BUS_MESSAGE_COOKIE(m) == 0xFFFFFFFFULL)
fprintf(f, " Cookie=-1");
else
if (m->reply_cookie != 0)
fputs("\n", f);
if (m->sender)
if (m->destination)
if (m->path)
if (m->interface)
if (m->member)
fputs("\n", f);
if (sd_bus_error_is_set(&m->error))
fprintf(f,
" ErrorName=%s%s%s"
" ErrorMessage=%s\"%s\"%s\n",
if (m->monotonic != 0)
if (m->realtime != 0)
if (m->seqnum != 0)
fputs("\n", f);
bus_creds_dump(&m->creds, f, true);
}
if (r < 0)
return log_error_errno(r, "Failed to rewind: %m");
if (!(flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY)) {
if (!prefix)
return log_oom();
}
for (;;) {
char type;
union {
double d64;
const char *string;
int i;
} basic;
if (r < 0)
return log_error_errno(r, "Failed to peek type: %m");
if (r == 0) {
if (level <= 1)
break;
r = sd_bus_message_exit_container(m);
if (r < 0)
return log_error_errno(r, "Failed to exit container: %m");
level--;
if (!prefix)
return log_oom();
continue;
}
if (!prefix)
return log_oom();
if (bus_type_is_container(type) > 0) {
if (r < 0)
return log_error_errno(r, "Failed to enter container: %m");
if (type == SD_BUS_TYPE_ARRAY)
else if (type == SD_BUS_TYPE_VARIANT)
else if (type == SD_BUS_TYPE_STRUCT)
else if (type == SD_BUS_TYPE_DICT_ENTRY)
level ++;
continue;
}
if (r < 0)
return log_error_errno(r, "Failed to get basic: %m");
assert(r > 0);
switch (type) {
case SD_BUS_TYPE_BYTE:
break;
case SD_BUS_TYPE_BOOLEAN:
break;
case SD_BUS_TYPE_INT16:
break;
case SD_BUS_TYPE_UINT16:
break;
case SD_BUS_TYPE_INT32:
break;
case SD_BUS_TYPE_UINT32:
break;
case SD_BUS_TYPE_INT64:
break;
case SD_BUS_TYPE_UINT64:
break;
case SD_BUS_TYPE_DOUBLE:
break;
case SD_BUS_TYPE_STRING:
break;
case SD_BUS_TYPE_OBJECT_PATH:
break;
case SD_BUS_TYPE_SIGNATURE:
break;
case SD_BUS_TYPE_UNIX_FD:
break;
default:
assert_not_reached("Unknown basic type.");
}
}
if (!(flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY)) {
if (!prefix)
return log_oom();
}
return 0;
}
static void dump_capabilities(
sd_bus_creds *c,
FILE *f,
const char *name,
bool terse,
unsigned long i, last_cap;
unsigned n = 0;
int r;
assert(c);
assert(f);
i = 0;
r = has(c, i);
if (r < 0)
return;
last_cap = cap_last_cap();
for (;;) {
if (r > 0) {
if (n > 0)
fputc(' ', f);
if (n % 4 == 3)
n++;
}
i++;
if (i > last_cap)
break;
r = has(c, i);
}
fputs("\n", f);
if (!terse)
fputs(ansi_normal(), f);
}
int r, q, v, w, z;
assert(c);
if (!f)
f = stdout;
if (terse) {
prefix = " ";
suffix = "";
color = "";
} else {
const char *off;
prefix = "";
color = ansi_highlight();
off = ansi_normal();
}
if (c->mask & SD_BUS_CREDS_PID)
if (c->mask & SD_BUS_CREDS_TID)
if (c->mask & SD_BUS_CREDS_PPID) {
if (c->ppid == 0)
else
}
if (c->mask & SD_BUS_CREDS_TTY)
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_UID)
if (c->mask & SD_BUS_CREDS_EUID)
if (c->mask & SD_BUS_CREDS_SUID)
if (c->mask & SD_BUS_CREDS_FSUID)
r = sd_bus_creds_get_owner_uid(c, &owner);
if (r >= 0)
if (c->mask & SD_BUS_CREDS_GID)
if (c->mask & SD_BUS_CREDS_EGID)
if (c->mask & SD_BUS_CREDS_SGID)
if (c->mask & SD_BUS_CREDS_FSGID)
if (c->mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
unsigned i;
for (i = 0; i < c->n_supplementary_gids; i++)
}
SD_BUS_CREDS_SUPPLEMENTARY_GIDS)) || r >= 0))
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_COMM)
if (c->mask & SD_BUS_CREDS_TID_COMM)
if (c->mask & SD_BUS_CREDS_EXE)
fputs("\n", f);
r = sd_bus_creds_get_cmdline(c, &cmdline);
if (r >= 0) {
char **i;
STRV_FOREACH(i, cmdline) {
if (i != cmdline)
fputc(' ', f);
fputs(*i, f);
}
} else if (r != -ENODATA)
if (c->mask & SD_BUS_CREDS_SELINUX_CONTEXT)
if (c->mask & SD_BUS_CREDS_DESCRIPTION)
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_CGROUP)
s = NULL;
r = sd_bus_creds_get_unit(c, &s);
if (r != -ENODATA)
s = NULL;
v = sd_bus_creds_get_slice(c, &s);
if (v != -ENODATA)
s = NULL;
q = sd_bus_creds_get_user_unit(c, &s);
if (q != -ENODATA)
s = NULL;
w = sd_bus_creds_get_user_slice(c, &s);
if (w != -ENODATA)
s = NULL;
z = sd_bus_creds_get_session(c, &s);
if (z != -ENODATA)
if (terse && ((c->mask & SD_BUS_CREDS_CGROUP) || r != -ENODATA || q != -ENODATA || v != -ENODATA || w != -ENODATA || z != -ENODATA))
fputs("\n", f);
if (r >= 0)
else if (r != -ENODATA)
if (q >= 0)
else if (q != -ENODATA)
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_UNIQUE_NAME)
if (sd_bus_creds_get_well_known_names(c, &well_known) >= 0) {
char **i;
STRV_FOREACH(i, well_known) {
if (i != well_known)
fputc(' ', f);
fputs(*i, f);
}
}
fputc('\n', f);
return 0;
}
/*
* For details about the file format, see:
*
*/
typedef struct _packed_ pcap_hdr_s {
} pcap_hdr_t ;
typedef struct _packed_ pcaprec_hdr_s {
pcap_hdr_t hdr = {
.magic_number = 0xa1b2c3d4U,
.version_major = 2,
.version_minor = 4,
.thiszone = 0, /* UTC */
.sigfigs = 0,
};
if (!f)
f = stdout;
return fflush_and_check(f);
}
struct bus_body_part *part;
pcaprec_hdr_t hdr = {};
unsigned i;
size_t w;
if (!f)
f = stdout;
assert(m);
if (m->realtime != 0)
else
/* write the pcap header */
/* write the dbus header */
snaplen -= w;
/* write the dbus body */
MESSAGE_FOREACH_PART(part, i, m) {
if (snaplen <= 0)
break;
snaplen -= w;
}
return fflush_and_check(f);
}