Blame SOURCES/0010-subman-Add-new-no-installed-products-state.patch

6486b0
From d53c27802c69773d63d108f57912035fd3caabf9 Mon Sep 17 00:00:00 2001
6486b0
From: Ray Strode <rstrode@redhat.com>
6486b0
Date: Sun, 24 Jan 2021 11:24:36 -0500
6486b0
Subject: [PATCH 10/15] subman: Add new no-installed-products state
6486b0
6486b0
It's possible, though unlikley, the system has
6486b0
no packages installed from Red Hat supported package sets.
6486b0
6486b0
This commit adds a new state to track that situation.
6486b0
---
6486b0
 plugins/subman/gsd-subman-common.c        |  2 ++
6486b0
 plugins/subman/gsd-subman-common.h        |  1 +
6486b0
 plugins/subman/gsd-subscription-manager.c | 17 +++++++----------
6486b0
 3 files changed, 10 insertions(+), 10 deletions(-)
6486b0
6486b0
diff --git a/plugins/subman/gsd-subman-common.c b/plugins/subman/gsd-subman-common.c
6486b0
index e515131e..eef5175d 100644
6486b0
--- a/plugins/subman/gsd-subman-common.c
6486b0
+++ b/plugins/subman/gsd-subman-common.c
6486b0
@@ -5,32 +5,34 @@
6486b0
  * This program is free software; you can redistribute it and/or modify
6486b0
  * it under the terms of the GNU General Public License as published by
6486b0
  * the Free Software Foundation; either version 2 of the License, or
6486b0
  * (at your option) any later version.
6486b0
  *
6486b0
  * This program is distributed in the hope that it will be useful,
6486b0
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
6486b0
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6486b0
  * GNU General Public License for more details.
6486b0
  *
6486b0
  * You should have received a copy of the GNU General Public License
6486b0
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
6486b0
  *
6486b0
  */
6486b0
 
6486b0
 #include "config.h"
6486b0
 
6486b0
 #include "gsd-subman-common.h"
6486b0
 
6486b0
 const gchar *
6486b0
 gsd_subman_subscription_status_to_string (GsdSubmanSubscriptionStatus status)
6486b0
 {
6486b0
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID)
6486b0
 		return "valid";
6486b0
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID)
6486b0
 		return "invalid";
6486b0
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED)
6486b0
 		return "disabled";
6486b0
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID)
6486b0
 		return "partially-valid";
6486b0
+	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS)
6486b0
+		return "no-installed-products";
6486b0
 	return "unknown";
6486b0
 }
6486b0
diff --git a/plugins/subman/gsd-subman-common.h b/plugins/subman/gsd-subman-common.h
6486b0
index fccf9f6a..f8a3d9f4 100644
6486b0
--- a/plugins/subman/gsd-subman-common.h
6486b0
+++ b/plugins/subman/gsd-subman-common.h
6486b0
@@ -3,38 +3,39 @@
6486b0
  * Copyright (C) 2019 Richard Hughes <rhughes@redhat.com>
6486b0
  *
6486b0
  * This program is free software; you can redistribute it and/or modify
6486b0
  * it under the terms of the GNU General Public License as published by
6486b0
  * the Free Software Foundation; either version 2 of the License, or
6486b0
  * (at your option) any later version.
6486b0
  *
6486b0
  * This program is distributed in the hope that it will be useful,
6486b0
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
6486b0
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6486b0
  * GNU General Public License for more details.
6486b0
  *
6486b0
  * You should have received a copy of the GNU General Public License
6486b0
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
6486b0
  *
6486b0
  */
6486b0
 
6486b0
 #ifndef __GSD_SUBMAN_COMMON_H
6486b0
 #define __GSD_SUBMAN_COMMON_H
6486b0
 
6486b0
 #include <glib-object.h>
6486b0
 
6486b0
 G_BEGIN_DECLS
6486b0
 
6486b0
 typedef enum {
6486b0
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN,
6486b0
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID,
6486b0
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID,
6486b0
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED,
6486b0
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID,
6486b0
+	GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS,
6486b0
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_LAST
6486b0
 } GsdSubmanSubscriptionStatus;
6486b0
 
6486b0
 const gchar	*gsd_subman_subscription_status_to_string	(GsdSubmanSubscriptionStatus	 status);
6486b0
 
6486b0
 G_END_DECLS
6486b0
 
