]> ruin.nu Git - popboot.git/blobdiff - action.cpp
Spelling fix in inittab
[popboot.git] / action.cpp
index 87947ca054bb6684bfe9e23e006a16ff94df7c6c..5dbe86954cbbd29644ba710d35dd8585b2774c62 100644 (file)
@@ -1,4 +1,7 @@
 #include "action.h"
+#include <cstdlib>
+#include <unistd.h>
+#include <sys/wait.h>
 #include <iostream>
 using namespace std;
 using namespace __gnu_cxx;
@@ -16,6 +19,7 @@ Action::Action(const Action& action){
        _name = action._name;
        _preconditions = action._preconditions;
        _effects = action._effects;
+       _executable = action._executable;
 }
 
 const Literals& Action::effects(int value) const{
@@ -30,8 +34,20 @@ const Preconditions& Action::preconditions() const{
 }
 
 int Action::execute() const{
-       cout << "Executing: " << _executable << endl;
-       return 0;
+       cout << "Executing: " << _name << endl;
+       //return system(_executable.c_str());
+       pid_t proc = fork();
+       if (proc == -1) return proc;
+
+       int retval;
+       if (proc == 0) {
+               //execl("/bin/sh",  "-c", _executable.c_str(), (char*) NULL);
+               retval = system(_executable.c_str());
+               _exit(WEXITSTATUS(retval));
+       }
+       waitpid(proc,&retval,0);
+       cout << "Done executing: " << _name << ", returnvalue: " << WEXITSTATUS(retval) << endl;
+       return WEXITSTATUS(retval);
 }
 
 const string& Action::name() const{