}
Task::Status ExternalTask::check()
+{
+ return do_wait(false);
+}
+
+Task::Status ExternalTask::wait()
+{
+ return do_wait(true);
+}
+
+Task::Status ExternalTask::do_wait(bool block)
{
if(pid>0)
{
- // XXX This is sub-optimal, should have support for a blocking wait
int status;
- if(waitpid(pid, &status, WNOHANG)==pid)
+ if(waitpid(pid, &status, (block ? 0 : WNOHANG))==pid)
{
if(WIFEXITED(status))
exit_code = WEXITSTATUS(status);
task.set_stdout(CAPTURE);
task.set_stderr(IGNORE);
task.start();
- Task::Status status;
- while((status=task.check())==RUNNING) ;
- if(status!=SUCCESS)
+ if(task.wait()!=SUCCESS)
throw runtime_error(format("%s failed", argv.front()));
return task.get_output();
}
virtual std::string get_command() const;
virtual void start();
virtual Status check();
+ Status wait();
+private:
+ Status do_wait(bool);
+public:
void set_stdout(Destination);
void set_stderr(Destination);
const std::string &get_output() const { return output; }