From c4d006d5c113daf4c02bac876bbabb47fdd1358c Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 23 Nov 2010 01:08:19 +0000 Subject: added cleanup function to exec child git-svn-id: https://svn.spreadspace.org/gcsd/trunk@57 ac14a137-c7f1-4531-abe0-07747231d213 --- src/main_loop.lua | 4 ++-- src/module_list.lua | 5 +++++ src/modules/exec.lua | 9 +++++++++ 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 -- cgit v1.2.3