summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-11-23 01:08:19 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-11-23 01:08:19 +0000
commitc4d006d5c113daf4c02bac876bbabb47fdd1358c (patch)
tree3e10455ffa79c987f31deffd3e8b04d7d753da69
parentexec and waitpid work with lua table for each child (diff)
added cleanup function to exec child
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@57 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r--src/main_loop.lua4
-rw-r--r--src/module_list.lua5
-rw-r--r--src/modules/exec.lua9
3 files changed, 16 insertions, 2 deletions
diff --git a/src/main_loop.lua b/src/main_loop.lua
index 22809aa..2a34477 100644
--- a/src/main_loop.lua
+++ b/src/main_loop.lua
@@ -91,8 +91,8 @@ function main_loop(opt)
log.printf(log.DEBUG, "waitpid failed: " .. reason)
end
else
- log.printf(log.DEBUG, "child with pid %d stopped, reason: %s, code: %s", child.pid, reason, tostring(status))
- if(child.cleanup ~= nil) then child:cleanup() end
+ log.printf(log.DEBUG, "child with pid %d stopped, reason: %s, status: %s", child.pid, reason, status)
+ if(child.cleanup ~= nil) then child:cleanup(reason, status) end
end
elseif(err == "signal") then
-- ignore this
diff --git a/src/module_list.lua b/src/module_list.lua
index 5b35fe9..26f2ff0 100644
--- a/src/module_list.lua
+++ b/src/module_list.lua
@@ -92,6 +92,11 @@ function module_list:parse_config(module_config)
end
function module_list:unregister(module)
+ if(module == self.output) then
+ log.printf(log.WARNING, "won't remove output module: " .. module.name)
+ return
+ end
+
for i, m in ipairs(self.inputs) do
if(m == module) then
log.printf(log.INFO, "removing input module: " .. module.name)
diff --git a/src/modules/exec.lua b/src/modules/exec.lua
index 239248f..14a8856 100644
--- a/src/modules/exec.lua
+++ b/src/modules/exec.lua
@@ -131,10 +131,19 @@ function exec:new(config)
end
function client:cleanup()
util.kill(self.pid)
+ rawio.close(in_handle.fd)
+ rawio.close(out_handle.fd)
end
in_handle.client_instance = client
out_handle.client_instance = client
+ function child:cleanup(reason, status)
+ log.printf(log.INFO, "cleanup for child %d called (after %s(%s))", self.pid, reason, status)
+ -- TODO: restart programm after it stopped?
+ module_list:unregister(inst)
+ client_list:unregister(client)
+ end
+
function inst:cleanup()
client_list:unregister_by_module(self)
end