Skip to content

Commit

Permalink
daemon: Detect peer connection from GDBusConnection
Browse files Browse the repository at this point in the history
If g_dbus_connection_get_unique_name() returns a name, we're connected
to a message bus.  Otherwise we're connected directly to a peer.

Remove redundant "out" parameters from DBus helper functions.
  • Loading branch information
mbarnes committed Aug 5, 2015
1 parent 8d57e46 commit c08dabc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 39 deletions.
8 changes: 3 additions & 5 deletions src/app/rpmostree-builtin-rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ rpmostree_builtin_rebase (int argc,
GError **error)
{
gboolean ret = FALSE;
gboolean is_peer = FALSE;
const char *new_provided_refspec;

/* forced blank for now */
Expand All @@ -86,11 +85,10 @@ rpmostree_builtin_rebase (int argc,
cancellable,
&connection,
&sysroot_proxy,
&is_peer,
error))
goto out;

if (!rpmostree_load_os_proxy (sysroot_proxy, NULL, is_peer,
if (!rpmostree_load_os_proxy (sysroot_proxy, NULL,
cancellable, &os_proxy, error))
goto out;

Expand Down Expand Up @@ -133,8 +131,8 @@ rpmostree_builtin_rebase (int argc,
ret = TRUE;

out:
if (is_peer)
rpmostree_cleanup_peer ();
/* Does nothing if using the message bus. */
rpmostree_cleanup_peer ();

return ret;
}
8 changes: 3 additions & 5 deletions src/app/rpmostree-builtin-rollback.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ rpmostree_builtin_rollback (int argc,
GError **error)
{
gboolean ret = FALSE;
gboolean is_peer = FALSE;

GOptionContext *context = g_option_context_new ("- Revert to the previously booted tree");
glnx_unref_object GDBusConnection *connection = NULL;
Expand All @@ -64,11 +63,10 @@ rpmostree_builtin_rollback (int argc,
cancellable,
&connection,
&sysroot_proxy,
&is_peer,
error))
goto out;

if (!rpmostree_load_os_proxy (sysroot_proxy, NULL, is_peer,
if (!rpmostree_load_os_proxy (sysroot_proxy, NULL,
cancellable, &os_proxy, error))
goto out;

Expand Down Expand Up @@ -104,8 +102,8 @@ rpmostree_builtin_rollback (int argc,
ret = TRUE;

out:
if (is_peer)
rpmostree_cleanup_peer ();
/* Does nothing if using the message bus. */
rpmostree_cleanup_peer ();

return ret;
}
8 changes: 3 additions & 5 deletions src/app/rpmostree-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ rpmostree_builtin_status (int argc,
GError **error)
{
gboolean ret = FALSE;
gboolean is_peer = FALSE;
GOptionContext *context = g_option_context_new ("- Get the version of the booted system");
glnx_unref_object GDBusConnection *connection = NULL;
glnx_unref_object RPMOSTreeOS *os_proxy = NULL;
Expand Down Expand Up @@ -94,11 +93,10 @@ rpmostree_builtin_status (int argc,
cancellable,
&connection,
&sysroot_proxy,
&is_peer,
error))
goto out;

if (!rpmostree_load_os_proxy (sysroot_proxy, NULL, is_peer,
if (!rpmostree_load_os_proxy (sysroot_proxy, NULL,
cancellable, &os_proxy, error))
goto out;

Expand Down Expand Up @@ -254,8 +252,8 @@ rpmostree_builtin_status (int argc,
ret = TRUE;

out:
if (is_peer)
rpmostree_cleanup_peer ();
/* Does nothing if using the message bus. */
rpmostree_cleanup_peer ();

return ret;
}
8 changes: 3 additions & 5 deletions src/app/rpmostree-builtin-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ rpmostree_builtin_upgrade (int argc,
GError **error)
{
gboolean ret = FALSE;
gboolean is_peer = FALSE;

GOptionContext *context = g_option_context_new ("- Perform a system upgrade");
glnx_unref_object GDBusConnection *connection = NULL;
Expand All @@ -93,11 +92,10 @@ rpmostree_builtin_upgrade (int argc,
cancellable,
&connection,
&sysroot_proxy,
&is_peer,
error))
goto out;

if (!rpmostree_load_os_proxy (sysroot_proxy, NULL, is_peer,
if (!rpmostree_load_os_proxy (sysroot_proxy, NULL,
cancellable, &os_proxy, error))
goto out;

Expand Down Expand Up @@ -207,8 +205,8 @@ rpmostree_builtin_upgrade (int argc,
ret = TRUE;

out:
if (is_peer)
rpmostree_cleanup_peer ();
/* Does nothing if using the message bus. */
rpmostree_cleanup_peer ();

return ret;
}
35 changes: 18 additions & 17 deletions src/app/rpmostree-dbus-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ get_connection_for_path (gchar *sysroot,
gboolean force_peer,
GCancellable *cancellable,
GDBusConnection **out_connection,
gboolean *out_is_peer,
GError **error)
{
glnx_unref_object GDBusConnection *connection = NULL;
Expand All @@ -53,7 +52,6 @@ get_connection_for_path (gchar *sysroot,

int pair[2];
gboolean ret = FALSE;
gboolean is_peer = FALSE;

const gchar *args[] = {
"rpm-ostreed",
Expand All @@ -72,7 +70,6 @@ get_connection_for_path (gchar *sysroot,
}

g_print ("Running in single user mode. Be sure no other users are modifying the system\n");
is_peer = TRUE;
if (socketpair (AF_UNIX, SOCK_STREAM, 0, pair) < 0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
Expand Down Expand Up @@ -109,7 +106,6 @@ get_connection_for_path (gchar *sysroot,
{
ret = TRUE;
*out_connection = g_steal_pointer (&connection);
*out_is_peer = is_peer;
}
return ret;
}
Expand All @@ -122,7 +118,6 @@ get_connection_for_path (gchar *sysroot,
* @cancellable: A GCancellable
* @out_connection: (out) Return location for connection.
* @out_sysroot: (out) Return location for sysroot
* @out_is_peer: (out) indicates if connection is connected to a peer.
* @error: A pointer to a GError pointer.
*
* Returns: True on success
Expand All @@ -133,33 +128,33 @@ rpmostree_load_connection_and_sysroot (gchar *sysroot,
GCancellable *cancellable,
GDBusConnection **out_connection,
RPMOSTreeSysroot **out_sysroot_proxy,
gboolean *out_is_peer,
GError **error)
{
gboolean ret = FALSE;
gboolean is_peer = FALSE;
const char *bus_name = NULL;
glnx_unref_object GDBusConnection *connection = NULL;
glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL;

if (!get_connection_for_path (sysroot,
force_peer,
cancellable,
&connection,
&is_peer,
error))
goto out;

if (g_dbus_connection_get_unique_name (connection) != NULL)
bus_name = BUS_NAME;

sysroot_proxy = rpmostree_sysroot_proxy_new_sync (connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
is_peer ? NULL : BUS_NAME,
bus_name,
"/org/projectatomic/rpmostree1/Sysroot",
NULL,
error);
if (sysroot_proxy == NULL)
goto out;

*out_connection = g_steal_pointer (&connection);
*out_is_peer = is_peer;
*out_sysroot_proxy = g_steal_pointer (&sysroot_proxy);
ret = TRUE;

Expand All @@ -170,12 +165,12 @@ rpmostree_load_connection_and_sysroot (gchar *sysroot,
gboolean
rpmostree_load_os_proxy (RPMOSTreeSysroot *sysroot_proxy,
gchar *opt_osname,
gboolean is_peer,
GCancellable *cancellable,
RPMOSTreeOS **out_os_proxy,
GError **error)
{
gboolean ret = FALSE;
const char *bus_name;
g_autofree char *os_object_path = NULL;
glnx_unref_object RPMOSTreeOS *os_proxy = NULL;

Expand Down Expand Up @@ -204,9 +199,13 @@ rpmostree_load_os_proxy (RPMOSTreeSysroot *sysroot_proxy,
}

connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (sysroot_proxy));

if (g_dbus_connection_get_unique_name (connection) != NULL)
bus_name = BUS_NAME;

os_proxy = rpmostree_os_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
is_peer ? NULL : BUS_NAME,
bus_name,
os_object_path,
cancellable,
error);
Expand Down Expand Up @@ -507,20 +506,22 @@ rpmostree_transaction_get_response_sync (GDBusConnection *connection,

TransactionProgress *tp = transaction_progress_new ();

const char *bus_name;
gint cancel_handler;
gboolean is_peer = TRUE;
gulong property_handler = 0;
gulong signal_handler = 0;
gboolean success = FALSE;

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 (g_dbus_connection_get_unique_name (connection) != NULL)
if (bus_name != NULL)
{
is_peer = FALSE;
object_manager = rpmostree_object_manager_client_new_sync (connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
BUS_NAME,
bus_name,
"/org/projectatomic/rpmostree1",
cancellable,
error);
Expand All @@ -536,7 +537,7 @@ rpmostree_transaction_get_response_sync (GDBusConnection *connection,

transaction = rpmostree_transaction_proxy_new_sync (connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
is_peer ? NULL : BUS_NAME,
bus_name,
object_path,
cancellable,
error);
Expand Down
2 changes: 0 additions & 2 deletions src/app/rpmostree-dbus-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ rpmostree_load_connection_and_sysroot (gchar *sysroot,
GCancellable *cancellable,
GDBusConnection **out_connection,
RPMOSTreeSysroot **out_manager,
gboolean *out_is_peer,
GError **error);

gboolean
rpmostree_load_os_proxy (RPMOSTreeSysroot *sysroot_proxy,
gchar *opt_osname,
gboolean is_peer,
GCancellable *cancellable,
RPMOSTreeOS **out_os_proxy,
GError **error);
Expand Down

0 comments on commit c08dabc

Please sign in to comment.