Teach a job its command at constructor time

No point in allowing this to be set later.
This commit is contained in:
ridiculousfish
2020-07-17 14:05:23 -07:00
parent f30ce21aaa
commit ba8b89873e
3 changed files with 7 additions and 11 deletions

View File

@@ -1136,9 +1136,6 @@ end_execution_reason_t parse_execution_context_t::populate_job_from_job_node(
job_t *j, const ast::job_t &job_node, const block_t *associated_block) {
UNUSED(associated_block);
// Tell the job what its command is.
j->set_command(get_source(job_node));
// We are going to construct process_t structures for every statement in the job.
// Create processes. Each one may fail.
process_list_t processes;
@@ -1307,7 +1304,7 @@ end_execution_reason_t parse_execution_context_t::run_1_job(const ast::job_t &jo
props.from_event_handler = ld.is_event;
props.job_control = wants_job_control;
shared_ptr<job_t> job = std::make_shared<job_t>(props);
shared_ptr<job_t> job = std::make_shared<job_t>(props, get_source(job_node));
// We are about to populate a job. One possible argument to the job is a command substitution
// which may be interested in the job that's populating it, via '--on-job-exit caller'. Record

View File

@@ -383,8 +383,10 @@ static uint64_t next_internal_job_id() {
return ++s_next;
}
job_t::job_t(const properties_t &props)
: properties(props), internal_job_id(next_internal_job_id()) {}
job_t::job_t(const properties_t &props, wcstring command_str)
: properties(props),
command_str(std::move(command_str)),
internal_job_id(next_internal_job_id()) {}
job_t::~job_t() = default;

View File

@@ -430,14 +430,14 @@ class job_t {
/// The original command which led to the creation of this job. It is used for displaying
/// messages about job status on the terminal.
wcstring command_str;
const wcstring command_str;
// No copying.
job_t(const job_t &rhs) = delete;
void operator=(const job_t &) = delete;
public:
explicit job_t(const properties_t &props);
job_t(const properties_t &props, wcstring command_str);
~job_t();
/// Returns the command as a wchar_t *. */
@@ -446,9 +446,6 @@ class job_t {
/// Returns the command.
const wcstring &command() const { return command_str; }
/// Sets the command.
void set_command(wcstring cmd) { command_str = std::move(cmd); }
/// \return whether it is OK to reap a given process. Sometimes we want to defer reaping a
/// process if it is the group leader and the job is not yet constructed, because then we might
/// also reap the process group and then we cannot add new processes to the group.