diff --git a/src/daemon/os.c b/src/daemon/os.c index 64f5720b..6aadaa17 100644 --- a/src/daemon/os.c +++ b/src/daemon/os.c @@ -817,7 +817,11 @@ osstub_handle_pull_dir (RPMOSTreeOS *interface, goto out; transaction = transaction_monitor_new_transaction (os->transaction_monitor, - invocation, cancellable); + invocation, cancellable, + &local_error); + + if (transaction == NULL) + goto out; data = g_slice_new0 (TaskData); data->sysroot = g_object_ref (sysroot); @@ -857,7 +861,11 @@ osstub_handle_deploy (RPMOSTreeOS *interface, goto out; transaction = transaction_monitor_new_transaction (os->transaction_monitor, - invocation, cancellable); + invocation, cancellable, + &local_error); + + if (transaction == NULL) + goto out; data = g_slice_new0 (TaskData); data->sysroot = g_object_ref (sysroot); @@ -959,7 +967,11 @@ osstub_handle_rollback (RPMOSTreeOS *interface, goto out; transaction = transaction_monitor_new_transaction (os->transaction_monitor, - invocation, cancellable); + invocation, cancellable, + &local_error); + + if (transaction == NULL) + goto out; data = g_slice_new0 (TaskData); data->sysroot = g_object_ref (sysroot); @@ -998,7 +1010,11 @@ osstub_handle_clear_rollback_target (RPMOSTreeOS *interface, goto out; transaction = transaction_monitor_new_transaction (os->transaction_monitor, - invocation, cancellable); + invocation, cancellable, + &local_error); + + if (transaction == NULL) + goto out; data = g_slice_new0 (TaskData); data->sysroot = g_object_ref (sysroot); diff --git a/src/daemon/transaction-monitor.c b/src/daemon/transaction-monitor.c index d6bd7a29..dc0f54bd 100644 --- a/src/daemon/transaction-monitor.c +++ b/src/daemon/transaction-monitor.c @@ -184,7 +184,8 @@ transaction_monitor_new (void) RPMOSTreeTransaction * transaction_monitor_new_transaction (TransactionMonitor *monitor, GDBusMethodInvocation *invocation, - GCancellable *method_cancellable) + GCancellable *cancellable, + GError **error) { RPMOSTreeTransaction *transaction; const char *object_path; @@ -193,7 +194,10 @@ transaction_monitor_new_transaction (TransactionMonitor *monitor, g_return_val_if_fail (IS_TRANSACTION_MONITOR (monitor), NULL); g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL); - transaction = transaction_new (invocation, method_cancellable); + transaction = transaction_new (invocation, cancellable, error); + + if (transaction == NULL) + goto out; g_signal_connect_object (transaction, "notify::active", G_CALLBACK (transaction_monitor_notify_active_cb), @@ -219,6 +223,7 @@ transaction_monitor_new_transaction (TransactionMonitor *monitor, g_queue_push_head (monitor->transactions, g_object_ref (transaction)); g_object_notify (G_OBJECT (monitor), "active-transaction"); +out: return transaction; } diff --git a/src/daemon/transaction-monitor.h b/src/daemon/transaction-monitor.h index 9298cf17..d8246447 100644 --- a/src/daemon/transaction-monitor.h +++ b/src/daemon/transaction-monitor.h @@ -32,7 +32,8 @@ RPMOSTreeTransaction * transaction_monitor_new_transaction (TransactionMonitor *monitor, GDBusMethodInvocation *invocation, - GCancellable *method_cancellable); + GCancellable *cancellable, + GError **error); RPMOSTreeTransaction * transaction_monitor_ref_active_transaction (TransactionMonitor *monitor); diff --git a/src/daemon/transaction.c b/src/daemon/transaction.c index 66f0613b..f8714b52 100644 --- a/src/daemon/transaction.c +++ b/src/daemon/transaction.c @@ -29,7 +29,7 @@ typedef struct _TransactionClass TransactionClass; struct _Transaction { RPMOSTreeTransactionSkeleton parent; - GCancellable *method_cancellable; + GCancellable *cancellable; gboolean success; char *message; @@ -43,8 +43,7 @@ struct _TransactionClass }; enum { - PROP_0, - PROP_CANCELLABLE + PROP_0 }; enum { @@ -56,12 +55,15 @@ enum { static guint signals[LAST_SIGNAL]; -static void transaction_iface_init (RPMOSTreeTransactionIface *iface); +static void transaction_initable_iface_init (GInitableIface *iface); +static void transaction_dbus_iface_init (RPMOSTreeTransactionIface *iface); G_DEFINE_TYPE_WITH_CODE (Transaction, transaction, RPMOSTREE_TYPE_TRANSACTION_SKELETON, + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, + transaction_initable_iface_init) G_IMPLEMENT_INTERFACE (RPMOSTREE_TYPE_TRANSACTION, - transaction_iface_init)) + transaction_dbus_iface_init)) static gboolean transaction_check_sender_is_owner (RPMOSTreeTransaction *transaction, @@ -215,9 +217,6 @@ transaction_set_property (GObject *object, switch (property_id) { - case PROP_CANCELLABLE: - transaction->method_cancellable = g_value_dup_object (value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -234,9 +233,6 @@ transaction_get_property (GObject *object, switch (property_id) { - case PROP_CANCELLABLE: - g_value_set_object (value, transaction->method_cancellable); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -248,7 +244,7 @@ transaction_dispose (GObject *object) { Transaction *transaction = TRANSACTION (object); - g_clear_object (&transaction->method_cancellable); + g_clear_object (&transaction->cancellable); G_OBJECT_CLASS (transaction_parent_class)->dispose (object); } @@ -266,13 +262,26 @@ transaction_finalize (GObject *object) G_OBJECT_CLASS (transaction_parent_class)->finalize (object); } +static gboolean +transaction_initable_init (GInitable *initable, + GCancellable *cancellable, + GError **error) +{ + Transaction *transaction = TRANSACTION (initable); + + if (G_IS_CANCELLABLE (cancellable)) + transaction->cancellable = g_object_ref (cancellable); + + return TRUE; +} + static gboolean transaction_handle_cancel (RPMOSTreeTransaction *transaction, GDBusMethodInvocation *invocation) { Transaction *real_transaction = TRANSACTION (transaction); - if (real_transaction->method_cancellable == NULL) + if (real_transaction->cancellable == NULL) return FALSE; if (!transaction_check_sender_is_owner (transaction, invocation)) @@ -284,7 +293,7 @@ transaction_handle_cancel (RPMOSTreeTransaction *transaction, } else { - g_cancellable_cancel (real_transaction->method_cancellable); + g_cancellable_cancel (real_transaction->cancellable); g_signal_emit (transaction, signals[CANCELLED], 0); rpmostree_transaction_complete_cancel (transaction, invocation); } @@ -335,16 +344,6 @@ transaction_class_init (TransactionClass *class) object_class->dispose = transaction_dispose; object_class->finalize = transaction_finalize; - g_object_class_install_property (object_class, - PROP_CANCELLABLE, - g_param_spec_object ("cancellable", - NULL, - NULL, - G_TYPE_CANCELLABLE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - signals[CANCELLED] = g_signal_new ("cancelled", TYPE_TRANSACTION, G_SIGNAL_RUN_LAST, @@ -365,7 +364,13 @@ transaction_class_init (TransactionClass *class) } static void -transaction_iface_init (RPMOSTreeTransactionIface *iface) +transaction_initable_iface_init (GInitableIface *iface) +{ + iface->init = transaction_initable_init; +} + +static void +transaction_dbus_iface_init (RPMOSTreeTransactionIface *iface) { iface->handle_cancel = transaction_handle_cancel; iface->handle_finish = transaction_handle_finish; @@ -378,7 +383,8 @@ transaction_init (Transaction *transaction) RPMOSTreeTransaction * transaction_new (GDBusMethodInvocation *invocation, - GCancellable *method_cancellable) + GCancellable *cancellable, + GError **error) { Transaction *transaction; GDBusConnection *connection; @@ -390,12 +396,15 @@ transaction_new (GDBusMethodInvocation *invocation, method_name = g_dbus_method_invocation_get_method_name (invocation); sender = g_dbus_method_invocation_get_sender (invocation); - transaction = g_object_new (TYPE_TRANSACTION, - "cancellable", method_cancellable, - "method-name", method_name, - "owner", sender, - "active", TRUE, - NULL); + transaction = g_initable_new (TYPE_TRANSACTION, + cancellable, error, + "method-name", method_name, + "owner", sender, + "active", TRUE, + NULL); + + if (transaction == NULL) + goto out; /* XXX Would be handy if GDBusInterfaceSkeleton had an export() * class method so subclasses can know when a GDBusConnection @@ -412,7 +421,8 @@ transaction_new (GDBusMethodInvocation *invocation, transaction, NULL); - return RPMOSTREE_TRANSACTION (transaction); +out: + return (RPMOSTreeTransaction *) transaction; } void diff --git a/src/daemon/transaction.h b/src/daemon/transaction.h index c9735dfa..511daddd 100644 --- a/src/daemon/transaction.h +++ b/src/daemon/transaction.h @@ -27,7 +27,8 @@ GType transaction_get_type (void) G_GNUC_CONST; RPMOSTreeTransaction * transaction_new (GDBusMethodInvocation *invocation, - GCancellable *method_cancellable); + GCancellable *cancellable, + GError **error); void transaction_done (RPMOSTreeTransaction *transaction, gboolean success, const char *message);