/** * rpmostree_load_sysroot * @sysroot: sysroot path * @force_peer: Force a peer connection * @cancellable: A GCancellable * @out_sysroot: (out) Return location for sysroot * @error: A pointer to a GError pointer. * * Returns: True on success **/ gboolean rpmostree_load_sysroot (gchar *sysroot, gboolean force_peer, GCancellable *cancellable, RPMOSTreeSysroot **out_sysroot_proxy, GPid *out_peer_pid, GError **error) { const char *bus_name = NULL; glnx_unref_object GDBusConnection *connection = NULL; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; g_autoptr(GVariantBuilder) options_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); _cleanup_peer_ GPid peer_pid = 0; connection = get_connection_for_path (sysroot, force_peer, &peer_pid, cancellable, error); if (connection == NULL) return FALSE; if (g_dbus_connection_get_unique_name (connection) != NULL) bus_name = BUS_NAME; sysroot_proxy = rpmostree_sysroot_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, bus_name, "/org/projectatomic/rpmostree1/Sysroot", NULL, error); if (sysroot_proxy == NULL) return FALSE; /* Try to register if we can; it doesn't matter much now since the daemon doesn't * auto-exit, though that might change in the future. But only register if we're active or * root; the daemon won't allow it otherwise. */ uid_t uid = getuid (); gboolean should_register; if (uid == 0) should_register = TRUE; else { g_autofree char *state = NULL; if (sd_uid_get_state (uid, &state) >= 0) should_register = (g_strcmp0 (state, "active") == 0); else should_register = FALSE; } if (should_register) { if (!rpmostree_sysroot_call_register_client_sync (sysroot_proxy, g_variant_builder_end (options_builder), cancellable, error)) return FALSE; } *out_sysroot_proxy = g_steal_pointer (&sysroot_proxy); *out_peer_pid = peer_pid; peer_pid = 0; return TRUE; }
static void gtk_application_window_real_map (GtkWidget *widget) { GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget); /* XXX could eliminate this by tweaking gtk_window_map */ if (window->priv->menubar) gtk_widget_map (window->priv->menubar); #ifdef GDK_WINDOWING_WAYLAND { GdkWindow *gdkwindow; GtkApplication *application; application = gtk_window_get_application (GTK_WINDOW (window)); gdkwindow = gtk_widget_get_window (widget); if (GDK_IS_WAYLAND_WINDOW (gdkwindow) && window->priv->session) { gdk_wayland_window_set_dbus_properties_libgtk_only (gdkwindow, g_application_get_application_id (G_APPLICATION (application)), gtk_application_get_app_menu_object_path (application), gtk_application_get_menubar_object_path (application), window->priv->object_path, g_application_get_dbus_object_path (G_APPLICATION (application)), g_dbus_connection_get_unique_name (window->priv->session)); } } #endif GTK_WIDGET_CLASS (gtk_application_window_parent_class)->map (widget); }
static void gtk_application_window_real_realize (GtkWidget *widget) { GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget); GtkApplication *application; GtkSettings *settings; application = gtk_window_get_application (GTK_WINDOW (window)); settings = gtk_widget_get_settings (widget); g_signal_connect (settings, "notify::gtk-shell-shows-app-menu", G_CALLBACK (gtk_application_window_shell_shows_app_menu_changed), window); g_signal_connect (settings, "notify::gtk-shell-shows-menubar", G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window); if (!window->priv->muxer_initialised) { g_action_muxer_insert (G_ACTION_MUXER (window->priv->muxer), "app", G_ACTION_GROUP (application)); g_action_muxer_insert (G_ACTION_MUXER (window->priv->muxer), "win", G_ACTION_GROUP (window)); window->priv->muxer_initialised = TRUE; } gtk_application_window_update_shell_shows_app_menu (window, settings); gtk_application_window_update_shell_shows_menubar (window, settings); gtk_application_window_update_menubar (window); gtk_application_window_update_accels (window); GTK_WIDGET_CLASS (gtk_application_window_parent_class) ->realize (widget); #ifdef GDK_WINDOWING_X11 { GdkWindow *gdkwindow; gdkwindow = gtk_widget_get_window (GTK_WIDGET (window)); if (GDK_IS_X11_WINDOW (gdkwindow) && window->priv->session) { gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_ID", g_application_get_application_id (G_APPLICATION (application))); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name (window->priv->session)); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_OBJECT_PATH", g_application_get_dbus_object_path (G_APPLICATION (application))); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_WINDOW_OBJECT_PATH", window->priv->object_path); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APP_MENU_OBJECT_PATH", gtk_application_get_app_menu_object_path (application)); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_MENUBAR_OBJECT_PATH", gtk_application_get_menubar_object_path (application)); } } #endif }
static void gtk_application_window_real_realize (GtkWidget *widget) { GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget); GtkApplication *application; GtkSettings *settings; application = gtk_window_get_application (GTK_WINDOW (window)); settings = gtk_widget_get_settings (widget); g_signal_connect (settings, "notify::gtk-shell-shows-app-menu", G_CALLBACK (gtk_application_window_shell_shows_app_menu_changed), window); g_signal_connect (settings, "notify::gtk-shell-shows-menubar", G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window); gtk_application_window_update_shell_shows_app_menu (window, settings); gtk_application_window_update_shell_shows_menubar (window, settings); gtk_application_window_update_menubar (window); /* Update the accelerators, and ensure we do again * if the accel map changes */ gtk_application_window_update_accels (window); window->priv->accel_map_changed_id = g_signal_connect_swapped (gtk_accel_map_get (), "changed", G_CALLBACK (gtk_application_window_update_accels), window); GTK_WIDGET_CLASS (gtk_application_window_parent_class) ->realize (widget); #ifdef GDK_WINDOWING_X11 { GdkWindow *gdkwindow; gdkwindow = gtk_widget_get_window (GTK_WIDGET (window)); if (GDK_IS_X11_WINDOW (gdkwindow) && window->priv->session) { gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_ID", g_application_get_application_id (G_APPLICATION (application))); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name (window->priv->session)); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_OBJECT_PATH", g_application_get_dbus_object_path (G_APPLICATION (application))); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_WINDOW_OBJECT_PATH", window->priv->object_path); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APP_MENU_OBJECT_PATH", gtk_application_get_app_menu_object_path (application)); gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_MENUBAR_OBJECT_PATH", gtk_application_get_menubar_object_path (application)); } } #endif }
static void gtk_application_impl_dbus_startup (GtkApplicationImpl *impl, gboolean register_session) { GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl; static gchar *client_id; GError *error = NULL; GVariant *res; dbus->session = g_application_get_dbus_connection (G_APPLICATION (impl->application)); if (!dbus->session) return; dbus->application_id = g_application_get_application_id (G_APPLICATION (impl->application)); dbus->object_path = g_application_get_dbus_object_path (G_APPLICATION (impl->application)); dbus->unique_name = g_dbus_connection_get_unique_name (dbus->session); if (client_id == NULL) { const gchar *desktop_autostart_id; desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID"); /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to * use the same client id. */ g_unsetenv ("DESKTOP_AUTOSTART_ID"); client_id = g_strdup (desktop_autostart_id ? desktop_autostart_id : ""); } g_debug ("Connecting to session manager"); dbus->sm_proxy = g_dbus_proxy_new_sync (dbus->session, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, "org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", NULL, &error); if (error) { g_warning ("Failed to get a session proxy: %s", error->message); g_error_free (error); return; } /* FIXME: should we reuse the D-Bus application id here ? */ dbus->app_id = g_strdup (g_get_prgname ()); if (!register_session) return; g_debug ("Registering client '%s' '%s'", dbus->app_id, client_id); res = g_dbus_proxy_call_sync (dbus->sm_proxy, "RegisterClient", g_variant_new ("(ss)", dbus->app_id, client_id), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error); if (error) { g_warning ("Failed to register client: %s", error->message); g_error_free (error); g_clear_object (&dbus->sm_proxy); return; } g_variant_get (res, "(o)", &dbus->client_path); g_variant_unref (res); g_debug ("Registered client at '%s'", dbus->client_path); dbus->client_proxy = g_dbus_proxy_new_sync (dbus->session, 0, NULL, "org.gnome.SessionManager", dbus->client_path, "org.gnome.SessionManager.ClientPrivate", NULL, &error); if (error) { g_warning ("Failed to get client proxy: %s", error->message); g_error_free (error); g_clear_object (&dbus->sm_proxy); g_free (dbus->client_path); dbus->client_path = NULL; return; } g_signal_connect (dbus->client_proxy, "g-signal", G_CALLBACK (client_proxy_signal), dbus); }
gboolean rpmostree_transaction_get_response_sync (RPMOSTreeSysroot *sysroot_proxy, const char *transaction_address, GCancellable *cancellable, GError **error) { guint sigintid = 0; GDBusConnection *connection; glnx_unref_object GDBusObjectManager *object_manager = NULL; glnx_unref_object RPMOSTreeTransaction *transaction = NULL; TransactionProgress *tp = transaction_progress_new (); const char *bus_name = NULL; gint cancel_handler; gulong signal_handler = 0; gboolean success = FALSE; gboolean just_started = FALSE; connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (sysroot_proxy)); if (g_dbus_connection_get_unique_name (connection) != NULL) bus_name = BUS_NAME; /* If we are on the message bus, setup object manager connection * to notify if the owner changes. */ if (bus_name != NULL) { object_manager = rpmostree_object_manager_client_new_sync (connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, bus_name, "/org/projectatomic/rpmostree1", cancellable, error); if (object_manager == NULL) goto out; g_signal_connect (object_manager, "notify::name-owner", G_CALLBACK (on_owner_changed), tp); } transaction = rpmostree_transaction_connect (transaction_address, cancellable, error); if (!transaction) goto out; sigintid = g_unix_signal_add (SIGINT, on_sigint, cancellable); /* setup cancel handler */ cancel_handler = g_cancellable_connect (cancellable, G_CALLBACK (cancelled_handler), transaction, NULL); signal_handler = g_signal_connect (transaction, "g-signal", G_CALLBACK (on_transaction_progress), tp); /* Tell the server we're ready to receive signals. */ if (!rpmostree_transaction_call_start_sync (transaction, &just_started, cancellable, error)) goto out; /* FIXME Use the 'just_started' flag to determine whether to print * a message about reattaching to an in-progress transaction, * like: * * Existing upgrade in progress, reattaching. Control-C to cancel. * * But that requires having a printable description of the * operation. Maybe just add a string arg to this function? */ g_main_loop_run (tp->loop); g_cancellable_disconnect (cancellable, cancel_handler); if (!g_cancellable_set_error_if_cancelled (cancellable, error)) { if (tp->error) { g_propagate_error (error, tp->error); } else { success = TRUE; } } out: if (sigintid) g_source_remove (sigintid); if (signal_handler) g_signal_handler_disconnect (transaction, signal_handler); transaction_progress_free (tp); return success; }
gboolean rpmostree_load_os_proxies (RPMOSTreeSysroot *sysroot_proxy, gchar *opt_osname, GCancellable *cancellable, RPMOSTreeOS **out_os_proxy, RPMOSTreeOSExperimental **out_osexperimental_proxy, GError **error) { g_autofree char *os_object_path = NULL; if (opt_osname == NULL) os_object_path = rpmostree_sysroot_dup_booted (sysroot_proxy); if (os_object_path == NULL) { /* Usually if opt_osname is null and the property isn't populated that means the daemon isn't listen on the bus make the call anyways to get the standard error. */ if (!opt_osname) opt_osname = ""; if (!rpmostree_sysroot_call_get_os_sync (sysroot_proxy, opt_osname, &os_object_path, cancellable, error)) return FALSE; } /* owned by sysroot_proxy */ GDBusConnection *connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (sysroot_proxy)); const char *bus_name; if (g_dbus_connection_get_unique_name (connection) != NULL) bus_name = BUS_NAME; glnx_unref_object RPMOSTreeOS *os_proxy = rpmostree_os_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, bus_name, os_object_path, cancellable, error); if (os_proxy == NULL) return FALSE; glnx_unref_object RPMOSTreeOSExperimental *ret_osexperimental_proxy = NULL; if (out_osexperimental_proxy) { ret_osexperimental_proxy = rpmostree_osexperimental_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, bus_name, os_object_path, cancellable, error); if (!ret_osexperimental_proxy) return FALSE; } *out_os_proxy = g_steal_pointer (&os_proxy); if (out_osexperimental_proxy) *out_osexperimental_proxy = g_steal_pointer (&ret_osexperimental_proxy); return TRUE; }
gboolean _nm_dbus_is_connection_private (GDBusConnection *connection) { return g_dbus_connection_get_unique_name (connection) == NULL; }
static void gtk_application_impl_dbus_startup (GtkApplicationImpl *impl, gboolean register_session) { GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl; static gchar *client_id; GError *error = NULL; GVariant *res; gboolean same_bus; const char *bus_name; const char *client_interface; dbus->session = g_application_get_dbus_connection (G_APPLICATION (impl->application)); if (!dbus->session) goto out; dbus->application_id = g_application_get_application_id (G_APPLICATION (impl->application)); dbus->object_path = g_application_get_dbus_object_path (G_APPLICATION (impl->application)); dbus->unique_name = g_dbus_connection_get_unique_name (dbus->session); if (client_id == NULL) { const gchar *desktop_autostart_id; desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID"); /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to * use the same client id. */ g_unsetenv ("DESKTOP_AUTOSTART_ID"); client_id = g_strdup (desktop_autostart_id ? desktop_autostart_id : ""); } g_debug ("Connecting to session manager"); /* Try the GNOME session manager first */ dbus->sm_proxy = gtk_application_get_proxy_if_service_present (dbus->session, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, GNOME_DBUS_NAME, GNOME_DBUS_OBJECT_PATH, GNOME_DBUS_INTERFACE, &error); if (error) { g_warning ("Failed to get the GNOME session proxy: %s", error->message); g_clear_error (&error); } if (!dbus->sm_proxy) { /* Fallback to trying the Xfce session manager */ dbus->sm_proxy = gtk_application_get_proxy_if_service_present (dbus->session, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, XFCE_DBUS_NAME, XFCE_DBUS_OBJECT_PATH, XFCE_DBUS_INTERFACE, &error); if (error) { g_warning ("Failed to get the Xfce session proxy: %s", error->message); g_clear_error (&error); goto out; } } if (!register_session) goto out; g_debug ("Registering client '%s' '%s'", dbus->application_id, client_id); res = g_dbus_proxy_call_sync (dbus->sm_proxy, "RegisterClient", g_variant_new ("(ss)", dbus->application_id, client_id), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error); if (error) { g_warning ("Failed to register client: %s", error->message); g_clear_error (&error); g_clear_object (&dbus->sm_proxy); goto out; } g_variant_get (res, "(o)", &dbus->client_path); g_variant_unref (res); g_debug ("Registered client at '%s'", dbus->client_path); if (g_str_equal (g_dbus_proxy_get_name (dbus->sm_proxy), GNOME_DBUS_NAME)) { bus_name = GNOME_DBUS_NAME; client_interface = GNOME_DBUS_CLIENT_INTERFACE; } else { bus_name = XFCE_DBUS_NAME; client_interface = XFCE_DBUS_CLIENT_INTERFACE; } dbus->client_proxy = g_dbus_proxy_new_sync (dbus->session, 0, NULL, bus_name, dbus->client_path, client_interface, NULL, &error); if (error) { g_warning ("Failed to get client proxy: %s", error->message); g_clear_error (&error); g_free (dbus->client_path); dbus->client_path = NULL; goto out; } g_signal_connect (dbus->client_proxy, "g-signal", G_CALLBACK (client_proxy_signal), dbus); out: same_bus = FALSE; if (dbus->session) { const gchar *id; const gchar *id2; GValue value = G_VALUE_INIT; g_value_init (&value, G_TYPE_STRING); gdk_screen_get_setting (gdk_screen_get_default (), "gtk-session-bus-id", &value); id = g_value_get_string (&value); if (id && id[0]) { res = g_dbus_connection_call_sync (dbus->session, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetId", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); if (res) { g_variant_get (res, "(&s)", &id2); if (g_strcmp0 (id, id2) == 0) same_bus = TRUE; g_variant_unref (res); } } else same_bus = TRUE; g_value_unset (&value); } if (!same_bus) g_object_set (gtk_settings_get_default (), "gtk-shell-shows-app-menu", FALSE, "gtk-shell-shows-menubar", FALSE, NULL); if (dbus->sm_proxy == NULL) { dbus->inhibit_proxy = gtk_application_get_proxy_if_service_present (dbus->session, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.portal.Inhibit", &error); if (error) { g_warning ("Failed to get an inhibit portal proxy: %s", error->message); g_clear_error (&error); } } }