Unverified Commit 467c688d authored by Dapa's avatar Dapa Committed by GitHub

Update daemon.cpp

parent f6d6623c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <string> #include <string.h>
using namespace std; using namespace std;
...@@ -11,11 +11,21 @@ int command(const char *cmd) { ...@@ -11,11 +11,21 @@ int command(const char *cmd) {
if ((pid = fork())) { if ((pid = fork())) {
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
} else { } else {
execl("/bin/bash", "/bin/bash", "-c", cmd, NULL); char *env = new char[2048]; // fingers crossed this is enough
strcpy(env, "PATH=");
strcat(env, getenv("PATH"));
strcat(env, ":");
strcat(env, getenv("HOME"));
strcat(env, "/.virtualenv/bin");
env[strlen(env)+1] = '\0';
execl("/bin/bash", "/bin/bash", "-c", cmd, NULL, env);
} }
return status; return status;
} }
int main() { int main() {
cout << command("cd ~/.virtualenv/bin && PATH=$(pwd):$PATH && while [ 1 ]; do timeout 45m service; sleep 15m; done") << std::endl; while(1)
{
cout << command("service > /dev/null") << std::endl;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment