int main(int argc, char *argv[]) { sd_bus_slot *slot = NULL; int r; char *mode = NULL; /* Connect to system bus */ // r = sd_bus_open_user(&bus); r = sd_bus_open_system(&bus); if (r < 0) { fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); goto finish; } r = sd_bus_add_match(bus, &slot, FILTER, bus_signal_cb, NULL); if (r < 0) { fprintf(stderr, "Failed: sd_bus_add_match: %s : %s\n", strerror(-r), FILTER); goto finish; } r = sd_bus_add_match(bus, &slot, FILTER2, greeting, NULL); if (r < 0) { fprintf(stderr, "Failed: %d sd_bus_add_match: %s : %s\n", __LINE__, strerror(-r), FILTER); goto finish; } for (;;) { /* Process requests */ r = sd_bus_process(bus, NULL); if (r < 0) { fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); goto finish; } if (r > 0) { continue; } r = sd_bus_wait(bus, (uint64_t) - 1); if (r < 0) { fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); goto finish; } } finish: sd_bus_slot_unref(slot); sd_bus_unref(bus); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
static kbdctx *kbdctx_unref(kbdctx *kc) { if (!kc) return NULL; assert_return(kc->ref > 0, NULL); if (--kc->ref > 0) return NULL; free(kc->last_x11_options); free(kc->last_x11_variant); free(kc->last_x11_layout); free(kc->last_x11_model); free(kc->locale_x11_options); free(kc->locale_x11_variant); free(kc->locale_x11_layout); free(kc->locale_x11_model); free(kc->locale_lang); kc->slot_locale_get_all = sd_bus_slot_unref(kc->slot_locale_get_all); kc->slot_locale_props_changed = sd_bus_slot_unref(kc->slot_locale_props_changed); kc->kbdtbl = kbdtbl_unref(kc->kbdtbl); kc->kbdmap = kbdmap_unref(kc->kbdmap); xkb_context_unref(kc->xkb_context); hashmap_remove_value(kc->context->data_map, KBDCTX_KEY, kc); free(kc); return NULL; }
static int kbdctx_locale_props_changed_fn(sd_bus *bus, sd_bus_message *signal, void *userdata, sd_bus_error *ret_err) { kbdctx *kc = userdata; int r; kc->slot_locale_get_all = sd_bus_slot_unref(kc->slot_locale_get_all); /* skip interface name */ r = sd_bus_message_skip(signal, "s"); if (r < 0) goto error; r = bus_message_map_properties_changed(bus, signal, kbdctx_locale_map, kc); if (r < 0) goto error; if (r > 0) { r = kbdctx_query_locale(kc); if (r < 0) return r; } kbdctx_refresh_keymap(kc); return 0; error: return log_debug_errno(r, "idev-keyboard: cannot handle PropertiesChanged from locale1: %m"); }
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 kbdctx_locale_get_all_fn(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_err) { kbdctx *kc = userdata; int r; kc->slot_locale_get_all = sd_bus_slot_unref(kc->slot_locale_get_all); if (sd_bus_message_is_method_error(m, NULL)) { const sd_bus_error *error = sd_bus_message_get_error(m); log_debug("idev-keyboard: GetAll() on locale1 failed: %s: %s", error->name, error->message); return 0; } r = bus_message_map_all_properties(bus, m, kbdctx_locale_map, kc); if (r < 0) { log_debug("idev-keyboard: erroneous GetAll() reply from locale1"); return 0; } kbdctx_refresh_keymap(kc); return 0; }
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); }
static int session_take_control_fn(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error) { sysview_session *session = userdata; int r, error; session->slot_take_control = sd_bus_slot_unref(session->slot_take_control); if (sd_bus_message_is_method_error(reply, NULL)) { const sd_bus_error *e = sd_bus_message_get_error(reply); log_debug("sysview: %s: TakeControl failed: %s: %s", session->name, e->name, e->message); error = -sd_bus_error_get_errno(e); } else { session->has_control = true; error = 0; } r = context_raise_session_control(session->seat->context, session, error); if (r < 0) log_debug_errno(r, "sysview: callback failed while signalling session control '%d' on session '%s': %m", error, session->name); return 0; }
void Slot::stop(){ bus=nullptr; if(handle){ handle=sd_bus_slot_unref(handle); } Event::stop(); }
static int async_polkit_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) { _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL; AsyncPolkitQuery *q = userdata; int r; assert(bus); assert(reply); assert(q); q->slot = sd_bus_slot_unref(q->slot); q->reply = sd_bus_message_ref(reply); r = sd_bus_message_rewind(q->request, true); if (r < 0) { r = sd_bus_reply_method_errno(q->request, r, NULL); goto finish; } r = q->callback(bus, q->request, q->userdata, &error_buffer); r = bus_maybe_reply_error(q->request, r, &error_buffer); finish: async_polkit_query_free(q); return r; }
static struct track_item* track_item_free(struct track_item *i) { if (!i) return NULL; sd_bus_slot_unref(i->slot); free(i->name); return mfree(i); }
static void run_context_free(RunContext *c) { assert(c); c->forward = pty_forward_free(c->forward); c->match = sd_bus_slot_unref(c->match); c->bus = sd_bus_unref(c->bus); c->event = sd_event_unref(c->event); free(c->active_state); free(c->result); }
struct cc_client_Ball *cc_client_Ball_free(struct cc_client_Ball *instance) { CC_LOG_DEBUG("invoked cc_client_Ball_free()\n"); if (instance) { instance->grab_reply_slot = sd_bus_slot_unref(instance->grab_reply_slot); instance->instance = cc_instance_free(instance->instance); /* User is responsible for memory management of data. */ free(instance); } return NULL; }
struct cc_server_Smartie *cc_server_Smartie_free(struct cc_server_Smartie *instance) { CC_LOG_DEBUG("invoked cc_server_Smartie_free()\n"); if (instance) { instance->vtable_slot = sd_bus_slot_unref(instance->vtable_slot); instance->instance = cc_instance_free(instance->instance); /* User is resposible for memory management of impl and data. */ free(instance); } return NULL; }
static void subscription_cleanup(const struct sol_monitors *monitors, const struct sol_monitors_entry *entry) { struct subscription *sub = (struct subscription *)entry; sub->slot = sd_bus_slot_unref(sub->slot); if (sub->conn) sol_bt_conn_unref(sub->conn); }
static void async_polkit_query_free(AsyncPolkitQuery *q) { if (!q) return; sd_bus_slot_unref(q->slot); if (q->registry && q->request) hashmap_remove(q->registry, q->request); sd_bus_message_unref(q->request); sd_bus_message_unref(q->reply); free(q); }
/* * This is the main loop of the d-bus service. It won't exit until * quit_dbus_main_loop() is called. * * It is should be invoked as the startup function of a thread or the caller * should not expect it to return. */ void * multipath_main_loop(void * ap) { sd_bus_slot *slot = NULL; sd_bus *bus = NULL; int r; /* Connect to the user bus this time */ r = sd_bus_open_user(&bus); if (r < 0) { fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); goto finish; } sync_maps(bus, slot); /* Take a well-known service name so that clients can find us */ r = sd_bus_request_name(bus, MULTIPATH_BASE_INTERFACE, 0); if (r < 0) { fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r)); goto finish; } for (;;) { /* Process requests */ r = sd_bus_process(bus, NULL); if (r < 0) { fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); goto finish; } if (r > 0) /* we processed a request, try to process another one, right-away */ continue; /* Wait for the next request to process */ r = sd_bus_wait(bus, (uint64_t) - 1); if (r < 0) { fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); goto finish; } } finish: sd_bus_slot_unref(slot); sd_bus_unref(bus); return NULL; }
static void destroy_pending(struct sol_gatt_pending *op) { if (op->buf) sol_buffer_fini(op->buf); if (op->type == PENDING_REMOTE_READ && op->read) op->read((void *)op->user_data, false, NULL, NULL); if (op->type == PENDING_REMOTE_WRITE && op->write) op->write((void *)op->user_data, false, NULL); op->slot = sd_bus_slot_unref(op->slot); sd_bus_message_unref(op->m); free(op); }
static int session_take_control_fn(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error) { sysview_session *session = userdata; int error; session->slot_take_control = sd_bus_slot_unref(session->slot_take_control); if (sd_bus_message_is_method_error(reply, NULL)) { const sd_bus_error *e = sd_bus_message_get_error(reply); log_debug("sysview: %s: TakeControl failed: %s: %s", session->name, e->name, e->message); error = sd_bus_error_get_errno(e); } else { session->has_control = true; error = 0; } return context_raise_session_control(session->seat->context, session, error); }
static int cc_Calculator_split_reply_thunk( CC_IGNORE_BUS_ARG sd_bus_message *message, void *userdata, sd_bus_error *ret_error) { int result = 0; sd_bus *bus; struct cc_client_Calculator *ii = (struct cc_client_Calculator *) userdata; int32_t whole; int32_t fraction; (void) ret_error; CC_LOG_DEBUG("invoked cc_Calculator_split_reply_thunk()\n"); assert(message); bus = sd_bus_message_get_bus(message); assert(bus); assert(ii); assert(ii->split_reply_callback); assert(ii->split_reply_slot == sd_bus_get_current_slot(bus)); result = sd_bus_message_get_errno(message); if (result != 0) { CC_LOG_ERROR("failed to receive response: %s\n", strerror(result)); goto finish; } result = sd_bus_message_read(message, "ii", &whole, &fraction); if (result < 0) { CC_LOG_ERROR("unable to get reply value: %s\n", strerror(-result)); goto finish; } CC_LOG_DEBUG("invoking callback in cc_Calculator_split_reply_thunk()\n"); CC_LOG_DEBUG("with whole=%" PRId32 ", fraction=%" PRId32 "\n", whole, fraction); ii->split_reply_callback(ii, whole, fraction); result = 1; finish: ii->split_reply_callback = NULL; ii->split_reply_slot = sd_bus_slot_unref(ii->split_reply_slot); return result; }
_public_ int sd_bus_slot_set_floating(sd_bus_slot *slot, int b) { assert_return(slot, -EINVAL); if (slot->floating == !!b) return 0; if (!slot->bus) /* already disconnected slots can't be reconnected */ return -ESTALE; slot->floating = b; /* When a slot is "floating" then the bus references the slot. Otherwise the slot references the bus. Hence, * when we move from one to the other, let's increase one reference and decrease the other. */ if (b) { sd_bus_slot_ref(slot); sd_bus_unref(slot->bus); } else { sd_bus_ref(slot->bus); sd_bus_slot_unref(slot); } return 1; }
static int cc_Ball_grab_reply_thunk( CC_IGNORE_BUS_ARG sd_bus_message *message, void *userdata, sd_bus_error *ret_error) { int result = 0; sd_bus *bus; struct cc_client_Ball *ii = (struct cc_client_Ball *) userdata; int success_int; CC_LOG_DEBUG("invoked cc_Ball_grab_reply_thunk()\n"); assert(message); bus = sd_bus_message_get_bus(message); assert(bus); assert(ii); assert(ii->grab_reply_callback); assert(ii->grab_reply_slot == sd_bus_get_current_slot(bus)); result = sd_bus_message_get_errno(message); if (result != 0) { CC_LOG_ERROR("failed to receive response: %s\n", strerror(result)); goto finish; } result = sd_bus_message_read(message, "b", &success_int); if (result < 0) { CC_LOG_ERROR("unable to get reply value: %s\n", strerror(-result)); goto finish; } CC_LOG_DEBUG("invoking callback in cc_Ball_grab_reply_thunk()\n"); CC_LOG_DEBUG("with success=%d\n", !!success_int); ii->grab_reply_callback(ii, !!success_int); result = 1; finish: ii->grab_reply_callback = NULL; ii->grab_reply_slot = sd_bus_slot_unref(ii->grab_reply_slot); return result; }
void kirstu_dbus_free(void) { sd_bus_slot_unref(slot); sd_bus_unref(bus); }
int main(int argc, char *argv[]) { sd_bus_slot *slot = NULL; int r; char *mode = NULL; // Register all the handlers that provider implementation to IPMI commands. ipmi_register_callback_handlers(HOST_IPMI_LIB_PATH); #ifdef __IPMI_DEBUG__ printf("Registered Function handlers:\n"); // Print the registered handlers and their arguments. for(auto& iter : g_ipmid_router_map) { ipmi_fn_cmd_t fn_and_cmd = iter.first; printf("NETFN:[0x%X], cmd[0x%X]\n", fn_and_cmd.first, fn_and_cmd.second); } #endif /* Connect to system bus */ r = sd_bus_open_system(&bus); if (r < 0) { fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); goto finish; } r = sd_bus_add_match(bus, &slot, FILTER, handle_ipmi_command, NULL); if (r < 0) { fprintf(stderr, "Failed: sd_bus_add_match: %s : %s\n", strerror(-r), FILTER); goto finish; } for (;;) { /* Process requests */ r = sd_bus_process(bus, NULL); if (r < 0) { fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); goto finish; } if (r > 0) { continue; } r = sd_bus_wait(bus, (uint64_t) - 1); if (r < 0) { fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); goto finish; } } finish: sd_bus_slot_unref(slot); sd_bus_unref(bus); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { sd_bus_slot *slot = NULL; sd_bus *bus = NULL; int r; char **acquired = NULL, **activatable = NULL, **i; /* Connect to the user bus this time */ r = sd_bus_open_system(&bus); if (r < 0) { fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); goto finish; } /* Install an object */ r = sd_bus_add_object_vtable(bus, &slot, "/org/openbmc/examples/path0/SDBusObj", /* object path */ "org.openbmc.examples.Echo", /* interface name */ echo_vtable, NULL); if (r < 0) { fprintf(stderr, "Failed to issue method call: %s\n", strerror(-r)); goto finish; } /* Install an object */ r = sd_bus_add_object_vtable(bus, &slot, "/org/openbmc/examples/path1/SDBusObj", /* object path */ "org.openbmc.examples.Echo", /* interface name */ echo_vtable, NULL); if (r < 0) { fprintf(stderr, "Failed to issue method call: %s\n", strerror(-r)); goto finish; } /* Take a well-known service name so that clients can find us */ r = sd_bus_request_name(bus, "org.openbmc.examples.SDBusService", 0); if (r < 0) { fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r)); goto finish; } for (;;) { /* Process requests */ r = sd_bus_process(bus, NULL); if (r < 0) { fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); goto finish; } if (r > 0) /* we processed a request, try to process another one, right-away */ continue; /* Wait for the next request to process */ r = sd_bus_wait(bus, (uint64_t) -1); if (r < 0) { fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); goto finish; } } finish: sd_bus_slot_unref(slot); sd_bus_unref(bus); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
/* * ------------------------------------------------ * Called as part of setting up skeleton services. * ----------------------------------------------- */ int start_led_services() { /* Generic error reporter. */ int rc = -1; int num_leds = 0; int count_leds = 0; /* Bus and slot where we are offering the LED dbus service. */ sd_bus *bus_type = NULL; sd_bus_slot *led_slot = NULL; /* For walking '/sys/class/leds/' looking for names of LED.*/ struct dirent **led_list; /* Get a hook onto system bus. */ rc = sd_bus_open_system(&bus_type); if(rc < 0) { fprintf(stderr,"Error opening system bus.\n"); return rc; } count_leds = num_leds = scandir("/sys/class/leds/", &led_list, led_select, alphasort); if(num_leds <= 0) { fprintf(stderr,"No LEDs present in the system\n"); sd_bus_slot_unref(led_slot); sd_bus_unref(bus_type); return rc; } /* Fully qualified Dbus object for a particular LED */ char led_object[128] = {0}; int len = 0; /* For each led present, announce the service on dbus. */ while(num_leds--) { memset(led_object, 0x0, sizeof(led_object)); len = snprintf(led_object, sizeof(led_object), "%s%s", "/org/openbmc/controller/led/", led_list[num_leds]->d_name); if(len >= sizeof(led_object)) { fprintf(stderr, "Error. LED object is too long:[%d]\n",len); rc = -1; break; } /* Install the object */ rc = sd_bus_add_object_vtable(bus_type, &led_slot, led_object, /* object path */ "org.openbmc.controller.led", /* interface name */ led_control_vtable, NULL); if (rc < 0) { fprintf(stderr, "Failed to add object to dbus: %s\n", strerror(-rc)); break; } } /* Done with all registration. */ while (count_leds > 0) { free(led_list[--count_leds]); if(count_leds == 0) { free(led_list); } } /* If we had success in adding the providers, request for a bus name. */ if(rc == 0) { /* Take one in OpenBmc */ rc = sd_bus_request_name(bus_type, "org.openbmc.controller.led", 0); if (rc < 0) { fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-rc)); } else { for (;;) { /* Process requests */ rc = sd_bus_process(bus_type, NULL); if (rc < 0) { fprintf(stderr, "Failed to process bus: %s\n", strerror(-rc)); break; } if (rc > 0) { continue; } rc = sd_bus_wait(bus_type, (uint64_t) - 1); if (rc < 0) { fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-rc)); break; } } } } sd_bus_slot_unref(led_slot); sd_bus_unref(bus_type); return rc; }
void bus_slot_disconnect(sd_bus_slot *slot, bool unref) { sd_bus *bus; assert(slot); if (!slot->bus) return; switch (slot->type) { case BUS_REPLY_CALLBACK: if (slot->reply_callback.cookie != 0) ordered_hashmap_remove(slot->bus->reply_callbacks, &slot->reply_callback.cookie); if (slot->reply_callback.timeout_usec != 0) prioq_remove(slot->bus->reply_callbacks_prioq, &slot->reply_callback, &slot->reply_callback.prioq_idx); break; case BUS_FILTER_CALLBACK: slot->bus->filter_callbacks_modified = true; LIST_REMOVE(callbacks, slot->bus->filter_callbacks, &slot->filter_callback); break; case BUS_MATCH_CALLBACK: if (slot->match_added) (void) bus_remove_match_internal(slot->bus, slot->match_callback.match_string); if (slot->match_callback.install_slot) { bus_slot_disconnect(slot->match_callback.install_slot, true); slot->match_callback.install_slot = sd_bus_slot_unref(slot->match_callback.install_slot); } slot->bus->match_callbacks_modified = true; bus_match_remove(&slot->bus->match_callbacks, &slot->match_callback); slot->match_callback.match_string = mfree(slot->match_callback.match_string); break; case BUS_NODE_CALLBACK: if (slot->node_callback.node) { LIST_REMOVE(callbacks, slot->node_callback.node->callbacks, &slot->node_callback); slot->bus->nodes_modified = true; bus_node_gc(slot->bus, slot->node_callback.node); } break; case BUS_NODE_ENUMERATOR: if (slot->node_enumerator.node) { LIST_REMOVE(enumerators, slot->node_enumerator.node->enumerators, &slot->node_enumerator); slot->bus->nodes_modified = true; bus_node_gc(slot->bus, slot->node_enumerator.node); } break; case BUS_NODE_OBJECT_MANAGER: if (slot->node_object_manager.node) { LIST_REMOVE(object_managers, slot->node_object_manager.node->object_managers, &slot->node_object_manager); slot->bus->nodes_modified = true; bus_node_gc(slot->bus, slot->node_object_manager.node); } break; case BUS_NODE_VTABLE: if (slot->node_vtable.node && slot->node_vtable.interface && slot->node_vtable.vtable) { const sd_bus_vtable *v; for (v = slot->node_vtable.vtable; v->type != _SD_BUS_VTABLE_END; v = bus_vtable_next(slot->node_vtable.vtable, v)) { struct vtable_member *x = NULL; switch (v->type) { case _SD_BUS_VTABLE_METHOD: { struct vtable_member key; key.path = slot->node_vtable.node->path; key.interface = slot->node_vtable.interface; key.member = v->x.method.member; x = hashmap_remove(slot->bus->vtable_methods, &key); break; } case _SD_BUS_VTABLE_PROPERTY: case _SD_BUS_VTABLE_WRITABLE_PROPERTY: { struct vtable_member key; key.path = slot->node_vtable.node->path; key.interface = slot->node_vtable.interface; key.member = v->x.method.member; x = hashmap_remove(slot->bus->vtable_properties, &key); break; }} free(x); } } slot->node_vtable.interface = mfree(slot->node_vtable.interface); if (slot->node_vtable.node) { LIST_REMOVE(vtables, slot->node_vtable.node->vtables, &slot->node_vtable); slot->bus->nodes_modified = true; bus_node_gc(slot->bus, slot->node_vtable.node); } break; default: assert_not_reached("Wut? Unknown slot type?"); } bus = slot->bus; slot->type = _BUS_SLOT_INVALID; slot->bus = NULL; LIST_REMOVE(slots, bus->slots, slot); if (!slot->floating) sd_bus_unref(bus); else if (unref) sd_bus_slot_unref(slot); }
int main(int argc, char *argv[]) { sd_bus_slot *slot = NULL; int r; char *mode = NULL; if (argc != 2) { fprintf(stderr, "syntax: %s [server|client]\n", argv[0]); return 1; } mode = argv[1]; /* Connect to system bus */ r = sd_bus_open_system(&bus); if (r < 0) { fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); goto finish; } if (!strcmp("server", mode)) { r = sd_bus_add_object_vtable(bus, &slot, OBJ, /* object path */ INT, /* interface name */ signal_vtable, NULL); if (r < 0) { fprintf(stderr, "Failed to issue method call: %s\n", strerror(-r)); goto finish; } /* Take a well-known service name so that clients can find us */ r = sd_bus_request_name(bus, INT, 0); if (r < 0) { fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r)); goto finish; } } else if (!strcmp("client", mode)) { r = sd_bus_add_match(bus, &slot, FILTER, bus_signal_cb, NULL); if (r < 0) { fprintf(stderr, "Failed: sd_bus_add_match: %s\n", strerror(-r)); goto finish; } } else { fprintf(stderr, "Invalid operating mode %s", mode); return 1; } for (;;) { /* Process requests */ r = sd_bus_process(bus, NULL); if (r < 0) { fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); goto finish; } if (r > 0) { continue; } r = sd_bus_wait(bus, (uint64_t) - 1); if (r < 0) { fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); goto finish; } } finish: sd_bus_slot_unref(slot); sd_bus_unref(bus); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }