Skip to content
Closed
20 changes: 19 additions & 1 deletion src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ namespace proc {
proc_t::get_apps() {
return _apps;
}
void
proc_t::set_apps(std::vector<ctx_t> apps) {
_apps = std::move(apps);
}

// Gets application image from application list.
// Returns image from assets directory if found there.
Expand All @@ -382,6 +386,19 @@ namespace proc {
return _app.name;
}

const boost::process::v1::environment &
proc_t::get_env() const {
return _env;
}
boost::process::v1::environment &
proc_t::get_env() {
return _env;
}
void
proc_t::set_env(boost::process::v1::environment env) {
_env = std::move(env);
}

proc_t::~proc_t() {
// It's not safe to call terminate() here because our proc_t is a static variable
// that may be destroyed after the Boost loggers have been destroyed. Instead,
Expand Down Expand Up @@ -716,7 +733,8 @@ namespace proc {
auto proc_opt = proc::parse(file_name);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly suggest to change signature of std::optional<proc::proc_t> parse(const std::string &file_name) to std::optional<std:tuple<std::vector<ctx_t>, boost::process::v1::environment>> parse(const std::string &file_name) and also remove proc_t constructor as it is another disaster waiting to happen (don't forget to initialize int _app_id{0};)


if (proc_opt) {
proc = std::move(*proc_opt);
proc.set_env(proc_opt->get_env());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into this I have found another bug related to _env. It is used in terminate function, this means we have to preserve the _env until process terminates :/

The moment we call execute we should copy the _env to a member variable _app_env (name is debatable) and replace every usage of _env within execute and terminate with _app_env (except the first one where we copy it of course). Or we could store the new ENV to _current_env and the in execute copy it (_env = _current_env). I prefer the first renaming option, but whatever is easier is ok.

proc.set_apps(proc_opt->get_apps());
}
}
} // namespace proc
8 changes: 8 additions & 0 deletions src/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,18 @@ namespace proc {
get_apps() const;
std::vector<ctx_t> &
get_apps();
void
set_apps(std::vector<ctx_t> apps);
std::string
get_app_image(int app_id);
std::string
get_last_run_app_name();
const boost::process::v1::environment &
get_env() const;
boost::process::v1::environment &
get_env();
void
set_env(boost::process::v1::environment env);
void
terminate();

Expand Down