#include <sys/wait.h>
#include <iostream>
-#include <msp/iter.h>
#include "builder.h"
#include "externalaction.h"
signal_done.emit();
return 0;
}
-
+
if(!pid)
- return 255;
+ return exit_code;
int status;
if(waitpid(pid, &status, WNOHANG)==pid)
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)
{
- for(list<string>::const_iterator i=argv.begin(); i!=argv.end(); ++i)
+ for(StringList::const_iterator i=argv.begin(); i!=argv.end(); ++i)
{
if(i!=argv.begin())
cout<<' ';
}
cout<<'\n';
}
-
+
if(builder.get_dry_run())
pid=-1;
else
if(pid==0)
{
char *argv_[argv.size()+1];
- for(CountingIterator<string, list<string>::iterator> i=argv.begin(); i!=argv.end(); ++i)
- argv_[i.count()]=strdup(i->c_str());
- argv_[argv.size()]=0;
+
+ unsigned j=0;
+ for(StringList::iterator i=argv.begin(); i!=argv.end(); ++i)
+ argv_[j++]=strdup(i->c_str());
+ argv_[j]=0;
+
execvp(argv_[0], argv_);
+ cout<<"Couldn't execute "<<argv.front()<<'\n';
exit(1);
}
else if(pid<0)