summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2014-03-13 11:21:30 +1300
committerRobert Ancell <robert.ancell@canonical.com>2014-03-13 11:21:30 +1300
commitd9c97174a27e51c47d21e5c4a3201d4bbd2ef421 (patch)
tree4f7cbc0fda9d6fa36dc7cf96782c83dd040f6c1e
parent7488ac6105a8096993e1605b75768f8ffbb7e62c (diff)
downloadlightdm-git-d9c97174a27e51c47d21e5c4a3201d4bbd2ef421.tar.gz
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 4d1f1d6a..d7a0452a 100644
--- a/src/greeter.c
+++ b/src/greeter.c
@@ -64,6 +64,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);
@@ -529,6 +530,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;
}
@@ -658,7 +660,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]);
@@ -723,6 +725,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 5fe11e72..2a73ad84 100644
--- a/src/process.c
+++ b/src/process.c
@@ -130,6 +130,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))
@@ -137,10 +138,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 473ef92a..0ef7f194 100644
--- a/src/session.c
+++ b/src/session.c
@@ -216,6 +216,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 03c9134a..f64d22dd 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;
}