Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade agent #1368

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/rpmostree-dbus-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "rpmostree-util.h"
#include "rpmostree-rpm-util.h"

#define RPMOSTREE_CLI_ID "cli"

void
rpmostree_cleanup_peer (GPid *peer_pid)
{
Expand Down Expand Up @@ -211,6 +213,8 @@ rpmostree_load_sysroot (gchar *sysroot,
g_autoptr(GError) local_error = NULL;
g_autoptr(GVariantBuilder) options_builder =
g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (options_builder, "{sv}", "id",
g_variant_new_string (RPMOSTREE_CLI_ID));
g_autoptr(GVariant) res =
g_dbus_connection_call_sync (connection, bus_name, sysroot_objpath,
"org.projectatomic.rpmostree1.Sysroot",
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
to either invoke methods on the daemon, or monitor status.
If no clients are registered, the daemon may exit.

No options are currently defined.
'name' (type 's') - Package/component name (e.g. `cockpit`, `gnome-software`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/name/id/?

Copy link
Member Author

@cgwalters cgwalters May 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I noticed that in self-review, had already pushed a fixup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh right, sigh. I tend to do reviews by looking at each commit one at a time, and I missed the fixup! WDYT if in general we just squash fixups into the commits as long as the PR hasn't been reviewed? Fixups are really helpful for follow-up reviews, but demand extra processing for initial reviews.

-->
<method name="RegisterClient">
<arg type="a{sv}" name="options" direction="in"/>
Expand Down
20 changes: 14 additions & 6 deletions src/daemon/rpmostreed-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define EXPERIMENTAL_CONFIG_GROUP "Experimental"

struct RpmOstreeClient;
static struct RpmOstreeClient *client_new (RpmostreedDaemon *self, const char *address);
static struct RpmOstreeClient *client_new (RpmostreedDaemon *self, const char *address, const char *id);

/**
* SECTION: daemon
Expand Down Expand Up @@ -98,6 +98,7 @@ G_DEFINE_TYPE_WITH_CODE (RpmostreedDaemon, rpmostreed_daemon, G_TYPE_OBJECT,
rpmostreed_daemon_initable_iface_init))

struct RpmOstreeClient {
char *id;
char *address;
guint name_watch_id;
/* In Rust this'd be Option<uid_t> etc. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIIR? :)

Expand All @@ -113,6 +114,7 @@ rpmostree_client_free (struct RpmOstreeClient *client)
{
if (!client)
return;
g_free (client->id);
g_free (client->address);
g_free (client->sd_unit);
g_free (client);
Expand All @@ -121,10 +123,13 @@ rpmostree_client_free (struct RpmOstreeClient *client)
static char *
rpmostree_client_to_string (struct RpmOstreeClient *client)
{
g_autoptr(GString) buf = g_string_new ("client(");
if (client->id)
g_string_append_printf (buf, "id:%s ", client->id);
/* Since DBus addresses have a leading ':', let's avoid another. Yeah it's not
* symmetric, but it does read better.
*/
g_autoptr(GString) buf = g_string_new ("client(dbus");
g_string_append (buf, "dbus");
g_string_append (buf, client->address);
if (client->sd_unit)
g_string_append_printf (buf, " unit:%s", client->sd_unit);
Expand Down Expand Up @@ -246,7 +251,7 @@ on_active_txn_changed (GObject *object,
* then let's gather the relevant client info now.
*/
if (!clientdata)
clientdata = clientdata_owned = client_new (self, sender);
clientdata = clientdata_owned = client_new (self, sender, NULL);
g_autofree char *client_str = rpmostree_client_to_string (clientdata);
g_autofree char *client_data_msg = NULL;
if (clientdata->uid_valid)
Expand Down Expand Up @@ -665,10 +670,12 @@ get_client_pid (RpmostreedDaemon *self,

/* Given a DBus address, load metadata for it */
static struct RpmOstreeClient *
client_new (RpmostreedDaemon *self, const char *address)
client_new (RpmostreedDaemon *self, const char *address,
const char *client_id)
{
struct RpmOstreeClient *client = g_new0 (struct RpmOstreeClient, 1);
client->address = g_strdup (address);
client->id = g_strdup (client_id);
if (rpmostreed_get_client_uid (self, address, &client->uid))
client->uid_valid = TRUE;
if (get_client_pid (self, address, &client->pid))
Expand All @@ -685,12 +692,13 @@ client_new (RpmostreedDaemon *self, const char *address)

void
rpmostreed_daemon_add_client (RpmostreedDaemon *self,
const char *client)
const char *client,
const char *client_id)
{
if (g_hash_table_lookup (self->bus_clients, client))
return;

struct RpmOstreeClient *clientdata = client_new (self, client);
struct RpmOstreeClient *clientdata = client_new (self, client, client_id);
clientdata->name_watch_id =
g_dbus_connection_signal_subscribe (self->connection,
"org.freedesktop.DBus",
Expand Down
3 changes: 2 additions & 1 deletion src/daemon/rpmostreed-daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ gboolean rpmostreed_get_client_uid (RpmostreedDaemon *self,
const char *client,
uid_t *out_uid);
void rpmostreed_daemon_add_client (RpmostreedDaemon *self,
const char *client);
const char *client,
const char *client_id);
void rpmostreed_daemon_remove_client (RpmostreedDaemon *self,
const char *client);
char * rpmostreed_daemon_client_get_string (RpmostreedDaemon *self,
Expand Down
9 changes: 6 additions & 3 deletions src/daemon/rpmostreed-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,14 @@ handle_register_client (RPMOSTreeSysroot *object,
GDBusMethodInvocation *invocation,
GVariant *arg_options)
{
const char *sender;
sender = g_dbus_method_invocation_get_sender (invocation);
const char *sender = g_dbus_method_invocation_get_sender (invocation);
g_assert (sender);

rpmostreed_daemon_add_client (rpmostreed_daemon_get (), sender);
g_autoptr(GVariantDict) optdict = g_variant_dict_new (arg_options);
const char *client_id = NULL;
g_variant_dict_lookup (optdict, "id", "&s", &client_id);

rpmostreed_daemon_add_client (rpmostreed_daemon_get (), sender, client_id);
rpmostree_sysroot_complete_register_client (object, invocation);

return TRUE;
Expand Down