From 60260fb81339dc9960c998dd046b8ea4948db9f8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 30 Aug 2014 23:53:59 -0400 Subject: [PATCH] Hooks - Removed obsolete ::execute method, instead relying on the util.cpp variant. --- src/Hooks.cpp | 75 +++++++-------------------------------------------- src/Hooks.h | 1 - 2 files changed, 9 insertions(+), 67 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 0d78b6101..0fc9bb5f1 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -38,6 +38,7 @@ #include #include #include +#include extern Context context; @@ -90,7 +91,8 @@ void Hooks::onLaunch () for (i = matchingScripts.begin (); i != matchingScripts.end (); ++i) { std::string output; - int status = execute (*i, "", output); + std::vector args; + int status = execute (*i, args, "", output); std::vector lines; split (lines, output, '\n'); @@ -146,7 +148,8 @@ bool Hooks::onExit () for (i = matchingScripts.begin (); i != matchingScripts.end (); ++i) { std::string output; - int status = execute (*i, "", output); + std::vector args; + int status = execute (*i, args, "", output); std::vector lines; split (lines, output, '\n'); @@ -206,7 +209,8 @@ void Hooks::onAdd (Task& after) { std::string input = after.composeJSON () + "\n"; std::string output; - int status = execute (*i, input, output); + std::vector args; + int status = execute (*i, args, input, output); std::vector lines; split (lines, output, '\n'); @@ -280,7 +284,8 @@ void Hooks::onModify (const Task& before, Task& after) + afterJSON + "\n"; std::string output; - int status = execute (*i, input, output); + std::vector args; + int status = execute (*i, args, input, output); std::vector lines; split (lines, output, '\n'); @@ -347,65 +352,3 @@ std::vector Hooks::scripts (const std::string& event) } //////////////////////////////////////////////////////////////////////////////// -int Hooks::execute ( - const std::string& command, - const std::string& input, - std::string& output) -{ - // TODO Improve error handling. - // TODO Check errors. - - int pin[2], pout[2]; - pipe (pin); - pipe (pout); - - pid_t pid = fork(); - if (!pid) - { - // This is only reached in the child - dup2 (pin[0], STDIN_FILENO); - dup2 (pout[1], STDOUT_FILENO); - if (! execl (command.c_str (), command.c_str (), (char*) NULL)) - exit (1); - } - - // This is only reached in the parent - close (pin[0]); - close (pout[1]); - - // Write input to fp. - FILE* pinf = fdopen (pin[1], "w"); - if (input != "" && - input != "\n") - { - fputs (input.c_str (), pinf); - } - - fclose (pinf); - close (pin[1]); - - // Read output from fp. - output = ""; - char* line = NULL; - size_t len = 0; - FILE* poutf = fdopen(pout[0], "r"); - while (getline (&line, &len, poutf) != -1) - { - output += line; - } - - free (line); - line = NULL; - fclose (poutf); - close (pout[0]); - - int status = -1; - wait (&status); - if (WIFEXITED (status)) - status = WEXITSTATUS (status); - - context.debug (format ("Hooks::execute {1} (status {2})", command, status)); - return status; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Hooks.h b/src/Hooks.h index 69dbfe1f8..f646de123 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -49,7 +49,6 @@ public: private: std::vector scripts (const std::string&); - int execute (const std::string&, const std::string&, std::string&); private: std::vector _scripts;