[packagekit] [PATCH] Spawn debconf-kde-frontend when KDE is running
Matthias Klumpp
matthias at nlinux.org
Wed Dec 8 09:37:01 PST 2010
Hi!
Could you please review the following patch, before I commit it to PK?
The patch makes the debkonf tool handle the Debconf process in
pk-client-helper instead of debconf-communicate if the tool is found and
KDE is running.
Thanks!
Matthias
diff --git a/lib/packagekit-glib2/pk-client-helper.c
b/lib/packagekit-glib2/pk-client-helper.c
index fd440ac..ba71e65 100644
--- a/lib/packagekit-glib2/pk-client-helper.c
+++ b/lib/packagekit-glib2/pk-client-helper.c
@@ -110,19 +110,21 @@ pk_client_helper_stop (PkClientHelper
*client_helper, GError **error)
g_return_val_if_fail (priv->socket_file != NULL, FALSE);
/* close the socket */
- ret = g_socket_close (priv->socket, error);
- if (!ret)
- goto out;
+ if (priv->socket) {
+ ret = g_socket_close (priv->socket, error);
+ if (!ret)
+ goto out;
- /* stop watching for events */
- if (priv->io_channel_socket_listen_id > 0)
- g_source_remove (priv->io_channel_socket_listen_id);
- if (priv->io_channel_child_stdout_listen_id > 0)
- g_source_remove (priv->io_channel_child_stdout_listen_id);
- if (priv->io_channel_child_stderr_listen_id > 0)
- g_source_remove (priv->io_channel_child_stderr_listen_id);
- if (priv->io_channel_child_stdin_listen_id > 0)
- g_source_remove (priv->io_channel_child_stdin_listen_id);
+ /* stop watching for events */
+ if (priv->io_channel_socket_listen_id > 0)
+ g_source_remove (priv->io_channel_socket_listen_id);
+ if (priv->io_channel_child_stdout_listen_id > 0)
+ g_source_remove (priv->io_channel_child_stdout_listen_id);
+ if (priv->io_channel_child_stderr_listen_id > 0)
+ g_source_remove (priv->io_channel_child_stderr_listen_id);
+ if (priv->io_channel_child_stdin_listen_id > 0)
+ g_source_remove (priv->io_channel_child_stdin_listen_id);
+ }
/* kill process */
if (priv->child_pid > 0) {
@@ -138,10 +140,15 @@ pk_client_helper_stop (PkClientHelper
*client_helper, GError **error)
}
}
+ /* when we're here, everything worked fine */
+ ret = TRUE;
+
/* remove any socket file */
- ret = g_file_delete (priv->socket_file, NULL, error);
- if (!ret)
- goto out;
+ if (g_file_query_exists (priv->socket_file, NULL)) {
+ ret = g_file_delete (priv->socket_file, NULL, error);
+ if (!ret)
+ goto out;
+ }
out:
return ret;
}
@@ -437,7 +444,10 @@ pk_client_helper_start (PkClientHelper
*client_helper,
gchar **argv, gchar **envp,
GError **error)
{
+ guint i;
gboolean ret = FALSE;
+ gboolean use_debkonf = FALSE;
+ GError *error_local = NULL;
gint fd;
GSocketAddress *address = NULL;
PkClientHelperPrivate *priv = client_helper->priv;
@@ -459,13 +469,20 @@ pk_client_helper_start (PkClientHelper
*client_helper,
}
g_debug ("using socket in %s", socket_filename);
+ priv->socket_file = g_file_new_for_path (socket_filename);
+
+ /* preconfigure KDE frontend, if requested */
+ for (i=0; envp[i] != NULL; i++) {
+ if (g_strcmp0 (envp[i], "DEBIAN_FRONTEND=kde") == 0)
+ if (g_file_test ("/usr/bin/debkonf", G_FILE_TEST_EXISTS))
+ use_debkonf = TRUE;
+ }
/* cache for actual start */
- priv->argv = g_strdupv (argv);
priv->envp = g_strdupv (envp);
+ priv->argv = g_strdupv (argv);
/* create socket */
- priv->socket_file = g_file_new_for_path (socket_filename);
priv->socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_DEFAULT, error);
if (priv->socket == NULL)
goto out;
@@ -476,6 +493,23 @@ pk_client_helper_start (PkClientHelper
*client_helper,
if (!ret)
goto out;
+ /* spawn KDE debconf communicator */
+ if (use_debkonf) {
+ priv->argv = g_new0 (gchar *, 2);
+ priv->argv[0] = g_strdup ("/usr/bin/debkonf");
+ priv->argv[1] = g_strconcat ("--socket-path", "=", socket_filename,
NULL);
+
+ ret = g_spawn_async (NULL, priv->argv, NULL,
G_SPAWN_STDOUT_TO_DEV_NULL,
+ NULL, NULL, &priv->child_pid, &error_local);
+ if (!ret) {
+ g_warning ("failed to spawn: %s", error_local->message);
+ g_error_free (error_local);
+ goto out;
+ }
+ g_debug ("started process %s with pid %i", priv->argv[0],
priv->child_pid);
+ goto out;
+ }
+
/* listen to the socket */
ret = g_socket_listen (priv->socket, error);
if (!ret)
More information about the PackageKit
mailing list