diff --git a/src/laminar.cpp b/src/laminar.cpp index 6793480..59db5b4 100644 --- a/src/laminar.cpp +++ b/src/laminar.cpp @@ -557,13 +557,13 @@ void Laminar::assignNewJobs() { if(nodeCanQueue(node, *run)) { int buildNum = buildNums[run->name] + 1; - // create a working directory (different to a workspace!) - fs::path wd = fs::path(homeDir)/"run"/run->name/std::to_string(buildNum); - if(!fs::create_directory(wd)) { - LLOG(ERROR, "Could not create working directory", wd.string()); + // create the run directory (different to a workspace!) + fs::path rd = fs::path(homeDir)/"run"/run->name/std::to_string(buildNum); + if(!fs::create_directory(rd)) { + LLOG(ERROR, "Could not create working directory", rd.string()); break; } - run->wd = wd.string(); + run->runDir = rd.string(); // create an archive directory fs::path archive = fs::path(homeDir)/"archive"/run->name/std::to_string(buildNum); if(fs::is_directory(archive)) { @@ -723,8 +723,8 @@ void Laminar::runFinished(Run * r) { waiter.release(r->result); waiters.erase(r); - // remove the workdir - fs::remove_all(r->wd); + // remove the rundir + fs::remove_all(r->runDir); // will delete the job activeJobs.get<2>().erase(r); diff --git a/src/run.cpp b/src/run.cpp index 0da97ed..766cec0 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -59,7 +59,7 @@ std::string Run::reason() const { } bool Run::step() { - if(!currentScript.empty() && procStatus != 0) + if(!currentScript.path.empty() && procStatus != 0) result = RunState::FAILED; if(scripts.size()) { @@ -87,7 +87,7 @@ bool Run::step() { PATH.append(p); } - chdir(wd.c_str()); + chdir(currentScript.cwd.c_str()); for(std::string file : env) { StringMap vars = parseConfFile(file.c_str()); @@ -108,14 +108,14 @@ bool Run::step() { for(auto& pair : params) { setenv(pair.first.c_str(), pair.second.c_str(), false); } - fprintf(stderr, "[laminar] Executing %s\n", currentScript.c_str()); - execl(currentScript.c_str(), currentScript.c_str(), NULL); + fprintf(stderr, "[laminar] Executing %s\n", currentScript.path.c_str()); + execl(currentScript.path.c_str(), currentScript.path.c_str(), NULL); // cannot use LLOG because stdout/stderr are captured - fprintf(stderr, "[laminar] Failed to execute %s\n", currentScript.c_str()); + fprintf(stderr, "[laminar] Failed to execute %s\n", currentScript.path.c_str()); _exit(1); } - LLOG(INFO, "Forked", currentScript, pid); + LLOG(INFO, "Forked", currentScript.path, currentScript.cwd, pid); close(pfd[1]); fd = pfd[0]; this->pid = pid; @@ -125,8 +125,8 @@ bool Run::step() { return true; } } -void Run::addScript(std::string script) { - scripts.push(script); +void Run::addScript(std::string scriptPath, std::string scriptWorkingDir) { + scripts.push({scriptPath, scriptWorkingDir}); } void Run::addEnv(std::string path) { env.push_back(path); diff --git a/src/run.h b/src/run.h index 4637706..136519a 100644 --- a/src/run.h +++ b/src/run.h @@ -57,7 +57,10 @@ public: void complete(); // adds a script to the queue of scripts to be executed by this run - void addScript(std::string script); + void addScript(std::string scriptPath, std::string scriptWorkingDir); + + // adds a script to the queue using the runDir as the scripts CWD + void addScript(std::string script) { addScript(script, runDir); } // adds an environment file that will be sourced before this run void addEnv(std::string path); @@ -74,7 +77,7 @@ public: RunState lastResult; std::string laminarHome; std::string name; - std::string wd; + std::string runDir; std::string parentName; int parentBuild = 0; std::string reasonMsg; @@ -88,8 +91,14 @@ public: time_t queuedAt; time_t startedAt; private: - std::queue scripts; - std::string currentScript; + + struct Script { + std::string path; + std::string cwd; + }; + + std::queue