static void name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { NMFirewallManager *self = NM_FIREWALL_MANAGER (user_data); gs_free char *owner = NULL; owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (object)); if (owner) { _LOGD (NULL, "firewall started"); set_running (self, TRUE); g_signal_emit (self, signals[STARTED], 0); } else { _LOGD (NULL, "firewall stopped"); set_running (self, FALSE); } }
void ensure_gdbus_testserver_up (void) { guint id; gchar *name_owner; GDBusConnection *connection; GDBusProxy *proxy; GError *error = NULL; connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); error = NULL; proxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, /* GDBusInterfaceInfo */ "com.example.TestService", /* name */ "/com/example/TestObject", /* object path */ "com.example.Frob", /* interface */ NULL, /* GCancellable */ &error); g_assert_no_error (error); id = g_timeout_add_seconds (60, _give_up, "waited more than ~ 60s for gdbus-testserver to take its bus name"); while (TRUE) { name_owner = g_dbus_proxy_get_name_owner (proxy); if (name_owner != NULL) break; g_main_context_iteration (NULL, TRUE); } g_source_remove (id); g_free (name_owner); g_object_unref (proxy); g_object_unref (connection); }
/*static*/ void uGlobalMenuService::ProxyCreatedCallback(GObject *object, GAsyncResult *res, gpointer userdata) { GError *error = NULL; GDBusProxy *proxy = g_dbus_proxy_new_for_bus_finish(res, &error); if (error && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { // If the request was cancelled, then the service is definitely not // around already g_error_free(error); return; } if (error) { g_error_free(error); } if (!sService) { // We don't assume that GDbus cancellation is reliable // see https://launchpad.net/bugs/953562 return; } g_object_unref(sService->mCancellable); sService->mCancellable = nullptr; sService->mDbusProxy = proxy; if (!proxy) { NS_WARNING("Failed to create proxy for AppMenu registrar"); sService->SetOnline(false); return; } g_signal_connect(sService->mDbusProxy, "notify::g-name-owner", G_CALLBACK(NameOwnerChangedCallback), NULL); char *owner = g_dbus_proxy_get_name_owner(sService->mDbusProxy); sService->SetOnline(owner ? true : false); g_free(owner); }
static void name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { NMDnsDnsmasq *self = NM_DNS_DNSMASQ (user_data); NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE (self); gs_free char *owner = NULL; owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (object)); if (owner) { _LOGI ("dnsmasq appeared as %s", owner); priv->running = TRUE; send_dnsmasq_update (self); } else { _LOGI ("dnsmasq disappeared"); priv->running = FALSE; g_signal_emit_by_name (self, NM_DNS_PLUGIN_FAILED); } }
static void name_owner_cb (GDBusProxy *proxy, GParamSpec *pspec, gpointer user_data) { NMSupplicantManager *self = NM_SUPPLICANT_MANAGER (user_data); NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); char *owner; g_return_if_fail (proxy == priv->proxy); owner = g_dbus_proxy_get_name_owner (proxy); nm_log_info (LOGD_SUPPLICANT, "wpa_supplicant %s", owner ? "running" : "stopped"); if (owner) { set_running (self, TRUE); update_capabilities (self); } else if (priv->running) { /* Reschedule the die count reset timeout. Every time the supplicant * dies we wait 10 seconds before resetting the counter. If the * supplicant died more than twice before the timer is reset, then * we don't try to talk to the supplicant for a while. */ if (priv->die_count_reset_id) g_source_remove (priv->die_count_reset_id); priv->die_count_reset_id = g_timeout_add_seconds (10, wpas_die_count_reset_cb, self); set_die_count (self, priv->die_count + 1); if (die_count_exceeded (priv->die_count)) { nm_log_info (LOGD_SUPPLICANT, "wpa_supplicant die count %d; ignoring for 10 seconds", priv->die_count); } set_running (self, FALSE); priv->fast_supported = FALSE; } g_free (owner); }
static void _fcitx_client_create_ic_phase2_finished(GObject *source_object, GAsyncResult *res, gpointer user_data) { FCITX_UNUSED(source_object); g_return_if_fail (user_data != NULL); g_return_if_fail (FCITX_IS_CLIENT(user_data)); FcitxClient* self = (FcitxClient*) user_data; if (self->priv->cancellable) { g_object_unref (self->priv->cancellable); self->priv->cancellable = NULL; } if (self->priv->icproxy) g_object_unref(self->priv->icproxy); self->priv->icproxy = g_dbus_proxy_new_finish(res, NULL); do { if (!self->priv->icproxy) break; gchar* owner_name = g_dbus_proxy_get_name_owner(self->priv->icproxy); if (!owner_name) { g_object_unref(self->priv->icproxy); self->priv->icproxy = NULL; break; } g_free(owner_name); } while(0); if (self->priv->icproxy) { g_signal_connect(self->priv->icproxy, "g-signal", G_CALLBACK(_fcitx_client_g_signal), self); g_signal_emit(user_data, signals[CONNECTED_SIGNAL], 0); } /* unref for _fcitx_client_create_ic_cb */ g_object_unref(self); }
static void on_name_owner_changed(GObject *object, GParamSpec *pspec, struct proxyParams * pp) { char * name_owner = g_dbus_proxy_get_name_owner(pp->proxy); debug("on_name_owner_changed : change %d!\n", pp->active); printProxy(pp); if (name_owner && pp->active == 0) { updateStatus(mpris_data); pp->active = 1; } else if (!name_owner && pp->active == 1) { updateStatus(mpris_data); pp->active = 0; // Free the connection used, try to get a new one : closeConnection(pp); if (createConnection(pp, G_CALLBACK(onPropertiesChanged), G_CALLBACK(on_name_owner_changed)) == -1) { debug("mpris.c : Could not re-create mpris proxy.\n"); } } printMprisData(); }
static gboolean store_is_available (void) { GDBusConnection *connection; GDBusProxy *proxy; gchar *name_owner; connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); if (!connection) { return FALSE; } proxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, "org.freedesktop.Tracker1", "/org/freedesktop/Tracker1/Status", "org.freedesktop.Tracker1.Status", NULL, NULL); if (!proxy) { g_object_unref (connection); return FALSE; } name_owner = g_dbus_proxy_get_name_owner (proxy); g_object_unref (connection); g_object_unref (proxy); if (name_owner) { g_free (name_owner); return TRUE; } return FALSE; }
static void do_write_lock(struct app *app) { GVariant *ret; GError *error = NULL; char *nameowner; nameowner = g_dbus_proxy_get_name_owner(app->proxy); if (!nameowner) { fputs("Server is not running, cannot get write lock!\n", stderr); app->ret = EXIT_FAILURE; g_main_loop_quit(app->loop); return; } printf("Server at %s, try to get write lock\n", nameowner); g_free(nameowner); g_signal_connect(app->proxy, "g-properties-changed", G_CALLBACK(on_properties_changed_check_lock), app); ret = g_dbus_proxy_call_sync(app->proxy, "RequestWriteLock", g_variant_new("()"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!ret) { fprintf(stderr, "Could not get write lock: %s\n", error->message); g_error_free(error); app->ret = EXIT_FAILURE; g_main_loop_quit(app->loop); return; } g_variant_unref(ret); puts("Got write lock, close program to release it."); }
static void on_bus_name_owner_changed (NemoDesktopManager *manager) { FETCH_PRIV (manager); gchar *name_owner; g_return_if_fail (priv->proxy != NULL); name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->proxy)); priv->proxy_owned = name_owner != NULL; if (priv->proxy_owned) { if (priv->failsafe_timeout_id > 0) { g_source_remove (priv->failsafe_timeout_id); priv->failsafe_timeout_id = 0; } } DEBUG ("New name owner: %s", name_owner ? name_owner : "unowned"); g_free (name_owner); }
static void dnsmasq_proxy_cb (GObject *source, GAsyncResult *res, gpointer user_data) { NMDnsDnsmasq *self; NMDnsDnsmasqPrivate *priv; gs_free_error GError *error = NULL; gs_free char *owner = NULL; GDBusProxy *proxy; proxy = g_dbus_proxy_new_finish (res, &error); if ( !proxy && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) return; self = NM_DNS_DNSMASQ (user_data); if (!proxy) { _LOGW ("failed to connect to dnsmasq via DBus: %s", error->message); g_signal_emit_by_name (self, NM_DNS_PLUGIN_FAILED); return; } priv = NM_DNS_DNSMASQ_GET_PRIVATE (self); priv->dnsmasq = proxy; nm_clear_g_cancellable (&priv->dnsmasq_cancellable); _LOGD ("dnsmasq proxy creation successful"); g_signal_connect (priv->dnsmasq, "notify::g-name-owner", G_CALLBACK (name_owner_changed), self); owner = g_dbus_proxy_get_name_owner (priv->dnsmasq); priv->running = (owner != NULL); if (priv->running) send_dnsmasq_update (self); }
static void on_proxy_acquired (GObject *object, GAsyncResult *res, NMSleepMonitor *self) { GError *error = NULL; char *owner; self->sd_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (!self->sd_proxy) { nm_log_warn (LOGD_SUSPEND, "Failed to acquire logind proxy: %s", error->message); g_clear_error (&error); return; } g_signal_connect (self->sd_proxy, "notify::g-name-owner", G_CALLBACK (name_owner_cb), self); _nm_dbus_signal_connect (self->sd_proxy, "PrepareForSleep", G_VARIANT_TYPE ("(b)"), G_CALLBACK (prepare_for_sleep_cb), self); owner = g_dbus_proxy_get_name_owner (self->sd_proxy); if (owner) take_inhibitor (self); g_free (owner); }
static gboolean do_delayed_print_server(gpointer data) { GDBusProxy *proxy = data; char **props; char *nameowner; nameowner = g_dbus_proxy_get_name_owner(proxy); if (!nameowner) { print_server(proxy); return FALSE; } g_free(nameowner); props = g_dbus_proxy_get_cached_property_names(proxy); if (!props) { g_timeout_add(1000, do_delayed_print_server, proxy); return FALSE; } g_strfreev(props); print_server(data); return FALSE; }
/** * secret_prompt_perform: * @self: a prompt * @window_id: XWindow id for parent window to be transient for * @return_type: the variant type of the prompt result * @cancellable: optional cancellation object * @callback: called when the operation completes * @user_data: data to be passed to the callback * * Runs a prompt and performs the prompting. Returns %TRUE if the prompt * was completed and not dismissed. * * If @window_id is non-zero then it is used as an XWindow id. The Secret * Service can make its prompt transient for the window with this id. In some * Secret Service implementations this is not possible, so the behavior * depending on this should degrade gracefully. * * This method will return immediately and complete asynchronously. */ void secret_prompt_perform (SecretPrompt *self, gulong window_id, const GVariantType *return_type, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *res; PerformClosure *closure; const gchar *owner_name; const gchar *object_path; gboolean prompted; GDBusProxy *proxy; gchar *window; g_return_if_fail (SECRET_IS_PROMPT (self)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); prompted = g_atomic_int_get (&self->pv->prompted); if (prompted) { g_warning ("The prompt object has already had its prompt called."); return; } proxy = G_DBUS_PROXY (self); res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, secret_prompt_perform); closure = g_slice_new0 (PerformClosure); closure->connection = g_object_ref (g_dbus_proxy_get_connection (proxy)); closure->call_cancellable = g_cancellable_new (); closure->async_cancellable = cancellable ? g_object_ref (cancellable) : NULL; closure->return_type = return_type ? g_variant_type_copy (return_type) : NULL; g_simple_async_result_set_op_res_gpointer (res, closure, perform_closure_free); if (window_id == 0) window = g_strdup (""); else window = g_strdup_printf ("%lu", window_id); owner_name = g_dbus_proxy_get_name_owner (proxy); object_path = g_dbus_proxy_get_object_path (proxy); closure->signal = g_dbus_connection_signal_subscribe (closure->connection, owner_name, SECRET_PROMPT_INTERFACE, SECRET_PROMPT_SIGNAL_COMPLETED, object_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, on_prompt_completed, g_object_ref (res), g_object_unref); closure->watch = g_bus_watch_name_on_connection (closure->connection, owner_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, on_prompt_vanished, g_object_ref (res), g_object_unref); if (closure->async_cancellable) { closure->cancelled_sig = g_cancellable_connect (closure->async_cancellable, G_CALLBACK (on_prompt_cancelled), res, NULL); } g_dbus_proxy_call (proxy, "Prompt", g_variant_new ("(s)", window), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, closure->call_cancellable, on_prompt_prompted, g_object_ref (res)); g_free (window); g_object_unref (res); }
int main (int argc, char **argv) { GError *local_error = NULL; GError **error = NULL; GCancellable *cancellable = NULL; gs_unref_variant GVariant *user_list = NULL; gs_unref_variant GVariant *root_account_reply = NULL; gs_unref_object GDBusProxy *accountsservice = NULL; gs_unref_object GDBusProxy *root_account_properties = NULL; gs_unref_variant GVariant *root_account_locked_reply = NULL; gs_unref_variant GVariant *root_account_locked_property = NULL; gs_unref_variant GVariant *root_account_locked_value = NULL; gs_unref_object GFile *initial_setup_done_file = NULL; const char *root_account_path = NULL; gboolean have_user_accounts; gboolean root_is_locked; #if 0 bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif initial_setup_done_file = g_file_new_for_path ("/var/initial-setup-done"); if (g_file_query_exists (initial_setup_done_file, NULL)) goto out; accountsservice = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, 0, NULL, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts", cancellable, error); if (!accountsservice) goto out; user_list = g_dbus_proxy_call_sync (accountsservice, "ListCachedUsers", NULL, 0, -1, cancellable, error); if (!user_list) goto out; have_user_accounts = g_variant_n_children (user_list) > 0; root_account_reply = g_dbus_proxy_call_sync (accountsservice, "FindUserById", g_variant_new ("(t)", (guint64)0), 0, -1, cancellable, error); if (!root_account_reply) goto out; if (!g_variant_is_of_type (root_account_reply, G_VARIANT_TYPE ("(o)"))) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unexpected return type from FindUserById"); goto out; } g_variant_get (root_account_reply, "(&o)", &root_account_path); root_account_properties = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, 0, NULL, g_dbus_proxy_get_name_owner (accountsservice), root_account_path, "org.freedesktop.DBus.Properties", cancellable, error); if (!root_account_properties) goto out; root_account_locked_reply = g_dbus_proxy_call_sync (root_account_properties, "Get", g_variant_new ("(ss)", "org.freedesktop.Accounts.User", "Locked"), 0, -1, cancellable, error); if (!root_account_locked_reply) goto out; if (!g_variant_is_of_type (root_account_locked_reply, G_VARIANT_TYPE ("(v)"))) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unexpected return type from property Get"); goto out; } g_variant_get (root_account_locked_reply, "(v)", &root_account_locked_value); root_account_locked_property = g_variant_get_variant (root_account_locked_value); if (!g_variant_is_of_type (root_account_locked_property, G_VARIANT_TYPE ("b"))) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unexpected non-boolean value for Locked"); goto out; } root_is_locked = g_variant_get_boolean (root_account_locked_property); if (!(have_user_accounts && root_is_locked)) { if (!do_initial_setup (cancellable, error)) goto out; } if (!g_file_replace_contents (initial_setup_done_file, "", 0, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, cancellable, error)) goto out; gs_log_structured_print_id_v (INITIAL_SETUP_DONE_MSGID, "Initial setup complete"); out: if (local_error != NULL) { g_printerr ("error: %s\n", local_error->message); g_error_free (local_error); return 1; } return 0; }
static void do_scan(struct app *app) { GVariantBuilder *builder; GVariant *ret; GError *error = NULL; char *nameowner; int i; GHashTable *categories; nameowner = g_dbus_proxy_get_name_owner(app->proxy); if (!nameowner) { fputs("Server is not running, cannot start scan!\n", stderr); app->ret = EXIT_FAILURE; g_main_loop_quit(app->loop); return; } printf("Server at %s, try to start scan\n", nameowner); g_free(nameowner); g_signal_connect(app->proxy, "g-properties-changed", G_CALLBACK(on_properties_changed_check_scan), app); g_signal_connect(app->proxy, "g-signal", G_CALLBACK(on_signal), app); categories = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, do_free_array); for (i = 0; i < app->argc; i++) { GArray *arr; char *arg = app->argv[i]; char *sep = strchr(arg, ':'); char *path; if (!sep) { fprintf(stderr, "Ignored scan parameter: invalid format '%s'\n", arg); continue; } *sep = '\0'; path = sep + 1; arr = g_hash_table_lookup(categories, arg); if (!arr) { arr = g_array_new(TRUE, FALSE, sizeof(char *)); g_hash_table_insert(categories, arg, arr); } if (path[0]) g_array_append_val(arr, path); } builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); g_hash_table_foreach(categories, populate_scan_params, builder); ret = g_dbus_proxy_call_sync(app->proxy, "Scan", g_variant_new("(a{sv})", builder), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); g_variant_builder_unref(builder); g_hash_table_destroy(categories); if (!ret) { fprintf(stderr, "Could not start scan: %s\n", error->message); g_error_free(error); app->ret = EXIT_FAILURE; g_main_loop_quit(app->loop); return; } g_variant_unref(ret); }