Skip to content

Commit

Permalink
apt: debconf-helper: Cleanup properly when exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed Mar 23, 2024
1 parent 3605809 commit 401e1c5
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions backends/apt/pk-debconf-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <packagekit-glib2/pk-client-helper.h>
#include <systemd/sd-daemon.h>

static GMainLoop *main_loop;
static PkClientHelper *helper;
static GMainLoop *main_loop = NULL;
static PkClientHelper *helper = NULL;

static gboolean exit_loop(gpointer user_data)
{
Expand All @@ -19,36 +19,40 @@ static gboolean exit_loop(gpointer user_data)

int main(void)
{
char **argv = NULL;
char **envp = NULL;
GSocket *socket = NULL;
GError *error = NULL;
g_auto(GStrv) argv = NULL;
g_auto(GStrv) envp = NULL;
g_autoptr(GSocket) socket = NULL;
g_autoptr(GError) error = NULL;
int fd = -1;

main_loop = g_main_loop_new(NULL, FALSE);
pk_client_create_helper_argv_envp(&argv, &envp);
main_loop = g_main_loop_new (NULL, FALSE);
pk_client_create_helper_argv_envp (&argv, &envp);


if (sd_listen_fds(0) != 1) {
if (sd_listen_fds (0) != 1) {
g_error("No or too many file descriptors received.\n");
exit(1);
}

fd = SD_LISTEN_FDS_START + 0;
socket = g_socket_new_from_fd(fd, &error);
socket = g_socket_new_from_fd (fd, &error);

if (error != NULL) {
g_error("%s\n", error->message);
g_error ("%s\n", error->message);
return 1;
}

helper = pk_client_helper_new();
if (!pk_client_helper_start_with_socket(helper, socket, argv, envp, &error)) {
g_error("%s\n", error->message);
helper = pk_client_helper_new ();
if (!pk_client_helper_start_with_socket (helper, socket, argv, envp, &error)) {
g_error ("%s\n", error->message);
return 1;
}

g_timeout_add_seconds(60, exit_loop, NULL);
g_timeout_add_seconds (60, exit_loop, NULL);

g_main_loop_run(main_loop);
g_main_loop_run (main_loop);

g_object_unref (helper);
g_object_unref (main_loop);
return 0;
}

0 comments on commit 401e1c5

Please sign in to comment.