summaryrefslogtreecommitdiff
diff options
authorRobert Ancell <robert.ancell@canonical.com>2014-03-13 10:58:19 +1300
committerRobert Ancell <robert.ancell@canonical.com>2014-03-13 10:58:19 +1300
commit267a6f85e4308fbd537bf0e7eb38c8e8bf17d036 (patch)
treee2905bc6a82e5265437925c5df9923d0732abde0
parent1a0ad37c4f82b65276aac7059682954e25615864 (diff)
Correctly manage GSources
-rw-r--r--src/greeter.c6
-rw-r--r--src/process.c5
-rw-r--r--src/session.c1
-rw-r--r--src/xdmcp-server.c5
-rw-r--r--tests/src/test-runner.c3
5 files changed, 14 insertions, 6 deletions
diff --git a/src/greeter.c b/src/greeter.c
index 7128481d..9f3b7f46 100644
--- a/src/greeter.c
+++ b/src/greeter.c
@@ -68,6 +68,7 @@ struct GreeterPrivate
/* Communication channels to communicate with */
GIOChannel *to_greeter_channel;
GIOChannel *from_greeter_channel;
+ guint from_greeter_watch;
};
G_DEFINE_TYPE (Greeter, greeter, G_TYPE_OBJECT);
@@ -622,6 +623,7 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data)
if (condition == G_IO_HUP)
{
g_debug ("Greeter closed communication channel");
+ greeter->priv->from_greeter_watch = 0;
return FALSE;
}
@@ -757,7 +759,7 @@ greeter_start (Greeter *greeter, const gchar *service, const gchar *username)
greeter->priv->from_greeter_channel = g_io_channel_unix_new (from_greeter_pipe[0]);
g_io_channel_set_encoding (greeter->priv->from_greeter_channel, NULL, NULL);
g_io_channel_set_buffered (greeter->priv->from_greeter_channel, FALSE);
- g_io_add_watch (greeter->priv->from_greeter_channel, G_IO_IN | G_IO_HUP, read_cb, greeter);
+ greeter->priv->from_greeter_watch = g_io_add_watch (greeter->priv->from_greeter_channel, G_IO_IN | G_IO_HUP, read_cb, greeter);
/* Let the greeter session know how to communicate with the daemon */
value = g_strdup_printf ("%d", from_greeter_pipe[1]);
@@ -823,6 +825,8 @@ greeter_finalize (GObject *object)
g_io_channel_unref (self->priv->to_greeter_channel);
if (self->priv->from_greeter_channel)
g_io_channel_unref (self->priv->from_greeter_channel);
+ if (self->priv->from_greeter_watch)
+ g_source_remove (self->priv->from_greeter_watch);
G_OBJECT_CLASS (greeter_parent_class)->finalize (object);
}
diff --git a/src/process.c b/src/process.c
index e4978f5b..766a639e 100644
--- a/src/process.c
+++ b/src/process.c
@@ -131,6 +131,7 @@ process_watch_cb (GPid pid, gint status, gpointer data)
{
Process *process = data;
+ process->priv->watch = 0;
process->priv->exit_status = status;
if (WIFEXITED (status))
@@ -138,10 +139,6 @@ process_watch_cb (GPid pid, gint status, gpointer data)
else if (WIFSIGNALED (status))
g_debug ("Process %d terminated with signal %d", pid, WTERMSIG (status));
- if (process->priv->watch)
- g_source_remove (process->priv->watch);
- process->priv->watch = 0;
-
if (process->priv->quit_timeout)
g_source_remove (process->priv->quit_timeout);
process->priv->quit_timeout = 0;
diff --git a/src/session.c b/src/session.c
index fd2af4cc..3e54ea5b 100644
--- a/src/session.c
+++ b/src/session.c
@@ -220,6 +220,7 @@ session_watch_cb (GPid pid, gint status, gpointer data)
Session *session = data;
session->priv->pid = 0;
+ session->priv->child_watch = 0;
if (WIFEXITED (status))
g_debug ("Session %d exited with return value %d", pid, WEXITSTATUS (status));
diff --git a/src/xdmcp-server.c b/src/xdmcp-server.c
index b92df9c9..d1770589 100644
--- a/src/xdmcp-server.c
+++ b/src/xdmcp-server.c
@@ -117,6 +117,8 @@ xdmcp_server_set_key (XDMCPServer *server, const gchar *key)
static gboolean
session_timeout_cb (XDMCPSession *session)
{
+ session->priv->inactive_timeout = 0;
+
g_debug ("Timing out unmanaged session %d", session->priv->id);
g_hash_table_remove (session->priv->server->priv->sessions, GINT_TO_POINTER ((gint) session->priv->id));
return FALSE;
@@ -517,7 +519,8 @@ handle_manage (XDMCPServer *server, GSocket *socket, GSocketAddress *address, XD
if (result)
{
/* Cancel the inactive timer */
- g_source_remove (session->priv->inactive_timeout);
+ if (session->priv->inactive_timeout)
+ g_source_remove (session->priv->inactive_timeout);
session->priv->started = TRUE;
}
diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c
index dcbfd0fc..91a70089 100644
--- a/tests/src/test-runner.c
+++ b/tests/src/test-runner.c
@@ -131,9 +131,12 @@ kill_timeout_cb (gpointer data)
{
Process *process = data;
+ process->kill_timeout = 0;
+
if (getenv ("DEBUG"))
g_print ("Sending SIGKILL to process %d\n", process->pid);
kill (process->pid, SIGKILL);
+
return FALSE;
}