busctl.c revision 3ffd4af22052963e7a29431721ee204e634bea75
/*-*- 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 <getopt.h>
#include "sd-bus.h"
#include "bus-dump.h"
#include "bus-internal.h"
#include "bus-signature.h"
#include "bus-type.h"
#include "bus-util.h"
#include "busctl-introspect.h"
#include "escape.h"
#include "fd-util.h"
#include "log.h"
#include "pager.h"
#include "path-util.h"
#include "set.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
static bool arg_no_pager = false;
static bool arg_legend = true;
static char *arg_address = NULL;
static bool arg_unique = false;
static bool arg_acquired = false;
static bool arg_activatable = false;
static bool arg_show_machine = false;
static char **arg_matches = NULL;
static bool arg_user = false;
static bool arg_list = false;
static bool arg_quiet = false;
static bool arg_verbose = false;
static bool arg_expect_reply = true;
static bool arg_auto_start = true;
static bool arg_allow_interactive_authorization = true;
static bool arg_augment_creds = true;
static usec_t arg_timeout = 0;
static void pager_open_if_enabled(void) {
/* Cache result before we open the pager */
if (arg_no_pager)
return;
pager_open(false);
}
char **i;
int r;
unsigned n = 0;
void *v;
char *k;
r = sd_bus_list_names(bus, (arg_acquired || arg_unique) ? &acquired : NULL, arg_activatable ? &activatable : NULL);
if (r < 0)
return log_error_errno(r, "Failed to list names: %m");
if (!names)
return log_oom();
STRV_FOREACH(i, acquired) {
if (r < 0)
return log_error_errno(r, "Failed to add to hashmap: %m");
}
STRV_FOREACH(i, activatable) {
if (r < 0 && r != -EEXIST)
return log_error_errno(r, "Failed to add to hashmap: %m");
}
merged[n++] = k;
if (arg_legend) {
printf("%-*s %*s %-*s %-*s %-*s %-*s %-*s %-*s",
(int) max_i, "NAME", 10, "PID", 15, "PROCESS", 16, "USER", 13, "CONNECTION", 25, "UNIT", 10, "SESSION", 19, "DESCRIPTION");
if (arg_show_machine)
puts(" MACHINE");
else
putchar('\n');
}
STRV_FOREACH(i, merged) {
/* Activatable */
printf(" - - - (activatable) - - ");
if (arg_show_machine)
puts(" -");
else
putchar('\n');
continue;
}
if (!arg_unique && (*i)[0] == ':')
continue;
if (!arg_acquired && (*i)[0] != ':')
continue;
bus, *i,
(arg_augment_creds ? SD_BUS_CREDS_AUGMENT : 0) |
if (r >= 0) {
if (r >= 0) {
} else
if (r >= 0) {
_cleanup_free_ char *u = NULL;
u = uid_to_name(uid);
if (!u)
return log_oom();
if (strlen(u) > 16)
u[16] = 0;
printf(" %-16s", u);
} else
if (r >= 0)
else
if (r >= 0) {
_cleanup_free_ char *e;
if (!e)
return log_oom();
printf(" %-25s", e);
} else
if (r >= 0)
else
if (r >= 0)
else
} else
printf(" - - - - - - - ");
if (arg_show_machine) {
if (r >= 0) {
char m[SD_ID128_STRING_MAX];
} else
puts(" -");
} else
putchar('\n');
}
return 0;
}
char **n;
/* We assume the list is sorted. Let's first skip over the
* entry we are looking at. */
for (;;) {
if (!*l)
return;
break;
l++;
}
for (;;) {
bool has_more = false;
if (!*l || !path_startswith(*l, path))
break;
n = l + 1;
for (;;) {
if (!*n || !path_startswith(*n, path))
break;
if (!path_startswith(*n, *l)) {
has_more = true;
break;
}
n++;
}
l = n;
}
}
static void print_tree(const char *prefix, char **l) {
if (arg_list) {
char **i;
STRV_FOREACH(i, l)
return;
}
if (strv_isempty(l)) {
printf("No objects discovered.\n");
return;
}
printf("Only root object discovered.\n");
return;
}
}
int r;
if (r < 0)
return log_oom();
return 0;
}
static const XMLIntrospectOps ops = {
};
const char *xml;
int r;
r = sd_bus_call_method(bus, service, path, "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
if (r < 0) {
if (many)
printf("Failed to introspect object %s of service %s: %s\n", path, service, bus_error_message(&error, r));
else
log_error("Failed to introspect object %s of service %s: %s", path, service, bus_error_message(&error, r));
return r;
}
if (r < 0)
return bus_log_parse_error(r);
}
_cleanup_free_ char **l = NULL;
char *m;
int r;
if (!paths)
return log_oom();
if (!done)
return log_oom();
if (!failed)
return log_oom();
m = strdup("/");
if (!m)
return log_oom();
if (r < 0) {
free(m);
return log_oom();
}
for (;;) {
_cleanup_free_ char *p = NULL;
int q;
p = set_steal_first(paths);
if (!p)
break;
if (set_contains(done, p) ||
set_contains(failed, p))
continue;
if (q < 0) {
if (r >= 0)
r = q;
} else
if (q < 0)
return log_oom();
assert(q != 0);
p = NULL;
}
l = set_get_strv(done);
if (!l)
return log_oom();
strv_sort(l);
print_tree(prefix, l);
return r;
}
char **i;
int r = 0;
if (!arg_unique && !arg_acquired)
arg_acquired = true;
bool not_first = false;
if (r < 0)
return log_error_errno(r, "Failed to get name list: %m");
STRV_FOREACH(i, names) {
int q;
if (!arg_unique && (*i)[0] == ':')
continue;
if (!arg_acquired && (*i)[0] == ':')
continue;
if (not_first)
printf("\n");
if (q < 0 && r >= 0)
r = q;
not_first = true;
}
} else {
int q;
if (i > argv+1)
printf("\n");
if (argv[2]) {
}
if (q < 0 && r >= 0)
r = q;
}
}
return r;
}
int r;
for (;;) {
char type;
union {
double d64;
const char *string;
int i;
} basic;
if (r <= 0)
return r;
if (bus_type_is_container(type) > 0) {
if (r < 0)
return r;
if (type == SD_BUS_TYPE_ARRAY) {
unsigned n = 0;
/* count array entries */
for (;;) {
r = sd_bus_message_skip(m, contents);
if (r < 0)
return r;
if (r == 0)
break;
n++;
}
r = sd_bus_message_rewind(m, false);
if (r < 0)
return r;
if (needs_space)
fputc(' ', f);
fprintf(f, "%u", n);
} else if (type == SD_BUS_TYPE_VARIANT) {
if (needs_space)
fputc(' ', f);
}
if (r < 0)
return r;
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
continue;
}
if (r < 0)
return r;
if (needs_space)
fputc(' ', f);
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:
case SD_BUS_TYPE_OBJECT_PATH:
case SD_BUS_TYPE_SIGNATURE: {
_cleanup_free_ char *b = NULL;
if (!b)
return -ENOMEM;
fprintf(f, "\"%s\"", b);
break;
}
case SD_BUS_TYPE_UNIX_FD:
break;
default:
assert_not_reached("Unknown basic type.");
}
needs_space = true;
}
}
typedef struct Member {
const char *type;
char *interface;
char *name;
char *signature;
char *result;
char *value;
bool writable;
} Member;
const Member *m = p;
assert(m);
if (m->name)
if (m->interface)
}
static int member_compare_func(const void *a, const void *b) {
const Member *x = a, *y = b;
int d;
assert(x);
assert(y);
if (d != 0)
return d;
if (d != 0)
return d;
}
static int member_compare_funcp(const void *a, const void *b) {
return member_compare_func(*x, *y);
}
static void member_free(Member *m) {
if (!m)
return;
free(m);
}
static void member_set_free(Set *s) {
Member *m;
while ((m = set_steal_first(s)))
member_free(m);
set_free(s);
}
int r;
if (!m)
return log_oom();
m->type = "interface";
if (r < 0)
return log_oom();
if (r <= 0) {
log_error("Duplicate interface");
return -EINVAL;
}
m = NULL;
return 0;
}
static int on_method(const char *interface, const char *name, const char *signature, const char *result, uint64_t flags, void *userdata) {
int r;
if (!m)
return log_oom();
m->type = "method";
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
if (r <= 0) {
log_error("Duplicate method");
return -EINVAL;
}
m = NULL;
return 0;
}
static int on_signal(const char *interface, const char *name, const char *signature, uint64_t flags, void *userdata) {
int r;
if (!m)
return log_oom();
m->type = "signal";
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
if (r <= 0) {
log_error("Duplicate signal");
return -EINVAL;
}
m = NULL;
return 0;
}
static int on_property(const char *interface, const char *name, const char *signature, bool writable, uint64_t flags, void *userdata) {
int r;
if (!m)
return log_oom();
m->type = "property";
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
if (r <= 0) {
log_error("Duplicate property");
return -EINVAL;
}
m = NULL;
return 0;
}
static const char *strdash(const char *x) {
return isempty(x) ? "-" : x;
}
static const struct hash_ops member_hash_ops = {
.hash = member_hash_func,
};
static const XMLIntrospectOps ops = {
};
Iterator i;
Member *m;
const char *xml;
int r;
unsigned k = 0, j, n_args;
if (n_args < 3) {
log_error("Requires service and object path argument.");
return -EINVAL;
}
if (n_args > 4) {
log_error("Too many arguments.");
return -EINVAL;
}
if (!members)
return log_oom();
r = sd_bus_call_method(bus, argv[1], argv[2], "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
if (r < 0) {
log_error("Failed to introspect object %s of service %s: %s", argv[2], argv[1], bus_error_message(&error, r));
return r;
}
if (r < 0)
return bus_log_parse_error(r);
/* First, get list of all properties */
if (r < 0)
return r;
/* Second, find the current values for them */
SET_FOREACH(m, members, i) {
continue;
if (m->value)
continue;
continue;
r = sd_bus_call_method(bus, argv[1], argv[2], "org.freedesktop.DBus.Properties", "GetAll", &error, &reply, "s", m->interface);
if (r < 0) {
return r;
}
if (r < 0)
return bus_log_parse_error(r);
for (;;) {
Member *z;
const char *name;
if (r < 0)
return bus_log_parse_error(r);
if (r == 0)
break;
if (r < 0)
return bus_log_parse_error(r);
if (r < 0)
return bus_log_parse_error(r);
if (!mf)
return log_oom();
if (r < 0)
return bus_log_parse_error(r);
.type = "property",
if (z) {
}
if (r < 0)
return bus_log_parse_error(r);
if (r < 0)
return bus_log_parse_error(r);
}
if (r < 0)
return bus_log_parse_error(r);
}
SET_FOREACH(m, members, i) {
continue;
if (m->interface)
if (m->name)
if (m->type)
if (m->signature)
if (m->result)
if (m->value)
sorted[k++] = m;
}
if (result_width > 40)
result_width = 40;
if (arg_legend) {
printf("%-*s %-*s %-*s %-*s %s\n",
(int) name_width, "NAME",
(int) type_width, "TYPE",
(int) signature_width, "SIGNATURE",
(int) result_width, "RESULT/VALUE",
"FLAGS");
}
for (j = 0; j < k; j++) {
const char *rv;
bool is_interface;
m = sorted[j];
continue;
continue;
if (m->value) {
if (!ellipsized)
return log_oom();
rv = ellipsized;
} else
printf("%s%s%-*s%s %-*s %-*s %-*s%s%s%s%s%s%s\n",
- !is_interface + (int) name_width, strdash(streq_ptr(m->type, "interface") ? m->interface : m->name),
(int) result_width, rv,
}
return 0;
}
return bus_message_dump(m, f, BUS_MESSAGE_DUMP_WITH_HEADER);
}
return bus_message_pcap_frame(m, arg_snaplen, f);
}
bool added_something = false;
char **i;
int r;
_cleanup_free_ char *m = NULL;
if (!service_name_is_valid(*i)) {
log_error("Invalid service name '%s'", *i);
return -EINVAL;
}
if (!m)
return log_oom();
if (r < 0)
return log_error_errno(r, "Failed to add match: %m");
free(m);
if (!m)
return log_oom();
if (r < 0)
return log_error_errno(r, "Failed to add match: %m");
added_something = true;
}
STRV_FOREACH(i, arg_matches) {
if (r < 0)
return log_error_errno(r, "Failed to add match: %m");
added_something = true;
}
if (!added_something) {
if (r < 0)
return log_error_errno(r, "Failed to add match: %m");
}
log_info("Monitoring bus message stream.");
for (;;) {
r = sd_bus_process(bus, &m);
if (r < 0)
return log_error_errno(r, "Failed to process bus: %m");
if (m) {
log_info("Connection terminated, exiting.");
return 0;
}
continue;
}
if (r > 0)
continue;
if (r < 0)
return log_error_errno(r, "Failed to wait for bus: %m");
}
}
int r;
log_error("Refusing to write message data to console, please redirect output to a file.");
return -EINVAL;
}
if (r < 0)
return r;
log_error("Couldn't write capture file.");
return -EIO;
}
return r;
}
int r;
log_error("Expects no or one argument.");
return -EINVAL;
}
if (argv[1]) {
if (r < 0)
bus,
argv[1],
&creds);
else
&creds,
pid,
} else {
if (r >= 0)
if (r >= 0)
if (r >= 0)
printf("BusID=%s" SD_ID128_FORMAT_STR "%s\n", ansi_highlight(), SD_ID128_FORMAT_VAL(bus_id), ansi_normal());
bus,
&creds);
}
if (r < 0)
return log_error_errno(r, "Failed to get credentials: %m");
return 0;
}
char **p;
int r;
assert(m);
assert(x);
p = *x;
for (;;) {
const char *v;
char t;
t = *signature;
v = *p;
if (t == 0)
break;
if (!v) {
log_error("Too few parameters for signature.");
return -EINVAL;
}
signature++;
p++;
switch (t) {
case SD_BUS_TYPE_BOOLEAN:
r = parse_boolean(v);
if (r < 0) {
log_error("Failed to parse as boolean: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &r);
break;
case SD_BUS_TYPE_BYTE: {
uint8_t z;
r = safe_atou8(v, &z);
if (r < 0) {
log_error("Failed to parse as byte (unsigned 8bit integer): %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_INT16: {
int16_t z;
r = safe_atoi16(v, &z);
if (r < 0) {
log_error("Failed to parse as signed 16bit integer: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_UINT16: {
uint16_t z;
r = safe_atou16(v, &z);
if (r < 0) {
log_error("Failed to parse as unsigned 16bit integer: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_INT32: {
int32_t z;
r = safe_atoi32(v, &z);
if (r < 0) {
log_error("Failed to parse as signed 32bit integer: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_UINT32: {
uint32_t z;
r = safe_atou32(v, &z);
if (r < 0) {
log_error("Failed to parse as unsigned 32bit integer: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_INT64: {
int64_t z;
r = safe_atoi64(v, &z);
if (r < 0) {
log_error("Failed to parse as signed 64bit integer: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_UINT64: {
uint64_t z;
r = safe_atou64(v, &z);
if (r < 0) {
log_error("Failed to parse as unsigned 64bit integer: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_DOUBLE: {
double z;
r = safe_atod(v, &z);
if (r < 0) {
log_error("Failed to parse as double precision floating point: %s", v);
return r;
}
r = sd_bus_message_append_basic(m, t, &z);
break;
}
case SD_BUS_TYPE_STRING:
case SD_BUS_TYPE_OBJECT_PATH:
case SD_BUS_TYPE_SIGNATURE:
r = sd_bus_message_append_basic(m, t, v);
break;
case SD_BUS_TYPE_ARRAY: {
uint32_t n;
size_t k;
r = safe_atou32(v, &n);
if (r < 0) {
log_error("Failed to parse number of array entries: %s", v);
return r;
}
r = signature_element_length(signature, &k);
if (r < 0) {
log_error("Invalid array signature.");
return r;
}
{
unsigned i;
char s[k + 1];
s[k] = 0;
r = sd_bus_message_open_container(m, SD_BUS_TYPE_ARRAY, s);
if (r < 0)
return bus_log_create_error(r);
for (i = 0; i < n; i++) {
r = message_append_cmdline(m, s, &p);
if (r < 0)
return r;
}
}
signature += k;
r = sd_bus_message_close_container(m);
break;
}
case SD_BUS_TYPE_VARIANT:
r = sd_bus_message_open_container(m, SD_BUS_TYPE_VARIANT, v);
if (r < 0)
return bus_log_create_error(r);
r = message_append_cmdline(m, v, &p);
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
break;
case SD_BUS_TYPE_STRUCT_BEGIN:
case SD_BUS_TYPE_DICT_ENTRY_BEGIN: {
size_t k;
signature--;
p--;
r = signature_element_length(signature, &k);
if (r < 0) {
return r;
}
{
char s[k-1];
s[k - 2] = 0;
r = sd_bus_message_open_container(m, t == SD_BUS_TYPE_STRUCT_BEGIN ? SD_BUS_TYPE_STRUCT : SD_BUS_TYPE_DICT_ENTRY, s);
if (r < 0)
return bus_log_create_error(r);
r = message_append_cmdline(m, s, &p);
if (r < 0)
return r;
}
signature += k;
r = sd_bus_message_close_container(m);
break;
}
case SD_BUS_TYPE_UNIX_FD:
log_error("UNIX file descriptor not supported as type.");
return -EINVAL;
default:
log_error("Unknown signature type %c.", t);
return -EINVAL;
}
if (r < 0)
return bus_log_create_error(r);
}
*x = p;
return 0;
}
int r;
log_error("Expects at least four arguments.");
return -EINVAL;
}
if (r < 0)
return bus_log_create_error(r);
if (r < 0)
return bus_log_create_error(r);
if (r < 0)
return bus_log_create_error(r);
if (r < 0)
return bus_log_create_error(r);
char **p;
p = argv+6;
if (r < 0)
return r;
if (*p) {
log_error("Too many parameters for signature.");
return -EINVAL;
}
}
if (!arg_expect_reply) {
if (r < 0) {
log_error("Failed to send message.");
return r;
}
return 0;
}
if (r < 0) {
return r;
}
r = sd_bus_message_is_empty(reply);
if (r < 0)
return bus_log_parse_error(r);
if (r == 0 && !arg_quiet) {
if (arg_verbose) {
if (r < 0)
return r;
} else {
if (r < 0)
return bus_log_parse_error(r);
}
}
return 0;
}
unsigned n;
char **i;
int r;
n = strv_length(argv);
if (n < 5) {
log_error("Expects at least four arguments.");
return -EINVAL;
}
char type;
r = sd_bus_call_method(bus, argv[1], argv[2], "org.freedesktop.DBus.Properties", "Get", &error, &reply, "ss", argv[3], *i);
if (r < 0) {
return r;
}
if (r < 0)
return bus_log_parse_error(r);
if (r < 0)
return bus_log_parse_error(r);
if (arg_verbose) {
if (r < 0)
return r;
} else {
if (r < 0)
return bus_log_parse_error(r);
}
if (r < 0)
return bus_log_parse_error(r);
}
return 0;
}
unsigned n;
char **p;
int r;
n = strv_length(argv);
if (n < 6) {
log_error("Expects at least five arguments.");
return -EINVAL;
}
r = sd_bus_message_new_method_call(bus, &m, argv[1], argv[2], "org.freedesktop.DBus.Properties", "Set");
if (r < 0)
return bus_log_create_error(r);
if (r < 0)
return bus_log_create_error(r);
if (r < 0)
return bus_log_create_error(r);
p = argv+6;
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return bus_log_create_error(r);
if (*p) {
log_error("Too many parameters for signature.");
return -EINVAL;
}
if (r < 0) {
return r;
}
return 0;
}
static int help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Introspect the bus.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n"
" --no-legend Do not show the headers and footers\n"
" --system Connect to system bus\n"
" --user Connect to user bus\n"
" -H --host=[USER@]HOST Operate on remote host\n"
" -M --machine=CONTAINER Operate on local container\n"
" --address=ADDRESS Connect to bus specified by address\n"
" --show-machine Show machine ID column in list\n"
" --unique Only show unique names\n"
" --acquired Only show acquired names\n"
" --activatable Only show activatable names\n"
" --match=MATCH Only show matching messages\n"
" --size=SIZE Maximum length of captured packet\n"
" --list Don't show tree, but simple object path list\n"
" --quiet Don't show method call reply\n"
" --verbose Show result values in long format\n"
" --expect-reply=BOOL Expect a method call reply\n"
" --auto-start=BOOL Auto-start destination service\n"
" --allow-interactive-authorization=BOOL\n"
" Allow interactive authorization for operation\n"
" --timeout=SECS Maximum time to wait for method call completion\n"
" --augment-creds=BOOL Extend credential data with data read from /proc/$PID\n\n"
"Commands:\n"
" list List bus names\n"
" status [SERVICE] Show bus service, process or bus owner credentials\n"
" monitor [SERVICE...] Show bus traffic\n"
" capture [SERVICE...] Capture bus traffic as pcap\n"
" tree [SERVICE...] Show object tree of service\n"
" introspect SERVICE OBJECT [INTERFACE]\n"
" call SERVICE OBJECT INTERFACE METHOD [SIGNATURE [ARGUMENT...]]\n"
" Call a method\n"
" get-property SERVICE OBJECT INTERFACE PROPERTY...\n"
" Get property value\n"
" set-property SERVICE OBJECT INTERFACE PROPERTY SIGNATURE ARGUMENT...\n"
" Set property value\n"
" help Show this help\n"
return 0;
}
enum {
ARG_VERSION = 0x100,
};
{ "allow-interactive-authorization", required_argument, NULL, ARG_ALLOW_INTERACTIVE_AUTHORIZATION },
{},
};
int c, r;
switch (c) {
case 'h':
return help();
case ARG_VERSION:
return version();
case ARG_NO_PAGER:
arg_no_pager = true;
break;
case ARG_NO_LEGEND:
arg_legend = false;
break;
case ARG_USER:
arg_user = true;
break;
case ARG_SYSTEM:
arg_user = false;
break;
case ARG_ADDRESS:
break;
case ARG_SHOW_MACHINE:
arg_show_machine = true;
break;
case ARG_UNIQUE:
arg_unique = true;
break;
case ARG_ACQUIRED:
arg_acquired = true;
break;
case ARG_ACTIVATABLE:
arg_activatable = true;
break;
case ARG_MATCH:
return log_oom();
break;
case ARG_SIZE: {
if (r < 0) {
return r;
}
log_error("Size out of range.");
return -E2BIG;
}
break;
}
case ARG_LIST:
arg_list = true;
break;
case 'H':
break;
case 'M':
break;
case 'q':
arg_quiet = true;
break;
case ARG_VERBOSE:
arg_verbose = true;
break;
case ARG_EXPECT_REPLY:
r = parse_boolean(optarg);
if (r < 0) {
log_error("Failed to parse --expect-reply= parameter.");
return r;
}
arg_expect_reply = !!r;
break;
case ARG_AUTO_START:
r = parse_boolean(optarg);
if (r < 0) {
log_error("Failed to parse --auto-start= parameter.");
return r;
}
arg_auto_start = !!r;
break;
r = parse_boolean(optarg);
if (r < 0) {
log_error("Failed to parse --allow-interactive-authorization= parameter.");
return r;
}
break;
case ARG_TIMEOUT:
if (r < 0) {
log_error("Failed to parse --timeout= parameter.");
return r;
}
break;
case ARG_AUGMENT_CREDS:
r = parse_boolean(optarg);
if (r < 0) {
log_error("Failed to parse --augment-creds= parameter.");
return r;
}
arg_augment_creds = !!r;
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
return 1;
}
return help();
return -EINVAL;
}
int r;
log_open();
if (r <= 0)
goto finish;
r = sd_bus_new(&bus);
if (r < 0) {
log_error_errno(r, "Failed to allocate bus: %m");
goto finish;
}
r = sd_bus_set_monitor(bus, true);
if (r < 0) {
log_error_errno(r, "Failed to set monitor mode: %m");
goto finish;
}
if (r < 0) {
log_error_errno(r, "Failed to enable credentials: %m");
goto finish;
}
r = sd_bus_negotiate_timestamp(bus, true);
if (r < 0) {
log_error_errno(r, "Failed to enable timestamps: %m");
goto finish;
}
r = sd_bus_negotiate_fds(bus, true);
if (r < 0) {
log_error_errno(r, "Failed to enable fds: %m");
goto finish;
}
}
r = sd_bus_set_bus_client(bus, true);
if (r < 0) {
log_error_errno(r, "Failed to set bus client: %m");
goto finish;
}
if (arg_address)
else {
switch (arg_transport) {
case BUS_TRANSPORT_LOCAL:
if (arg_user) {
r = bus_set_address_user(bus);
} else {
r = bus_set_address_system(bus);
}
break;
case BUS_TRANSPORT_REMOTE:
break;
case BUS_TRANSPORT_MACHINE:
break;
default:
assert_not_reached("Hmm, unknown transport type.");
}
}
if (r < 0) {
log_error_errno(r, "Failed to set address: %m");
goto finish;
}
r = sd_bus_start(bus);
if (r < 0) {
log_error_errno(r, "Failed to connect to bus: %m");
goto finish;
}
pager_close();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}