]> git.tdb.fi Git - builder.git/blobdiff - source/externalaction.cpp
Reorder class members
[builder.git] / source / externalaction.cpp
index de799e4c550877e91927d8b85bcd5596d2b9b3f0..88c7e544e7907671daa82a6d8381f29f46257356 100644 (file)
@@ -1,40 +1,21 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <sys/wait.h>
 #include <iostream>
+#include <cstring>
+#include <cstdlib>
+#include <msp/fs/dir.h>
 #include "builder.h"
 #include "externalaction.h"
 
 using namespace std;
 using namespace Msp;
 
-int ExternalAction::check()
-{
-       if(builder.get_dry_run())
-       {
-               signal_done.emit();
-               return 0;
-       }
-
-       if(!pid)
-               return exit_code;
-
-       int status;
-       if(waitpid(pid, &status, WNOHANG)==pid)
-       {
-               signal_done.emit();
-               if(WIFEXITED(status))
-                       exit_code=WEXITSTATUS(status);
-               else
-                       exit_code=254;
-               pid=0;
-               return exit_code;
-       }
-       else
-               return -1;
-}
-
-/**
-Starts the external program.  Fill in argv before calling this.
-*/
 void ExternalAction::launch()
 {
        if(builder.get_verbose()>=2)
@@ -62,6 +43,8 @@ void ExternalAction::launch()
                                argv_[j++]=strdup(i->c_str());
                        argv_[j]=0;
 
+                       if(!work_dir.empty())
+                               FS::chdir(work_dir);
                        execvp(argv_[0], argv_);
                        cout<<"Couldn't execute "<<argv.front()<<'\n';
                        exit(1);
@@ -70,3 +53,29 @@ void ExternalAction::launch()
                        pid=0;
        }
 }
+
+int ExternalAction::check()
+{
+       if(builder.get_dry_run())
+       {
+               signal_done.emit();
+               return 0;
+       }
+
+       if(!pid)
+               return exit_code;
+
+       int status;
+       if(waitpid(pid, &status, WNOHANG)==pid)
+       {
+               signal_done.emit();
+               if(WIFEXITED(status))
+                       exit_code=WEXITSTATUS(status);
+               else
+                       exit_code=254;
+               pid=0;
+               return exit_code;
+       }
+       else
+               return -1;
+}