X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fexternalaction.cpp;h=6989f69bbe017c113ad3aa7fc3b7a9d6cec7a9b4;hb=835948343817c0e359330f8522dc4b8a0e025224;hp=5d01f4f701071fd4b330b26618b897899a59110d;hpb=a2adbd9c0a8d7a7567848c4c6bdbf0de6ba32bb1;p=builder.git diff --git a/source/externalaction.cpp b/source/externalaction.cpp index 5d01f4f..6989f69 100644 --- a/source/externalaction.cpp +++ b/source/externalaction.cpp @@ -1,21 +1,52 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include -#include #include #include +#include #include +#include +#include #include "builder.h" #include "externalaction.h" using namespace std; using namespace Msp; +void ExternalAction::launch() +{ + if(builder.get_verbose()>=2) + IO::print("%s\n", join(argv.begin(), argv.end())); + + if(builder.get_dry_run()) + pid = -1; + else + { + pid = fork(); + if(pid==0) + { + char *argv_[argv.size()+1]; + + unsigned j = 0; + for(StringList::iterator i=argv.begin(); i!=argv.end(); ++i) + argv_[j++] = strdup(i->c_str()); + argv_[j] = 0; + + if(!work_dir.empty()) + FS::chdir(work_dir); + execvp(argv_[0], argv_); + IO::print("Couldn't execute %s\n", argv.front()); + exit(1); + } + else if(pid<0) + pid = 0; + } +} + int ExternalAction::check() { if(builder.get_dry_run()) @@ -32,53 +63,12 @@ int ExternalAction::check() { signal_done.emit(); if(WIFEXITED(status)) - exit_code=WEXITSTATUS(status); + exit_code = WEXITSTATUS(status); else - exit_code=254; - pid=0; + 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) - { - for(StringList::const_iterator i=argv.begin(); i!=argv.end(); ++i) - { - if(i!=argv.begin()) - cout<<' '; - cout<<*i; - } - cout<<'\n'; - } - - if(builder.get_dry_run()) - pid=-1; - else - { - pid=fork(); - if(pid==0) - { - char *argv_[argv.size()+1]; - - unsigned j=0; - for(StringList::iterator i=argv.begin(); i!=argv.end(); ++i) - 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 "<