Added bgread destroying on unloading
Though it is still broken - it waits for process termination...
--- a/main.c Sat Aug 01 23:05:11 2009 +0300
+++ b/main.c Wed Oct 14 13:37:40 2009 +0300
@@ -1051,16 +1051,20 @@
typedef struct {
lua_State *L;
+ guint source;
FILE *fd;
int reference;
} lua_bgread_callback_t;
+static GSList *lua_bgreads = NULL;
+
static gchar lua_bgread_buffer[MLUA_BGREAD_BUFFER];
static void lua_bgread_callback_destroy (lua_bgread_callback_t *cb)
{
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference);
- pclose (cb->fd);
+ pclose (cb->fd); // Not necessary?
+ lua_bgreads = g_slist_remove (lua_bgreads, (gpointer) cb->source);
luaL_free (cb->L, cb);
}
@@ -1118,6 +1122,7 @@
FILE *fd;
GIOChannel *channel;
const char *charset = NULL;
+ guint source;
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
fd = popen (command, "r");
@@ -1141,7 +1146,10 @@
cb->L = L;
cb->fd = fd;
- g_io_add_watch_full (channel, MLUA_SOURCE_PRIORITY, G_IO_IN|G_IO_HUP|G_IO_ERR, (GIOFunc) lua_bgread_callback, cb, (GDestroyNotify) lua_bgread_callback_destroy);
+ source = g_io_add_watch_full (channel, MLUA_SOURCE_PRIORITY, G_IO_IN|G_IO_HUP|G_IO_ERR, (GIOFunc) lua_bgread_callback, cb, (GDestroyNotify) lua_bgread_callback_destroy);
+ cb->source = source;
+ lua_bgreads = g_slist_prepend (lua_bgreads, (gpointer) source);
+
return 0;
}
@@ -1319,6 +1327,11 @@
evs_del (event->id);
}
+static void lua_bgreads_destroy (guint source, gpointer ignore)
+{
+ g_source_remove (source);
+}
+
static void lua_timers_destroy (guint source, gpointer ignore)
{
g_source_remove (source);
@@ -1356,6 +1369,10 @@
hk_del_handler ((hk_handler_t) lua_hook, lua);
+ g_slist_foreach (lua_bgreads, (GFunc) lua_bgreads_destroy, NULL);
+ g_slist_free (lua_bgreads);
+ lua_bgreads = NULL;
+
g_slist_foreach (lua_timers, (GFunc) lua_timers_destroy, NULL);
g_slist_free (lua_timers);
lua_timers = NULL;