diff options
author | pixel <pixel> | 2007-05-24 13:53:11 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-05-24 13:53:11 +0000 |
commit | ce53fd2fcf346abe0114522c1df5186dc57b7043 (patch) | |
tree | 8ac092b0059b0a293367e0cf116d048c95541f88 | |
parent | ca5717feeec139896ff37374d24e714f876819a4 (diff) |
Adding the "Command" LuaTask.
-rw-r--r-- | lib/LuaTask.cc | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc index ac3df8d..4d9cca6 100644 --- a/lib/LuaTask.cc +++ b/lib/LuaTask.cc @@ -46,7 +46,8 @@ int LuaTask::Do() throw (GeneralException) { L->resume(nargs); } case 1: - if (c) { + case 2: + if (current == 2) { int nargs = 0; #ifndef LUATASK_OMIT_HTTPCLIENT @@ -57,11 +58,19 @@ int LuaTask::Do() throw (GeneralException) { } #endif - delete c; +#ifndef LUATASK_OMIT_COMMAND + if (task == "Command") { + nargs = 0; + } +#endif + + if (!c) + delete c; c = 0; L->resume(nargs); } + current = 2; if (L->gettop() >= 1) { task = L->tostring(1); if (task == "") { @@ -79,6 +88,33 @@ int LuaTask::Do() throw (GeneralException) { WaitFor(c); Suspend(TASK_ON_HOLD); #endif +#ifndef LUATASK_OMIT_COMMAND + } else if (task == "Command") { + pid_t p; + int i; + + char * cmd; + char ** args, ** ptr; + + cmd = L->tostring(2).strdup(); + + args = (char **) malloc(sizeof(char *) * (L->gettop() - 1)); + args[0] = cmd; + for (i = 3; i <= L->gettop(); i++) { + args[i - 2] = L->tostring(i).strdup(); + } + args[L->gettop() - 1] = 0; + + if (!(p = fork())) { + execvp(cmd, args); + } + WaitFor(p); + for (i = 3; i <= L->gettop(); i++) { + free(args[i - 3]); + } + free(cmd); + Suspend(TASK_ON_HOLD); +#endif } else { L->error("Unknow requested task: " + task); return TASK_DONE; |