6486b0
 #endif /* __GSD_SUBMAN_COMMON_H */
6486b0
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
6486b0
index 0838d490..46f8d35c 100644
6486b0
--- a/plugins/subman/gsd-subscription-manager.c
6486b0
+++ b/plugins/subman/gsd-subscription-manager.c
6486b0
@@ -242,60 +242,67 @@ _client_installed_products_update (GsdSubscriptionManager *manager, GError **err
6486b0
 		product->version = g_strdup (json_array_get_string_element (json_product, 2));
6486b0
 		product->arch = g_strdup (json_array_get_string_element (json_product, 3));
6486b0
 		product->status = g_strdup (json_array_get_string_element (json_product, 4));
6486b0
 		product->starts = g_strdup (json_array_get_string_element (json_product, 6));
6486b0
 		product->ends = g_strdup (json_array_get_string_element (json_product, 7));
6486b0
 
6486b0
 		g_ptr_array_add (priv->installed_products, g_steal_pointer (&product));
6486b0
 	}
6486b0
 
6486b0
 	/* emit notification for g-c-c */
6486b0
 	_emit_property_changed (manager, "InstalledProducts",
6486b0
 			       _make_installed_products_variant (priv->installed_products));
6486b0
 
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_subscription_status_update (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GVariant) uuid = NULL;
6486b0
 	const gchar *uuid_txt = NULL;
6486b0
 	JsonNode *json_root;
6486b0
 	JsonObject *json_obj;
6486b0
 	const gchar *json_txt = NULL;
6486b0
 	g_autoptr(GVariant) status = NULL;
6486b0
 	g_autoptr(JsonParser) json_parser = json_parser_new ();
6486b0
 
6486b0
 	/* save old value */
6486b0
 	priv->subscription_status_last = priv->subscription_status;
6486b0
+	if (!_client_installed_products_update (manager, error))
6486b0
+		goto out;
6486b0
+
6486b0
+	if (priv->installed_products->len == 0) {
6486b0
+		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS;
6486b0
+		goto out;
6486b0
+	}
6486b0
 
6486b0
 	uuid = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONSUMER],
6486b0
 				       "GetUuid",
6486b0
 				       g_variant_new ("(s)",
6486b0
 				                      "C.UTF-8"),
6486b0
 				       G_DBUS_CALL_FLAGS_NONE,
6486b0
 				       -1, NULL, error);
6486b0
 	if (uuid == NULL)
6486b0
 		return FALSE;
6486b0
 
6486b0
 	g_variant_get (uuid, "(&s)", &uuid_txt);
6486b0
 
6486b0
 	status = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
6486b0
 				         "GetStatus",
6486b0
 				         g_variant_new ("(ss)",
6486b0
 						        "", /* assumed as 'now' */
6486b0
 						        "C.UTF-8"),
6486b0
 				         G_DBUS_CALL_FLAGS_NONE,
6486b0
 				         -1, NULL, error);
6486b0
 	if (status == NULL)
6486b0
 		return FALSE;
6486b0
 	g_variant_get (status, "(&s)", &json_txt);
6486b0
 	g_debug ("Entitlement.GetStatus JSON: %s", json_txt);
6486b0
 	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
6486b0
 		return FALSE;
6486b0
 	json_root = json_parser_get_root (json_parser);
6486b0
 	json_obj = json_node_get_object (json_root);
6486b0
 	if (!json_object_has_member (json_obj, "valid")) {
6486b0
 		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
6486b0
 			     "no Entitlement.GetStatus valid in %s", json_txt);
6486b0
@@ -563,62 +570,60 @@ _client_register_with_keys (GsdSubscriptionManager *manager,
6486b0
 				       NULL);
