diff options
author | pixel <pixel> | 2007-05-24 18:02:22 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-05-24 18:02:22 +0000 |
commit | f5f42523c696b79935c67a56ae6a86d310e4b95f (patch) | |
tree | 7e4b03fb814d51bbac40df22ae020c3f0f303ffb /lib | |
parent | ce53fd2fcf346abe0114522c1df5186dc57b7043 (diff) |
LuaTask's "Command" is now able to return the stdout's output.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/InPipe.cc | 13 | ||||
-rw-r--r-- | lib/LuaTask.cc | 33 |
2 files changed, 38 insertions, 8 deletions
diff --git a/lib/InPipe.cc b/lib/InPipe.cc index efcab10..4a69b5e 100644 --- a/lib/InPipe.cc +++ b/lib/InPipe.cc @@ -5,10 +5,10 @@ #include "Output.h" #include "gettext.h" -InPipe::InPipe() : Handle(pipe(p, 0)), hooked(0) { +InPipe::InPipe() : Handle(pipe(p, 0)), hooked(false), halfclosed(false) { } -InPipe::InPipe(const InPipe & i) : Handle(i), hooked(i.hooked) { +InPipe::InPipe(const InPipe & i) : Handle(i), hooked(i.hooked), halfclosed(i.halfclosed) { p[0] = GetHandle(); p[1] = dup(i.p[1]); } @@ -22,13 +22,20 @@ InPipe::~InPipe() { void InPipe::Hook() { if (!hooked) { - hooked = 1; + hooked = true; ::close(1); dup(p[1]); ::close(p[1]); } } +void InPipe::HalfClose() { + if (!halfclosed) { + ::close(p[1]); + halfclosed = true; + } +} + bool InPipe::CanWrite() { return false; } diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc index 4d9cca6..a0fe0c3 100644 --- a/lib/LuaTask.cc +++ b/lib/LuaTask.cc @@ -1,8 +1,12 @@ #include <LuaTask.h> #include <LuaHandle.h> +#include <TaskMan.h> #ifndef LUATASK_OMIT_HTTPCLIENT #include <HttpClient.h> #endif +#ifndef LUATASK_OMIT_COMMAND +#include <CopyJob.h> +#endif LuaTask * LuaTask::top = 0; @@ -60,7 +64,11 @@ int LuaTask::Do() throw (GeneralException) { #ifndef LUATASK_OMIT_COMMAND if (task == "Command") { - nargs = 0; + delete p; + printm(M_INFO, "Got there (end of command - should)\n"); + LuaBuffer o(b); + o.pushdestruct(L); + nargs = 1; } #endif @@ -90,7 +98,7 @@ int LuaTask::Do() throw (GeneralException) { #endif #ifndef LUATASK_OMIT_COMMAND } else if (task == "Command") { - pid_t p; + pid_t pid; int i; char * cmd; @@ -105,14 +113,20 @@ int LuaTask::Do() throw (GeneralException) { } args[L->gettop() - 1] = 0; - if (!(p = fork())) { + b = new Buffer(true); + p = new InPipe(); + + if (!(pid = fork())) { + p->Hook(); execvp(cmd, args); } - WaitFor(p); + c = new CopyJob(p, b); for (i = 3; i <= L->gettop(); i++) { - free(args[i - 3]); + free(args[i - 2]); } free(cmd); + current = 3; + WaitFor(pid); Suspend(TASK_ON_HOLD); #endif } else { @@ -122,6 +136,15 @@ int LuaTask::Do() throw (GeneralException) { } else { return TASK_DONE; } + break; +#ifndef LUATASK_OMIT_COMMAND + case 3: + printm(M_INFO, "Got here (case 3), and event = %i\n", TaskMan::Event()); + current = 2; + WaitFor(c); + p->HalfClose(); + return TASK_ON_HOLD; +#endif } return TASK_ON_HOLD; |