diff --git a/src/builtin_bg.cpp b/src/builtin_bg.cpp index 9af0cbbfc..e737edae4 100644 --- a/src/builtin_bg.cpp +++ b/src/builtin_bg.cpp @@ -52,7 +52,7 @@ int builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (optind == argc) { // No jobs were specified so use the most recent (i.e., last) job. job_t *job = nullptr; - for (auto j : jobs()) { + for (const auto &j : jobs()) { if (j->is_stopped() && j->get_flag(job_flag_t::JOB_CONTROL) && (!j->is_completed())) { job = j.get(); break; diff --git a/src/builtin_disown.cpp b/src/builtin_disown.cpp index dc766cc34..ad965b693 100644 --- a/src/builtin_disown.cpp +++ b/src/builtin_disown.cpp @@ -65,7 +65,7 @@ int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // Foreground jobs can be disowned. // Even jobs that aren't under job control can be disowned! job_t *job = nullptr; - for (auto j : jobs()) { + for (const auto &j : jobs()) { if (j->is_constructed() && (!j->is_completed())) { job = j.get(); break; @@ -104,7 +104,7 @@ int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } // Disown all target jobs - for (auto j : jobs) { + for (const auto &j : jobs) { retval |= disown_job(cmd, parser, streams, j); } } diff --git a/src/builtin_fg.cpp b/src/builtin_fg.cpp index befff322c..5bd9221b6 100644 --- a/src/builtin_fg.cpp +++ b/src/builtin_fg.cpp @@ -38,7 +38,7 @@ int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // Select last constructed job (i.e. first job in the job queue) that can be brought // to the foreground. - for (auto j : jobs()) { + for (const auto &j : jobs()) { if (j->is_constructed() && (!j->is_completed()) && ((j->is_stopped() || (!j->is_foreground())) && j->get_flag(job_flag_t::JOB_CONTROL))) { diff --git a/src/builtin_jobs.cpp b/src/builtin_jobs.cpp index c3673b89d..f4dab2411 100644 --- a/src/builtin_jobs.cpp +++ b/src/builtin_jobs.cpp @@ -174,7 +174,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (print_last) { // Ignore unconstructed jobs, i.e. ourself. - for (auto j : jobs()) { + for (const auto &j : jobs()) { if (j->is_constructed() && !j->is_completed()) { builtin_jobs_print(j.get(), mode, !streams.out_is_redirected, streams); return STATUS_CMD_ERROR; @@ -215,7 +215,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } } } else { - for (auto j : jobs()) { + for (const auto &j : jobs()) { // Ignore unconstructed jobs, i.e. ourself. if (j->is_constructed() && !j->is_completed()) { builtin_jobs_print(j.get(), mode, !found && !streams.out_is_redirected, streams); diff --git a/src/builtin_wait.cpp b/src/builtin_wait.cpp index 34a687bb1..6df0d3abf 100644 --- a/src/builtin_wait.cpp +++ b/src/builtin_wait.cpp @@ -16,7 +16,7 @@ /// If a specified process has already finished but the job hasn't, parser_t::job_get_from_pid() /// doesn't work properly, so use this function in wait command. static job_id_t get_job_id_from_pid(pid_t pid) { - for (auto j : jobs()) { + for (const auto &j : jobs()) { if (j->pgid == pid) { return j->job_id; } @@ -31,7 +31,7 @@ static job_id_t get_job_id_from_pid(pid_t pid) { } static bool all_jobs_finished() { - for (auto j : jobs()) { + for (const auto &j : jobs()) { // If any job is not completed, return false. // If there are stopped jobs, they are ignored. if (j->is_constructed() && !j->is_completed() && !j->is_stopped()) { @@ -48,7 +48,7 @@ static bool any_jobs_finished(size_t jobs_len) { if (jobs_len != jobs().size()) { return true; } - for (auto j : jobs()) { + for (const auto &j : jobs()) { // If any job is completed, return true. if (j->is_constructed() && (j->is_completed() || j->is_stopped())) { return true; @@ -139,7 +139,7 @@ static bool match_pid(const wcstring &cmd, const wchar_t *proc) { static bool find_job_by_name(const wchar_t *proc, std::vector &ids) { bool found = false; - for (const auto j : jobs()) { + for (const auto &j : jobs()) { if (j->command_is_empty()) continue; if (match_pid(j->command(), proc)) { diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 8bd145c77..2af130d63 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -785,7 +785,7 @@ parse_execution_result_t parse_execution_context_t::populate_plain_process( static uint32_t last_exec_run_counter = -1; if (process_type == process_type_t::exec && shell_is_interactive()) { bool have_bg = false; - for (const auto bg : jobs()) { + for (const auto &bg : jobs()) { // The assumption here is that if it is a foreground job, // it's related to us. // This stops us from asking if we're doing `exec` inside a function. diff --git a/src/parser.cpp b/src/parser.cpp index d6751dac0..4b0a75082 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -597,7 +597,7 @@ job_t *parser_t::job_get_from_pid(pid_t pid) const { return 0; } - for (auto job : jobs()) { + for (const auto &job : jobs()) { if (job->pgid == pgid) { for (const process_ptr_t &p : job->processes) { if (p->pid == pid) { diff --git a/src/proc.cpp b/src/proc.cpp index 1530cdb9c..cc4705ffb 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -107,7 +107,7 @@ void job_t::promote() { } void proc_destroy() { - for (const auto job : jobs()) { + for (const auto &job : jobs()) { debug(2, L"freeing leaked job %ls", job->command_wcstr()); } jobs().clear(); @@ -372,7 +372,7 @@ static void process_mark_finished_children(bool block_ok) { // We got some changes. Since we last checked we received SIGCHLD, and or HUP/INT. // Update the hup/int generations and reap any reapable processes. - for (const auto j : jobs()) { + for (const auto &j : jobs()) { for (const auto &proc : j->processes) { if (auto mtopic = j->reap_topic_for_process(proc.get())) { // Update the signal hup/int gen. @@ -645,7 +645,7 @@ unsigned long proc_get_jiffies(process_t *p) { /// Update the CPU time for all jobs. void proc_update_jiffies() { - for (auto job : jobs()) { + for (const auto &job : jobs()) { for (process_ptr_t &p : job->processes) { gettimeofday(&p->last_time, 0); p->last_jiffies = proc_get_jiffies(p.get()); @@ -880,7 +880,7 @@ void job_t::continue_job(bool send_sigcont) { void proc_sanity_check() { const job_t *fg_job = NULL; - for (const auto j : jobs()) { + for (const auto &j : jobs()) { if (!j->is_constructed()) continue; // More than one foreground job? @@ -937,7 +937,7 @@ void proc_wait_any() { } void hup_background_jobs() { - for (auto j : jobs()) { + for (const auto &j : jobs()) { // Make sure we don't try to SIGHUP the calling builtin if (j->pgid == INVALID_PID || !j->get_flag(job_flag_t::JOB_CONTROL)) { continue; diff --git a/src/reader.cpp b/src/reader.cpp index e2c072700..6ffd3da31 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2229,7 +2229,7 @@ void reader_bg_job_warning() { std::fputws(_(L"There are still jobs active:\n"), stdout); std::fputws(_(L"\n PID Command\n"), stdout); - for (auto j : jobs()) { + for (const auto &j : jobs()) { if (!j->is_completed()) { std::fwprintf(stdout, L"%6d %ls\n", j->processes[0]->pid, j->command_wcstr()); } @@ -2253,7 +2253,7 @@ static void handle_end_loop() { } bool bg_jobs = false; - for (const auto j : jobs()) { + for (const auto &j : jobs()) { if (!j->is_completed()) { bg_jobs = true; break;