6486b0
 	if (subprocess == NULL) {
6486b0
 		g_prefix_error (error, "failed to find pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 
6486b0
 	if (!g_subprocess_communicate (subprocess, stdin_buf, NULL, NULL, &stderr_buf, error)) {
6486b0
 		g_prefix_error (error, "failed to run pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 
6486b0
 	rc = g_subprocess_get_exit_status (subprocess);
6486b0
 	if (rc != 0) {
6486b0
 		if (g_bytes_get_size (stderr_buf) == 0) {
6486b0
 			g_set_error_literal (error, G_IO_ERROR, rc,
6486b0
 			                     "Failed to run helper without stderr");
6486b0
 			return FALSE;
6486b0
 		}
6486b0
 
6486b0
 		g_set_error (error, G_IO_ERROR, rc,
6486b0
 			     "%.*s",
6486b0
 			     g_bytes_get_size (stderr_buf),
6486b0
 			     g_bytes_get_data (stderr_buf, NULL));
6486b0
 	}
6486b0
 
6486b0
 	/* FIXME: also do on error? */
6486b0
 	if (!_client_register_stop (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
-	if (!_client_installed_products_update (manager, error))
6486b0
-		return FALSE;
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 
6486b0
 	/* success */
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_register (GsdSubscriptionManager *manager,
6486b0
 			 const gchar *hostname,
6486b0
 			 const gchar *organisation,
6486b0
 			 const gchar *username,
6486b0
 			 const gchar *password,
6486b0
 			 GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GSubprocess) subprocess = NULL;
6486b0
 	g_autoptr(GBytes) stdin_buf = g_bytes_new (password, strlen (password) + 1);
6486b0
 	g_autoptr(GBytes) stderr_buf = NULL;
6486b0
 	gint rc;
6486b0
 
6486b0
 	/* fallback */
6486b0
 	if (organisation == NULL)
6486b0
 		organisation = "";
6486b0
 
6486b0
 	/* apparently: "we can't send registration credentials over the regular
6486b0
 	 * system or session bus since those aren't really locked down..." */
6486b0
 	if (!_client_register_start (manager, error))
6486b0
 		return FALSE;
6486b0
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
6486b0
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE,
6486b0
@@ -632,62 +637,60 @@ _client_register (GsdSubscriptionManager *manager,
6486b0
 				       NULL);
6486b0
 	if (subprocess == NULL) {
6486b0
 		g_prefix_error (error, "failed to find pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 
6486b0
 	if (!g_subprocess_communicate (subprocess, stdin_buf, NULL, NULL, &stderr_buf, error)) {
6486b0
 		g_prefix_error (error, "failed to run pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 
6486b0
 	rc = g_subprocess_get_exit_status (subprocess);
6486b0
 	if (rc != 0) {
6486b0
 		if (g_bytes_get_size (stderr_buf) == 0) {
6486b0
 			g_set_error_literal (error, G_IO_ERROR, rc,
6486b0
 			                     "Failed to run helper without stderr");
6486b0
 			return FALSE;
6486b0
 		}
6486b0
 
6486b0
 		g_set_error (error, G_IO_ERROR, rc,
6486b0
 			     "%.*s",
6486b0
 			     g_bytes_get_size (stderr_buf),
6486b0
 			     g_bytes_get_data (stderr_buf, NULL));
6486b0
 	}
6486b0
 
6486b0
 	/* FIXME: also do on error? */
6486b0
 	if (!_client_register_stop (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
-	if (!_client_installed_products_update (manager, error))
6486b0
-		return FALSE;
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_unregister (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	g_autoptr(GSubprocess) subprocess = NULL;
6486b0
 
6486b0
 	/* apparently: "we can't send registration credentials over the regular
6486b0
 	 * system or session bus since those aren't really locked down..." */
6486b0
 	if (!_client_register_start (manager, error))
6486b0
 		return FALSE;
6486b0
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
6486b0
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
6486b0
 				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
6486b0
 				       "--kind", "unregister",
6486b0
 				       NULL);
6486b0
 	if (subprocess == NULL) {
6486b0
 		g_prefix_error (error, "failed to find pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 	if (!_client_subprocess_wait_check (subprocess, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_installed_products_update (manager, error))
6486b0
 		return FALSE;
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	return TRUE;
6486b0
@@ -714,64 +717,60 @@ _client_update_config (GsdSubscriptionManager *manager, GError **error)
6486b0
 	dict = g_variant_dict_new (g_variant_get_child_value (val, 0));
6486b0
 	val_server = g_variant_dict_lookup_value (dict, "server", G_VARIANT_TYPE("a{ss}"));
6486b0
 	if (val_server != NULL) {
6486b0
 		g_variant_iter_init (&iter, val_server);
6486b0
 		while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
6486b0
 			g_debug ("%s=%s", key, value);
6486b0
 			g_hash_table_insert (priv->config,
6486b0
 					     g_steal_pointer (&key),
6486b0
 					     g_steal_pointer (&value));
6486b0
 		}
6486b0
 	}
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 _subman_proxy_signal_cb (GDBusProxy *proxy,
6486b0
 			 const gchar *sender_name,
6486b0
 			 const gchar *signal_name,
6486b0
 			 GVariant *parameters,
6486b0
 			 GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	g_autoptr(GError) error = NULL;
6486b0
 	if (!_client_syspurpose_update (manager, &error)) {
6486b0
 		g_warning ("failed to update syspurpose: %s", error->message);
6486b0
 		g_clear_error (&error);
6486b0
 	}
6486b0
 	if (!_client_subscription_status_update (manager, &error)) {
6486b0
 		g_warning ("failed to update subscription status: %s", error->message);
6486b0
 		g_clear_error (&error);
6486b0
 	}
6486b0
-	if (!_client_installed_products_update (manager, &error)) {
6486b0
-		g_warning ("failed to update installed products: %s", error->message);
6486b0
-		g_clear_error (&error);
6486b0
-	}
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 _client_unload (GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++)
6486b0
 		g_clear_object (&priv->proxies[i]);
6486b0
 	g_hash_table_unref (priv->config);
6486b0
 }
6486b0
 
6486b0
 static const gchar *
6486b0
 _rhsm_interface_to_string (_RhsmInterface kind)
6486b0
 {
6486b0
 	if (kind == _RHSM_INTERFACE_CONFIG)
6486b0
 		return "Config";
6486b0
 	if (kind == _RHSM_INTERFACE_REGISTER_SERVER)
6486b0
 		return "RegisterServer";
6486b0
 	if (kind == _RHSM_INTERFACE_ATTACH)
6486b0
 		return "Attach";
6486b0
 	if (kind == _RHSM_INTERFACE_ENTITLEMENT)
6486b0
 		return "Entitlement";
6486b0
 	if (kind == _RHSM_INTERFACE_PRODUCTS)
6486b0
 		return "Products";
6486b0
 	if (kind == _RHSM_INTERFACE_CONSUMER)
6486b0
 		return "Consumer";
6486b0
 	if (kind == _RHSM_INTERFACE_SYSPURPOSE)
6486b0
 		return "Syspurpose";
6486b0
 	return NULL;
6486b0
@@ -782,62 +781,60 @@ _client_load (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 
6486b0
 	priv->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
6486b0
 
6486b0
 	/* connect to all the interfaces on the *different* objects :| */
6486b0
 	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++) {
6486b0
 		const gchar *kind = _rhsm_interface_to_string (i);
6486b0
 		g_autofree gchar *opath = g_strdup_printf ("/com/redhat/RHSM1/%s", kind);
6486b0
 		g_autofree gchar *iface = g_strdup_printf ("com.redhat.RHSM1.%s", kind);
6486b0
 		priv->proxies[i] =
6486b0
 			g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
6486b0
 						       G_DBUS_PROXY_FLAGS_NONE,
6486b0
 						       NULL,
6486b0
 						       "com.redhat.RHSM1",
6486b0
 						       opath, iface,
6486b0
 						       NULL,
6486b0
 						       error);
6486b0
 		if (priv->proxies[i] == NULL)
6486b0
 			return FALSE;
6486b0
 		/* we want to get notified if the status of the system changes */
6486b0
 		g_signal_connect (priv->proxies[i], "g-signal",
6486b0
 				  G_CALLBACK (_subman_proxy_signal_cb), manager);
6486b0
 	}
6486b0
 
6486b0
 	/* get initial status */
6486b0
 	if (!_client_update_config (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
-	if (!_client_installed_products_update (manager, error))
6486b0
-		return FALSE;
6486b0
 	if (!_client_syspurpose_update (manager, error))
6486b0
 		return FALSE;
6486b0
 
6486b0
 	/* success */
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 gboolean
6486b0
 gsd_subscription_manager_start (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	gboolean ret;
6486b0
 	g_debug ("Starting subscription manager");
6486b0
 	gnome_settings_profile_start (NULL);
6486b0
 	ret = _client_load (manager, error);
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	gnome_settings_profile_end (NULL);
6486b0
 	return ret;
6486b0
 }
6486b0
 
6486b0
 void
6486b0
 gsd_subscription_manager_stop (GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	g_debug ("Stopping subscription manager");
6486b0
 	_client_unload (manager);
6486b0
 }
6486b0
 
6486b0
 static void
6486b0
 gsd_subscription_manager_class_init (GsdSubscriptionManagerClass *klass)
6486b0
 {
6486b0
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
6486b0
-- 
6486b0
2.30.0
6486b0