bus-dump.c revision c7fbd99660363b74ccb3c75d280c158518bc78b3
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek This file is part of systemd.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Copyright 2013 Lennart Poettering
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek (at your option) any later version.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekstatic char *indent(unsigned level, unsigned flags) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek unsigned n, i = 0;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY && level > 0)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (flags & BUS_MESSAGE_DUMP_WITH_HEADER)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (flags & BUS_MESSAGE_DUMP_WITH_HEADER) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint bus_message_dump(sd_bus_message *m, FILE *f, unsigned flags) {
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering if (flags & BUS_MESSAGE_DUMP_WITH_HEADER) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek "%s%s%s Type=%s%s%s Endian=%c Flags=%u Version=%u Priority=%lli",
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? ansi_highlight_red() :
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? ansi_highlight_green() :
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering m->header->type != SD_BUS_MESSAGE_SIGNAL ? ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), ansi_highlight_off(),
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering ansi_highlight(), bus_message_type_to_string(m->header->type), ansi_highlight_off(),
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek /* Display synthetic message serial number in a more readable
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek * format than (uint32_t) -1 */
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek if (BUS_MESSAGE_COOKIE(m) == 0xFFFFFFFFULL)
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek fprintf(f, " Cookie=%" PRIu64, BUS_MESSAGE_COOKIE(m));
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek fprintf(f, " ReplyCookie=%" PRIu64, m->reply_cookie);
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek fprintf(f, " Sender=%s%s%s", ansi_highlight(), m->sender, ansi_highlight_off());
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek fprintf(f, " Destination=%s%s%s", ansi_highlight(), m->destination, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, " Path=%s%s%s", ansi_highlight(), m->path, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, " Interface=%s%s%s", ansi_highlight(), m->interface, ansi_highlight_off());
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt fprintf(f, " Member=%s%s%s", ansi_highlight(), m->member, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (m->sender || m->destination || m->path || m->interface || m->member)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (sd_bus_error_is_set(&m->error))
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek " ErrorName=%s%s%s"
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek " ErrorMessage=%s\"%s\"%s\n",
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek ansi_highlight_red(), strna(m->error.name), ansi_highlight_off(),
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek ansi_highlight_red(), strna(m->error.message), ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, " Monotonic="USEC_FMT, m->monotonic);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, " Realtime="USEC_FMT, m->realtime);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, " SequenceNumber=%"PRIu64, m->seqnum);
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering if (m->monotonic != 0 || m->realtime != 0 || m->seqnum != 0)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = sd_bus_message_rewind(m, !(flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY));
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return log_error_errno(r, "Failed to rewind: %m");
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (!(flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY))
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sMESSAGE \"%s\" {\n", indent(0, flags), strempty(m->root_container.signature));
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek _cleanup_free_ char *prefix = NULL;
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek r = sd_bus_message_peek_type(m, &type, &contents);
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer return log_error_errno(r, "Failed to peek type: %m");
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek r = sd_bus_message_exit_container(m);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek return log_error_errno(r, "Failed to exit container: %m");
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (bus_type_is_container(type) > 0) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = sd_bus_message_enter_container(m, type, contents);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return log_error_errno(r, "Failed to enter container: %m");
23ea3dab15181a3966ec45fa2ccbb81e59d2e0a7Zbigniew Jędrzejewski-Szmek fprintf(f, "%sARRAY \"%s\" {\n", prefix, contents);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sVARIANT \"%s\" {\n", prefix, contents);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek else if (type == SD_BUS_TYPE_STRUCT)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sSTRUCT \"%s\" {\n", prefix, contents);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek else if (type == SD_BUS_TYPE_DICT_ENTRY)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sDICT_ENTRY \"%s\" {\n", prefix, contents);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = sd_bus_message_read_basic(m, type, &basic);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return log_error_errno(r, "Failed to get basic: %m");
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sBYTE %s%u%s;\n", prefix, ansi_highlight(), basic.u8, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, ansi_highlight(), true_false(basic.i), ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sINT16 %s%i%s;\n", prefix, ansi_highlight(), basic.s16, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sUINT16 %s%u%s;\n", prefix, ansi_highlight(), basic.u16, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sINT32 %s%i%s;\n", prefix, ansi_highlight(), basic.s32, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sUINT32 %s%u%s;\n", prefix, ansi_highlight(), basic.u32, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sINT64 %s%"PRIi64"%s;\n", prefix, ansi_highlight(), basic.s64, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sUINT64 %s%"PRIu64"%s;\n", prefix, ansi_highlight(), basic.u64, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sDOUBLE %s%g%s;\n", prefix, ansi_highlight(), basic.d64, ansi_highlight_off());
aa44499da15a8fa7026463555a7a27e55e4e24a8Philippe De Swert fprintf(f, "%sSTRING \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sOBJECT_PATH \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off());
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering fprintf(f, "%sSIGNATURE \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off());
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering fprintf(f, "%sUNIX_FD %s%i%s;\n", prefix, ansi_highlight(), basic.i, ansi_highlight_off());
e9c1ea9de87d4d508ac38ce87a2fa56e7529a91aJason St. John if (!(flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY))
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek int (*has)(sd_bus_creds *c, int capability)) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek unsigned long i, last_cap;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%s%s=%s", terse ? " " : "", name, terse ? "" : ansi_highlight());
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, terse ? "\n " : "\n ");
892213bf1fd23e48d64a407ece6e10b07bef1926Zbigniew Jędrzejewski-Szmek fprintf(f, "%s", strna(capability_to_name(i)));
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint bus_creds_dump(sd_bus_creds *c, FILE *f, bool terse) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek bool audit_sessionid_is_set = false, audit_loginuid_is_set = false;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek const char *u = NULL, *uu = NULL, *s = NULL, *sl = NULL;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek char **cmdline = NULL, **well_known = NULL;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek const char *prefix, *color, *suffix;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sPID=%s"PID_FMT"%s", prefix, color, c->pid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sTID=%s"PID_FMT"%s", prefix, color, c->tid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (terse && ((c->mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_TID))))
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sUID=%s"UID_FMT"%s", prefix, color, c->uid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_EUID)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sEUID=%s"UID_FMT"%s", prefix, color, c->euid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_SUID)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sSUID=%s"UID_FMT"%s", prefix, color, c->suid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_FSUID)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sFSUID=%s"UID_FMT"%s", prefix, color, c->fsuid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = sd_bus_creds_get_owner_uid(c, &owner);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sOwnerUID=%s"UID_FMT"%s", prefix, color, owner, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sGID=%s"GID_FMT"%s", prefix, color, c->gid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sEGID=%s"GID_FMT"%s", prefix, color, c->egid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_SGID)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sSGID=%s"GID_FMT"%s", prefix, color, c->sgid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_FSGID)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sFSGID=%s"GID_FMT"%s", prefix, color, c->fsgid, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sSupplementaryGIDs=%s", prefix, color);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek for (i = 0; i < c->n_supplementary_gids; i++)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%s" GID_FMT, i > 0 ? " " : "", c->supplementary_gids[i]);
2c408cb6276e3b8d18fb4e2a81a1128d8bbaa70dLennart Poettering if (terse && ((c->mask & (SD_BUS_CREDS_UID|SD_BUS_CREDS_EUID|SD_BUS_CREDS_SUID|SD_BUS_CREDS_FSUID|
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek SD_BUS_CREDS_GID|SD_BUS_CREDS_EGID|SD_BUS_CREDS_SGID|SD_BUS_CREDS_FSGID|
eceb8483e5a02e8e337486b89719a3b99cfcb7ceLennart Poettering SD_BUS_CREDS_SUPPLEMENTARY_GIDS)) || r >= 0))
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_COMM)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sComm=%s%s%s", prefix, color, c->comm, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (c->mask & SD_BUS_CREDS_TID_COMM)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sTIDComm=%s%s%s", prefix, color, c->tid_comm, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sExe=%s%s%s", prefix, color, c->exe, suffix);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (terse && (c->mask & (SD_BUS_CREDS_EXE|SD_BUS_CREDS_COMM|SD_BUS_CREDS_TID_COMM)))
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (sd_bus_creds_get_cmdline(c, &cmdline) >= 0) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek fprintf(f, "%sCommandLine=%s", prefix, color);
(void) sd_bus_creds_get_unit(c, &u);
if (uu)
if (sl)
(void) sd_bus_creds_get_session(c, &s);
audit_loginuid_is_set = true;
audit_sessionid_is_set = true;
if (i != well_known)
fputs(*i, f);
} pcap_hdr_t ;
.sigfigs = 0,
f = stdout;
fflush(f);
size_t w;
f = stdout;
assert(m);
if (m->realtime != 0)
snaplen -= w;
if (snaplen <= 0)
snaplen -= w;
fflush(f);