static void test_marshal(void) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *n = NULL; _cleanup_bus_unref_ sd_bus *bus = NULL; _cleanup_free_ void *blob; size_t sz; assert_se(sd_bus_open_system(&bus) >= 0); bus->message_version = 2; /* dirty hack to enable gvariant*/ assert_se(sd_bus_message_new_method_call(bus, "a.service.name", "/an/object/path/which/is/really/really/long/so/that/we/hit/the/eight/bit/boundary/by/quite/some/margin/to/test/this/stuff/that/it/really/works", "an.interface.name", "AMethodName", &m) >= 0); assert_se(sd_bus_message_append(m, "a(usv)", 2, 4711, "first-string-parameter", "(st)", "X", (uint64_t) 1111, 4712, "second-string-parameter", "(a(si))", 2, "Y", 5, "Z", 6) >= 0); assert_se(bus_message_seal(m, 4711) >= 0); #ifdef HAVE_GLIB { GVariant *v; char *t; #if !defined(GLIB_VERSION_2_36) g_type_init(); #endif v = g_variant_new_from_data(G_VARIANT_TYPE("(yyyyuuua(yv))"), m->header, sizeof(struct bus_header) + BUS_MESSAGE_FIELDS_SIZE(m), false, NULL, NULL); t = g_variant_print(v, TRUE); printf("%s\n", t); g_free(t); g_variant_unref(v); v = g_variant_new_from_data(G_VARIANT_TYPE("(a(usv))"), m->body.data, BUS_MESSAGE_BODY_SIZE(m), false, NULL, NULL); t = g_variant_print(v, TRUE); printf("%s\n", t); g_free(t); g_variant_unref(v); } #endif assert_se(bus_message_dump(m, NULL, true) >= 0); assert_se(bus_message_get_blob(m, &blob, &sz) >= 0); assert_se(bus_message_from_malloc(NULL, blob, sz, NULL, 0, NULL, NULL, &n) >= 0); blob = NULL; assert_se(bus_message_dump(n, NULL, true) >= 0); m = sd_bus_message_unref(m); assert_se(sd_bus_message_new_method_call(bus, "a.x", "/a/x", "a.x", "Ax", &m) >= 0); assert_se(sd_bus_message_append(m, "as", 0) >= 0); assert_se(bus_message_seal(m, 4712) >= 0); assert_se(bus_message_dump(m, NULL, true) >= 0); }
int sysview_session_take_control(sysview_session *session) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; assert_return(session, -EINVAL); assert_return(!session->custom, -EINVAL); if (session->wants_control) return 0; r = sd_bus_message_new_method_call(session->seat->context->sysbus, &m, "org.freedesktop.login1", session->path, "org.freedesktop.login1.Session", "TakeControl"); if (r < 0) return r; r = sd_bus_message_append(m, "b", 0); if (r < 0) return r; r = sd_bus_call_async(session->seat->context->sysbus, &session->slot_take_control, m, session_take_control_fn, session, 0); if (r < 0) return r; session->wants_control = true; return 0; }
static int reload_manager(sd_bus *bus) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; log_info("Reloading system manager configuration"); r = sd_bus_message_new_method_call( bus, &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reload"); if (r < 0) return bus_log_create_error(r); /* Note we use an extra-long timeout here. This is because a reload or reexec means generators are rerun which * are timed out after DEFAULT_TIMEOUT_USEC. Let's use twice that time here, so that the generators can have * their timeout, and for everything else there's the same time budget in place. */ r = sd_bus_call(bus, m, DEFAULT_TIMEOUT_USEC * 2, &error, NULL); if (r < 0) return log_error_errno(r, "Failed to reload daemon: %s", bus_error_message(&error, r)); return 0; }
// Use a lookup table to find the interface name of a specific sensor // This will be used until an alternative is found. this is the first // step for mapping IPMI int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) { const char *busname = "org.openbmc.managers.System"; const char *objname = "/org/openbmc/managers/System"; char *str1, *str2, *str3; sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus_message *reply = NULL, *m=NULL; int r; r = sd_bus_message_new_method_call(bus,&m,busname,objname,busname,"getObjectFromByteId"); if (r < 0) { fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); } r = sd_bus_message_append(m, "sy", type, num); if (r < 0) { fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); } // Call the IPMI responder on the bus so the message can be sent to the CEC r = sd_bus_call(bus, m, 0, &error, &reply); if (r < 0) { fprintf(stderr, "Failed to call the method: %s", strerror(-r)); goto final; }
void sysview_session_release_control(sysview_session *session) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; assert(session); assert(!session->custom); if (!session->wants_control) return; session->wants_control = false; if (!session->has_control && !session->slot_take_control) return; session->has_control = false; session->slot_take_control = sd_bus_slot_unref(session->slot_take_control); r = sd_bus_message_new_method_call(session->seat->context->sysbus, &m, "org.freedesktop.login1", session->path, "org.freedesktop.login1.Session", "ReleaseControl"); if (r >= 0) r = sd_bus_send(session->seat->context->sysbus, m, NULL); if (r < 0 && r != -ENOTCONN) log_debug_errno(r, "sysview: %s: cannot send ReleaseControl: %m", session->name); }
_public_ int sd_bus_call_method( sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; assert_return(bus, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); if (!BUS_IS_OPEN(bus->state)) return -ENOTCONN; r = sd_bus_message_new_method_call(bus, &m, destination, path, interface, member); if (r < 0) return r; if (!isempty(types)) { va_list ap; va_start(ap, types); r = bus_message_append_ap(m, types, ap); va_end(ap); if (r < 0) return r; } return sd_bus_call(bus, m, 0, error, reply); }
ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, ipmi_response_t response, ipmi_data_len_t data_len, ipmi_context_t context) { const char *busname = "org.openbmc.watchdog.Host"; const char *objname = "/org/openbmc/watchdog/host0"; const char *iface = "org.openbmc.Watchdog"; sd_bus_message *reply = NULL, *m = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; int r = 0; // Status code. ipmi_ret_t rc = IPMI_CC_OK; *data_len = 0; printf("WATCHDOG RESET\n"); // Refresh watchdog r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"poke"); if (r < 0) { fprintf(stderr, "Failed to add the method object: %s\n", strerror(-r)); return -1; } r = sd_bus_call(bus, m, 0, &error, &reply); if (r < 0) { fprintf(stderr, "Failed to call the method: %s\n", strerror(-r)); return -1; } sd_bus_error_free(&error); sd_bus_message_unref(m); return rc; }
static int maybe_reload(sd_bus **bus) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; if (!arg_reload) return 0; r = acquire_bus(bus); if (r < 0) return r; r = sd_bus_message_new_method_call( *bus, &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reload"); if (r < 0) return bus_log_create_error(r); /* Reloading the daemon may take long, hence set a longer timeout here */ r = sd_bus_call(*bus, m, DEFAULT_TIMEOUT_USEC * 2, &error, NULL); if (r < 0) return log_error_errno(r, "Failed to reload daemon: %s", bus_error_message(&error, r)); return 0; }
static int client(struct context *c) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL; _cleanup_bus_unref_ sd_bus *bus = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; int r; assert_se(sd_bus_new(&bus) >= 0); assert_se(sd_bus_set_fd(bus, c->fds[1], c->fds[1]) >= 0); assert_se(sd_bus_negotiate_fds(bus, c->client_negotiate_unix_fds) >= 0); assert_se(sd_bus_set_anonymous(bus, c->client_anonymous_auth) >= 0); assert_se(sd_bus_start(bus) >= 0); r = sd_bus_message_new_method_call( bus, &m, "org.freedesktop.systemd.test", "/", "org.freedesktop.systemd.test", "Exit"); if (r < 0) { log_error("Failed to allocate method call: %s", strerror(-r)); return r; } r = sd_bus_call(bus, m, 0, &error, &reply); if (r < 0) { log_error("Failed to issue method call: %s", bus_error_message(&error, -r)); return r; } return 0; }
static void test_rr_lookup(sd_bus *bus, const char *name, uint16_t type, const char *result) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *req = NULL, *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *m = NULL; int r; /* If the name starts with a dot, we prefix one to three random labels */ if (startswith(name, ".")) { prefix_random(name + 1, &m); name = m; } assert_se(sd_bus_message_new_method_call( bus, &req, "org.freedesktop.resolve1", "/org/freedesktop/resolve1", "org.freedesktop.resolve1.Manager", "ResolveRecord") >= 0); assert_se(sd_bus_message_append(req, "isqqt", 0, name, DNS_CLASS_IN, type, UINT64_C(0)) >= 0); r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply); if (r < 0) { assert_se(result); assert_se(sd_bus_error_has_name(&error, result)); log_info("[OK] %s/%s resulted in <%s>.", name, dns_type_to_string(type), error.name); } else { assert_se(!result); log_info("[OK] %s/%s succeeded.", name, dns_type_to_string(type)); } }
int cc_Ball_drop(struct cc_client_Ball *instance) { int result = 0; struct cc_instance *i; sd_bus_message *message = NULL; CC_LOG_DEBUG("invoked cc_Ball_drop()\n"); assert(instance); i = instance->instance; assert(i && i->backend && i->backend->bus); assert(i->service && i->path && i->interface); result = sd_bus_message_new_method_call( i->backend->bus, &message, i->service, i->path, i->interface, "drop"); if (result < 0) { CC_LOG_ERROR("unable to create message: %s\n", strerror(-result)); goto fail; } result = sd_bus_message_set_expect_reply(message, 0); if (result < 0) { CC_LOG_ERROR("unable to flag message no-reply-expected: %s\n", strerror(-result)); goto fail; } /* Setting cookie=NULL in sd_bus_send() call makes the previous one redundant */ result = sd_bus_send(i->backend->bus, message, NULL); if (result < 0) { CC_LOG_ERROR("unable to send message: %s\n", strerror(-result)); goto fail; } fail: message = sd_bus_message_unref(message); return result; }
static int kbdctx_query_locale(kbdctx *kc) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; kc->slot_locale_get_all = sd_bus_slot_unref(kc->slot_locale_get_all); r = sd_bus_message_new_method_call(kc->context->sysbus, &m, "org.freedesktop.locale1", "/org/freedesktop/locale1", "org.freedesktop.DBus.Properties", "GetAll"); if (r < 0) goto error; r = sd_bus_message_append(m, "s", "org.freedesktop.locale1"); if (r < 0) goto error; r = sd_bus_call_async(kc->context->sysbus, &kc->slot_locale_get_all, m, kbdctx_locale_get_all_fn, kc, 0); if (r < 0) goto error; return 0; error: return log_debug_errno(r, "idev-keyboard: cannot send GetAll to locale1: %m"); }
static int set_locale(sd_bus *bus, char **args, unsigned n) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; int r; assert(bus); assert(args); polkit_agent_open_if_enabled(); r = sd_bus_message_new_method_call(bus, "org.freedesktop.locale1", "/org/freedesktop/locale1", "org.freedesktop.locale1", "SetLocale", &m); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append_strv(m, args + 1); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append(m, "b", arg_ask_password); if (r < 0) return bus_log_create_error(r); r = sd_bus_call(bus, m, 0, &error, NULL); if (r < 0) { log_error("Failed to issue method call: %s", bus_error_message(&error, -r)); return r; } return 0; }
static int set_locale(int argc, char **argv, void *userdata) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus *bus = userdata; int r; assert(bus); polkit_agent_open_if_enabled(arg_transport, arg_ask_password); r = sd_bus_message_new_method_call( bus, &m, "org.freedesktop.locale1", "/org/freedesktop/locale1", "org.freedesktop.locale1", "SetLocale"); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append_strv(m, argv + 1); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append(m, "b", arg_ask_password); if (r < 0) return bus_log_create_error(r); r = sd_bus_call(bus, m, 0, &error, NULL); if (r < 0) return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, -r)); return 0; }
static int locale_update_system_manager(Context *c, sd_bus *bus) { _cleanup_free_ char **l_unset = NULL; _cleanup_strv_free_ char **l_set = NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; unsigned c_set, c_unset, p; int r; assert(bus); l_unset = new0(char*, _VARIABLE_LC_MAX); if (!l_unset) return -ENOMEM; l_set = new0(char*, _VARIABLE_LC_MAX); if (!l_set) return -ENOMEM; for (p = 0, c_set = 0, c_unset = 0; p < _VARIABLE_LC_MAX; p++) { const char *name; name = locale_variable_to_string(p); assert(name); if (isempty(c->locale[p])) l_unset[c_set++] = (char*) name; else { char *s; if (asprintf(&s, "%s=%s", name, c->locale[p]) < 0) return -ENOMEM; l_set[c_unset++] = s; } } assert(c_set + c_unset == _VARIABLE_LC_MAX); r = sd_bus_message_new_method_call(bus, &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment"); if (r < 0) return r; r = sd_bus_message_append_strv(m, l_unset); if (r < 0) return r; r = sd_bus_message_append_strv(m, l_set); if (r < 0) return r; r = sd_bus_call(bus, m, 0, &error, NULL); if (r < 0) log_error_errno(r, "Failed to update the manager environment: %m"); return 0; }
static int locale_update_system_manager(Context *c, sd_bus *bus) { _cleanup_free_ char **l_unset = NULL; _cleanup_strv_free_ char **l_set = NULL; _cleanup_bus_message_unref_ sd_bus_message *m = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; unsigned c_set, c_unset, p; int r; assert(bus); l_unset = new0(char*, _LOCALE_MAX); if (!l_unset) return -ENOMEM; l_set = new0(char*, _LOCALE_MAX); if (!l_set) return -ENOMEM; for (p = 0, c_set = 0, c_unset = 0; p < _LOCALE_MAX; p++) { assert(names[p]); if (isempty(c->locale[p])) l_unset[c_set++] = (char*) names[p]; else { char *s; if (asprintf(&s, "%s=%s", names[p], c->locale[p]) < 0) return -ENOMEM; l_set[c_unset++] = s; } } assert(c_set + c_unset == _LOCALE_MAX); r = sd_bus_message_new_method_call(bus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment", &m); if (r < 0) return r; r = sd_bus_message_append_strv(m, l_unset); if (r < 0) return r; r = sd_bus_message_append_strv(m, l_set); if (r < 0) return r; r = sd_bus_call(bus, m, 0, &error, NULL); if (r < 0) log_error("Failed to update the manager environment: %s", strerror(-r)); return 0; }
static void client_chart(const char *address) { _cleanup_bus_message_unref_ sd_bus_message *x = NULL; size_t csize; sd_bus *b; int r; r = sd_bus_new(&b); assert_se(r >= 0); r = sd_bus_set_address(b, address); assert_se(r >= 0); r = sd_bus_start(b); assert_se(r >= 0); assert_se(sd_bus_call_method(b, ":1.1", "/", "benchmark.server", "Ping", NULL, NULL, NULL) >= 0); printf("SIZE\tCOPY\tMEMFD\n"); for (csize = 1; csize <= MAX_SIZE; csize *= 2) { usec_t t; unsigned n_copying, n_memfd; printf("%zu\t", csize); b->use_memfd = 0; t = now(CLOCK_MONOTONIC); for (n_copying = 0;; n_copying++) { transaction(b, csize); if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec) break; } printf("%u\t", (unsigned) ((n_copying * USEC_PER_SEC) / arg_loop_usec)); b->use_memfd = -1; t = now(CLOCK_MONOTONIC); for (n_memfd = 0;; n_memfd++) { transaction(b, csize); if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec) break; } printf("%u\n", (unsigned) ((n_memfd * USEC_PER_SEC) / arg_loop_usec)); } b->use_memfd = 1; assert_se(sd_bus_message_new_method_call(b, ":1.1", "/", "benchmark.server", "Exit", &x) >= 0); assert_se(sd_bus_message_append(x, "t", csize) >= 0); assert_se(sd_bus_send(b, x, NULL) >= 0); sd_bus_unref(b); }
static void transaction(sd_bus *b, size_t sz, const char *server_name) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; uint8_t *p; assert_se(sd_bus_message_new_method_call(b, &m, server_name, "/", "benchmark.server", "Work") >= 0); assert_se(sd_bus_message_append_array_space(m, 'y', sz, (void**) &p) >= 0); memset(p, 0x80, sz); assert_se(sd_bus_call(b, m, 0, NULL, &reply) >= 0); }
static void transaction(sd_bus *b, size_t sz) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL; uint8_t *p; assert_se(sd_bus_message_new_method_call(b, ":1.1", "/", "benchmark.server", "Work", &m) >= 0); assert_se(sd_bus_message_append_array_space(m, 'y', sz, (void**) &p) >= 0); memset(p, 0x80, sz); assert_se(sd_bus_send_with_reply_and_block(b, m, 0, NULL, &reply) >= 0); }
static int attach_image(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_strv_free_ char **matches = NULL; _cleanup_free_ char *image = NULL; int r; r = determine_image(argv[1], false, &image); if (r < 0) return r; r = determine_matches(argv[1], argv + 2, false, &matches); if (r < 0) return r; r = acquire_bus(&bus); if (r < 0) return r; (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password); r = sd_bus_message_new_method_call( bus, &m, "org.freedesktop.portable1", "/org/freedesktop/portable1", "org.freedesktop.portable1.Manager", "AttachImage"); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append(m, "s", image); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append_strv(m, matches); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append(m, "sbs", arg_profile, arg_runtime, arg_copy_mode); if (r < 0) return bus_log_create_error(r); r = sd_bus_call(bus, m, 0, &error, &reply); if (r < 0) return log_error_errno(r, "Failed to attach image: %s", bus_error_message(&error, r)); (void) maybe_reload(&bus); print_changes(reply); return 0; }
static void test_bus_new_method_call(void) { sd_bus *bus = NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; assert_se(sd_bus_open_user(&bus) >= 0); assert_se(sd_bus_message_new_method_call(bus, &m, "a.service.name", "/an/object/path", "an.interface.name", "AMethodName") >= 0); printf("after message_new_method_call: refcount %u\n", REFCNT_GET(bus->n_ref)); sd_bus_flush_close_unref(bus); printf("after bus_flush_close_unref: refcount %u\n", m->n_ref); }
_public_ int sd_bus_set_property( sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, const char *type, ...) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; va_list ap; int r; bus_assert_return(bus, -EINVAL, error); bus_assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL, error); bus_assert_return(member_name_is_valid(member), -EINVAL, error); bus_assert_return(signature_is_single(type, false), -EINVAL, error); bus_assert_return(!bus_pid_changed(bus), -ECHILD, error); if (!BUS_IS_OPEN(bus->state)) { r = -ENOTCONN; goto fail; } r = sd_bus_message_new_method_call(bus, &m, destination, path, "org.freedesktop.DBus.Properties", "Set"); if (r < 0) goto fail; r = sd_bus_message_append(m, "ss", strempty(interface), member); if (r < 0) goto fail; r = sd_bus_message_open_container(m, 'v', type); if (r < 0) goto fail; va_start(ap, type); r = sd_bus_message_appendv(m, type, ap); va_end(ap); if (r < 0) goto fail; r = sd_bus_message_close_container(m); if (r < 0) goto fail; return sd_bus_call(bus, m, 0, error, NULL); fail: return sd_bus_error_set_errno(error, r); }
static void start_scope_unit(sd_bus *connection, pid_t child_pid, long memory_limit, char *devices, const char *unit_name) { sd_bus_message *message = NULL; check(sd_bus_message_new_method_call(connection, &message, systemd_bus_name, systemd_path_name, manager_interface, "StartTransientUnit")); check(sd_bus_message_append(message, "ss", unit_name, "fail")); check(sd_bus_message_open_container(message, 'a', "(sv)")); check(sd_bus_message_append(message, "(sv)", "PIDs", "au", 1, child_pid)); check(sd_bus_message_append(message, "(sv)", "Description", "s", "Playpen application sandbox")); check(sd_bus_message_append(message, "(sv)", "MemoryLimit", "t", 1024ULL * 1024ULL * (unsigned long long)memory_limit)); check(sd_bus_message_append(message, "(sv)", "DevicePolicy", "s", "strict")); if (devices) { check(sd_bus_message_open_container(message, 'r', "sv")); check(sd_bus_message_append(message, "s", "DeviceAllow")); check(sd_bus_message_open_container(message, 'v', "a(ss)")); check(sd_bus_message_open_container(message, 'a', "(ss)")); for (char *s_ptr = devices, *saveptr; ; s_ptr = NULL) { const char *device = strtok_r(s_ptr, ",", &saveptr); if (!device) break; char *split = strchr(device, ':'); if (!split) errx(EXIT_FAILURE, "invalid device parameter `%s`", device); *split = '\0'; sd_bus_message_append(message, "(ss)", device, split + 1); } check(sd_bus_message_close_container(message)); check(sd_bus_message_close_container(message)); check(sd_bus_message_close_container(message)); } check(sd_bus_message_append(message, "(sv)", "CPUAccounting", "b", 1)); check(sd_bus_message_append(message, "(sv)", "BlockIOAccounting", "b", 1)); check(sd_bus_message_close_container(message)); check(sd_bus_message_append(message, "a(sa(sv))", 0)); sd_bus_error error = SD_BUS_ERROR_NULL; int rc = sd_bus_call(connection, message, 0, &error, NULL); if (rc < 0) errx(EXIT_FAILURE, "%s", sd_bus_error_is_set(&error) ? error.message : strerror(-rc)); sd_bus_message_unref(message); wait_for_unit(child_pid, unit_name); }
int cc_Calculator_split_async( struct cc_client_Calculator *instance, double value, cc_Calculator_split_reply_t callback) { int result = 0; struct cc_instance *i; sd_bus_message *message = NULL; CC_LOG_DEBUG("invoked cc_Calculator_split_async()\n"); assert(instance); assert(callback); i = instance->instance; assert(i && i->backend && i->backend->bus); assert(i->service && i->path && i->interface); if (instance->split_reply_slot) { CC_LOG_ERROR("unable to call method with already pending reply\n"); return -EBUSY; } assert(!instance->split_reply_callback); result = sd_bus_message_new_method_call( i->backend->bus, &message, i->service, i->path, i->interface, "split"); if (result < 0) { CC_LOG_ERROR("unable to create message: %s\n", strerror(-result)); goto fail; } result = sd_bus_message_append(message, "d", value); if (result < 0) { CC_LOG_ERROR("unable to append message method arguments: %s\n", strerror(-result)); goto fail; } result = sd_bus_call_async( i->backend->bus, &instance->split_reply_slot, message, &cc_Calculator_split_reply_thunk, instance, CC_DBUS_ASYNC_CALL_TIMEOUT_USEC); if (result < 0) { CC_LOG_ERROR("unable to issue method call: %s\n", strerror(-result)); goto fail; } instance->split_reply_callback = callback; fail: message = sd_bus_message_unref(message); return result; }
static sd_bus_message * create_property_set(sd_bus *bus, const char *service, const char *path, const char *interface, const char *member) { sd_bus_message *m; int r; r = sd_bus_message_new_method_call(bus, &m, service, path, "org.freedesktop.DBus.Properties", "Set"); SOL_INT_CHECK(r, < 0, NULL); r = sd_bus_message_append(m, "ss", interface, member); SOL_INT_CHECK_GOTO(r, < 0, error_append); return m; error_append: sd_bus_message_unref(m); return NULL; }
static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bus_message **ret) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; char **i; int r; assert(bus); assert(name); assert(ret); r = sd_bus_message_new_method_call( bus, &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartTransientUnit"); if (r < 0) return r; r = sd_bus_message_append(m, "ss", name, "fail"); if (r < 0) return r; r = sd_bus_message_open_container(m, 'a', "(sv)"); if (r < 0) return r; STRV_FOREACH(i, arg_property) { r = sd_bus_message_open_container(m, 'r', "sv"); if (r < 0) return r; r = bus_append_unit_property_assignment(m, *i); if (r < 0) return r; r = sd_bus_message_close_container(m); if (r < 0) return r; }
_public_ int sd_bus_call_method( sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; bus_assert_return(bus, -EINVAL, error); bus_assert_return(!bus_pid_changed(bus), -ECHILD, error); if (!BUS_IS_OPEN(bus->state)) { r = -ENOTCONN; goto fail; } r = sd_bus_message_new_method_call(bus, &m, destination, path, interface, member); if (r < 0) goto fail; if (!isempty(types)) { va_list ap; va_start(ap, types); r = sd_bus_message_appendv(m, types, ap); va_end(ap); if (r < 0) goto fail; } return sd_bus_call(bus, m, 0, error, reply); fail: return sd_bus_error_set_errno(error, r); }
int sysview_seat_switch_to(sysview_seat *seat, uint32_t nr) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; assert_return(seat, -EINVAL); assert_return(seat->context->sysbus, -EINVAL); r = sd_bus_message_new_method_call(seat->context->sysbus, &m, "org.freedesktop.login1", seat->path, "org.freedesktop.login1.Seat", "SwitchTo"); if (r < 0) return r; r = sd_bus_message_append(m, "u", nr); if (r < 0) return r; return sd_bus_send(seat->context->sysbus, m, NULL); }
static void test_hostname_lookup(sd_bus *bus, const char *name, int family, const char *result) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *req = NULL, *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *m = NULL; const char *af; int r; af = family == AF_UNSPEC ? "AF_UNSPEC" : af_to_name(family); /* If the name starts with a dot, we prefix one to three random labels */ if (startswith(name, ".")) { prefix_random(name + 1, &m); name = m; } assert_se(sd_bus_message_new_method_call( bus, &req, "org.freedesktop.resolve1", "/org/freedesktop/resolve1", "org.freedesktop.resolve1.Manager", "ResolveHostname") >= 0); assert_se(sd_bus_message_append(req, "isit", 0, name, family, UINT64_C(0)) >= 0); r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply); if (r < 0) { assert_se(result); assert_se(sd_bus_error_has_name(&error, result)); log_info("[OK] %s/%s resulted in <%s>.", name, af, error.name); } else { assert_se(!result); log_info("[OK] %s/%s succeeded.", name, af); } }
_public_ int sd_bus_call_method_async( sd_bus *bus, sd_bus_slot **slot, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message_handler_t callback, void *userdata, const char *types, ...) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; assert_return(bus, -EINVAL); assert_return(bus = bus_resolve(bus), -ENOPKG); assert_return(!bus_pid_changed(bus), -ECHILD); if (!BUS_IS_OPEN(bus->state)) return -ENOTCONN; r = sd_bus_message_new_method_call(bus, &m, destination, path, interface, member); if (r < 0) return r; if (!isempty(types)) { va_list ap; va_start(ap, types); r = sd_bus_message_appendv(m, types, ap); va_end(ap); if (r < 0) return r; } return sd_bus_call_async(bus, slot, m, callback, userdata, 0); }