summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-11-22 20:23:01 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-11-22 20:23:01 +0000
commitbda86a863894c75776221d132cfd4770495601aa (patch)
tree4223f194ccf4beea7303d43dd10563efeb5d8915 /src
parentadded initial exec module (diff)
added kill to util
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@53 ac14a137-c7f1-4531-abe0-07747231d213
Diffstat (limited to 'src')
-rw-r--r--src/l_util.c52
-rw-r--r--src/modules/exec.lua2
2 files changed, 53 insertions, 1 deletions
diff --git a/src/l_util.c b/src/l_util.c
index 9cce024..5321f91 100644
--- a/src/l_util.c
+++ b/src/l_util.c
@@ -459,11 +459,63 @@ static int l_util_pipe(lua_State *L)
return 2;
}
+static int l_util_kill(lua_State *L)
+{
+ int pid = luaL_checkint(L, 1);
+ const char* signame = luaL_optstring(L, 2, "term");
+ int sig = SIGTERM;
+
+ if(!strcasecmp(signame, "HUP")) sig = SIGHUP;
+ else if(!strcasecmp(signame, "INT")) sig = SIGINT;
+ else if(!strcasecmp(signame, "QUIT")) sig = SIGQUIT;
+ else if(!strcasecmp(signame, "ILL")) sig = SIGILL;
+ else if(!strcasecmp(signame, "TRAP")) sig = SIGTRAP;
+ else if(!strcasecmp(signame, "ABRT")) sig = SIGABRT;
+ else if(!strcasecmp(signame, "IOT")) sig = SIGIOT;
+ else if(!strcasecmp(signame, "BUS")) sig = SIGBUS;
+ else if(!strcasecmp(signame, "FPE")) sig = SIGFPE;
+ else if(!strcasecmp(signame, "KILL")) sig = SIGKILL;
+ else if(!strcasecmp(signame, "USR1")) sig = SIGUSR1;
+ else if(!strcasecmp(signame, "SEGV")) sig = SIGSEGV;
+ else if(!strcasecmp(signame, "USR2")) sig = SIGUSR2;
+ else if(!strcasecmp(signame, "PIPE")) sig = SIGPIPE;
+ else if(!strcasecmp(signame, "ALRM")) sig = SIGALRM;
+ else if(!strcasecmp(signame, "TERM")) sig = SIGTERM;
+ else if(!strcasecmp(signame, "STKFLT")) sig = SIGSTKFLT;
+ else if(!strcasecmp(signame, "CLD")) sig = SIGCLD;
+ else if(!strcasecmp(signame, "CHLD")) sig = SIGCHLD;
+ else if(!strcasecmp(signame, "CONT")) sig = SIGCONT;
+ else if(!strcasecmp(signame, "STOP")) sig = SIGSTOP;
+ else if(!strcasecmp(signame, "TSTP")) sig = SIGTSTP;
+ else if(!strcasecmp(signame, "TTIN")) sig = SIGTTIN;
+ else if(!strcasecmp(signame, "TTOU")) sig = SIGTTOU;
+ else if(!strcasecmp(signame, "URG")) sig = SIGURG;
+ else if(!strcasecmp(signame, "XCPU")) sig = SIGXCPU;
+ else if(!strcasecmp(signame, "XFSZ")) sig = SIGXFSZ;
+ else if(!strcasecmp(signame, "VTALRM")) sig = SIGVTALRM;
+ else if(!strcasecmp(signame, "PROF")) sig = SIGPROF;
+ else if(!strcasecmp(signame, "WINCH")) sig = SIGWINCH;
+ else if(!strcasecmp(signame, "POLL")) sig = SIGPOLL;
+ else if(!strcasecmp(signame, "IO")) sig = SIGIO;
+ else if(!strcasecmp(signame, "PWR")) sig = SIGPWR;
+ else if(!strcasecmp(signame, "SYS")) sig = SIGSYS;
+ else if(!strcasecmp(signame, "UNUSED")) sig = SIGUNUSED;
+
+ if(kill(pid, sig) == -1) {
+ lua_pushnil(L);
+ lua_pushstring(L, strerror(errno)); // FIXXXXXME: strerror is not threadsafe!!!
+ return 2;
+ }
+ lua_pushboolean(L, 1);
+ return 1;
+}
+
static const struct luaL_reg util_funcs [] = {
{ "select", l_util_select },
{ "exec", l_util_exec },
{ "waitpid", l_util_waitpid },
{ "pipe", l_util_pipe },
+ { "kill", l_util_kill },
{ NULL, NULL }
};
diff --git a/src/modules/exec.lua b/src/modules/exec.lua
index b819b6f..765fdb6 100644
--- a/src/modules/exec.lua
+++ b/src/modules/exec.lua
@@ -128,7 +128,7 @@ function exec:new(config)
end
end
function client:cleanup()
- -- TODO: kill child
+ util.kill(pid)
end
in_handle.client_instance = client
out_handle.client_instance = client