diff options
-rw-r--r-- | include/InPipe.h | 4 | ||||
-rw-r--r-- | include/LuaTask.h | 4 | ||||
-rw-r--r-- | lib/InPipe.cc | 13 | ||||
-rw-r--r-- | lib/LuaTask.cc | 33 |
4 files changed, 44 insertions, 10 deletions
diff --git a/include/InPipe.h b/include/InPipe.h index 2828da3..7b77c4e 100644 --- a/include/InPipe.h +++ b/include/InPipe.h @@ -12,8 +12,10 @@ class InPipe : public Handle { virtual bool CanWrite(); virtual bool CanRead(); virtual String GetName(); + void HalfClose(); private: - int p[2], hooked; + int p[2]; + bool hooked, halfclosed; }; #endif diff --git a/include/LuaTask.h b/include/LuaTask.h index 85e228f..fcc1363 100644 --- a/include/LuaTask.h +++ b/include/LuaTask.h @@ -4,6 +4,7 @@ #include <Task.h> #include <Buffer.h> #include <BLua.h> +#include <InPipe.h> class LuaTask : public Task { public: @@ -16,9 +17,10 @@ class LuaTask : public Task { private: Lua * L; String cmd; - int nargs, stacktop; + int nargs, stacktop, r; Task * c; Buffer * b; + InPipe * p; String task; 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; |