[packagekit] Monitoring transactions for required restarts

Guido Berhoerster guido+freedesktop.org at berhoerster.name
Thu Jul 5 21:52:09 UTC 2018


Hi,

I'd like to monitor whether PackageKit transactions initiated by other
tools necessitate a restart. So I am adopting transactions and call
pk_results_get_require_restart_worst() on the transaction results in the
completion callback. However it always returns PK_RESTART_ENUM_UNKNOWN
even when it clearly shouldn't, i.e. when running "pkcon update" against
the dummy backend.
Is this the right way to achieve what I want or am I doing something
wrong?
I've been testing on Debian Stretch (PackageKit 1.1.5). A minimal
program to reproduce is as follows:

----8<----
#include <stdlib.h>
#include <glib.h>
#include <packagekit-glib2/packagekit.h>

PkClient	*pk_client;

static void
on_transaction_adopt_finish(GObject *source_object, GAsyncResult *result,
    gpointer user_data)
{
	PkClient	*pk_client = PK_CLIENT(source_object);
	PkResults	*results;
	GError		*error = NULL;
	PkRoleEnum	role;
	PkRestartEnum	restart;

	results = pk_client_generic_finish(pk_client, result, &error);
	if (results == NULL) {
		g_warning("failed to adopt transaction: %s",
		    error->message);
		g_error_free(error);
		goto out;
	}

	role = pk_results_get_role(results);
	g_message("transaction finished: %s", pk_role_enum_to_string(role));

	/* check if transaction requires a restart */
	restart = pk_results_get_require_restart_worst(results);
	g_message("required restart: %s", pk_restart_enum_to_string(restart));

out:
	if (results != NULL) {
		g_object_unref(results);
	}
}

static void
on_transaction_list_added(PkTransactionList *transaction_list,
    const gchar *transaction_id, gpointer user_data)
{
	/* adopt transaction in order to monitor it for restart requirements */
	pk_client_adopt_async(pk_client, transaction_id, NULL, NULL,
	    NULL, on_transaction_adopt_finish, user_data);
}

int
main(int argc, char *argv[])
{
	GMainLoop	*loop;
	PkTransactionList *transaction_list;

	loop = g_main_loop_new (NULL, FALSE);

	pk_client = pk_client_new();

	transaction_list = pk_transaction_list_new();
	g_signal_connect(transaction_list, "added",
	    G_CALLBACK(on_transaction_list_added), NULL);

	g_main_loop_run(loop);
}
---->8----

Thanks,
-- 
Guido Berhoerster


More information about the PackageKit mailing list