mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
make style-all time again
Recent changes have introduced some style deviations so clean them up.
This commit is contained in:
parent
acdb81bbca
commit
975a5bfbde
10 changed files with 57 additions and 68 deletions
|
@ -19,8 +19,8 @@
|
|||
#include <set>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "autoload.h"
|
||||
#include "builtin.h"
|
||||
|
@ -248,9 +248,7 @@ static Iterator unique_unsorted(Iterator begin, Iterator end, HashFunction hash)
|
|||
typedef typename std::iterator_traits<Iterator>::value_type T;
|
||||
|
||||
std::unordered_set<size_t> temp;
|
||||
return std::remove_if(begin, end, [&](const T& val) {
|
||||
return !temp.insert(hash(val)).second;
|
||||
});
|
||||
return std::remove_if(begin, end, [&](const T &val) { return !temp.insert(hash(val)).second; });
|
||||
}
|
||||
|
||||
void completions_sort_and_prioritize(std::vector<completion_t> *comps) {
|
||||
|
@ -276,9 +274,10 @@ void completions_sort_and_prioritize(std::vector<completion_t> *comps) {
|
|||
// Sort, provided COMPLETION_DONT_SORT isn't set
|
||||
stable_sort(comps->begin(), comps->end(), completion_t::is_naturally_less_than);
|
||||
// Deduplicate both sorted and unsorted results
|
||||
comps->erase(unique_unsorted(comps->begin(), comps->end(), [](const completion_t &c) {
|
||||
return std::hash<wcstring>{}(c.completion);
|
||||
}), comps->end());
|
||||
comps->erase(
|
||||
unique_unsorted(comps->begin(), comps->end(),
|
||||
[](const completion_t &c) { return std::hash<wcstring>{}(c.completion); }),
|
||||
comps->end());
|
||||
|
||||
// Sort the remainder by match type. They're already sorted alphabetically.
|
||||
stable_sort(comps->begin(), comps->end(), compare_completions_by_match_type);
|
||||
|
|
|
@ -929,7 +929,8 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
|
||||
// Set g_use_posix_spawn. Default to true.
|
||||
env_var_t use_posix_spawn = env_get(L"fish_use_posix_spawn");
|
||||
g_use_posix_spawn = use_posix_spawn.missing_or_empty() ? true : from_string<bool>(use_posix_spawn.as_string());
|
||||
g_use_posix_spawn =
|
||||
use_posix_spawn.missing_or_empty() ? true : from_string<bool>(use_posix_spawn.as_string());
|
||||
|
||||
// Set fish_bind_mode to "default".
|
||||
env_set(FISH_BIND_MODE_VAR, DEFAULT_BIND_MODE, ENV_GLOBAL);
|
||||
|
|
30
src/exec.cpp
30
src/exec.cpp
|
@ -395,7 +395,6 @@ void internal_exec(job_t *j, const io_chain_t &&all_ios) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void exec_job(parser_t &parser, job_t *j) {
|
||||
pid_t pid = 0;
|
||||
|
||||
|
@ -640,8 +639,9 @@ void exec_job(parser_t &parser, job_t *j) {
|
|||
// This is the io_streams we pass to internal builtins.
|
||||
std::unique_ptr<io_streams_t> builtin_io_streams(new io_streams_t(stdout_read_limit));
|
||||
|
||||
auto do_fork = [&j, &p, &pid, &exec_error, &process_net_io_chain, &block_child, &child_forked]
|
||||
(bool drain_threads, const char *fork_type, std::function<void()> child_action) -> bool {
|
||||
auto do_fork = [&j, &p, &pid, &exec_error, &process_net_io_chain, &block_child,
|
||||
&child_forked](bool drain_threads, const char *fork_type,
|
||||
std::function<void()> child_action) -> bool {
|
||||
pid = execute_fork(drain_threads);
|
||||
if (pid == 0) {
|
||||
// This is the child process. Setup redirections, print correct output to
|
||||
|
@ -649,9 +649,10 @@ void exec_job(parser_t &parser, job_t *j) {
|
|||
p->pid = getpid();
|
||||
blocked_pid = -1;
|
||||
child_set_group(j, p);
|
||||
// Make child processes pause after executing setup_child_process() to give down-chain
|
||||
// commands in the job a chance to join their process group and read their pipes.
|
||||
// The process will be resumed when the next command in the chain is started.
|
||||
// Make child processes pause after executing setup_child_process() to give
|
||||
// down-chain commands in the job a chance to join their process group and read
|
||||
// their pipes. The process will be resumed when the next command in the chain is
|
||||
// started.
|
||||
if (block_child) {
|
||||
kill(p->pid, SIGSTOP);
|
||||
}
|
||||
|
@ -659,8 +660,7 @@ void exec_job(parser_t &parser, job_t *j) {
|
|||
setup_child_process(p, process_net_io_chain);
|
||||
child_action();
|
||||
DIE("Child process returned control to do_fork lambda!");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (pid < 0) {
|
||||
debug(1, L"Failed to fork %s!\n", fork_type);
|
||||
job_mark_process_as_failed(j, p);
|
||||
|
@ -669,7 +669,8 @@ void exec_job(parser_t &parser, job_t *j) {
|
|||
}
|
||||
// This is the parent process. Store away information on the child, and
|
||||
// possibly give it control over the terminal.
|
||||
debug(2, L"Fork #%d, pid %d: %s for '%ls'", g_fork_count, pid, fork_type, p->argv0());
|
||||
debug(2, L"Fork #%d, pid %d: %s for '%ls'", g_fork_count, pid, fork_type,
|
||||
p->argv0());
|
||||
child_forked = true;
|
||||
if (block_child) {
|
||||
debug(2, L"Blocking process %d waiting for next command in chain.\n", pid);
|
||||
|
@ -683,7 +684,7 @@ void exec_job(parser_t &parser, job_t *j) {
|
|||
// Helper routine executed by INTERNAL_FUNCTION and INTERNAL_BLOCK_NODE to make sure an
|
||||
// output buffer exists in case there is another command in the job chain that will be
|
||||
// reading from this command's output.
|
||||
auto verify_buffer_output = [&] () {
|
||||
auto verify_buffer_output = [&]() {
|
||||
if (!p->is_last_in_job) {
|
||||
// Be careful to handle failure, e.g. too many open fds.
|
||||
block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios);
|
||||
|
@ -700,7 +701,6 @@ void exec_job(parser_t &parser, job_t *j) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
switch (p->type) {
|
||||
case INTERNAL_FUNCTION: {
|
||||
const wcstring func_name = p->argv0();
|
||||
|
@ -1082,16 +1082,14 @@ void exec_job(parser_t &parser, job_t *j) {
|
|||
if (pid == 0) {
|
||||
job_mark_process_as_failed(j, p);
|
||||
exec_error = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
child_spawned = true;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (!do_fork(false, "external command", [&] {
|
||||
safe_launch_process(p, actual_cmd, argv, envv);
|
||||
})) {
|
||||
if (!do_fork(false, "external command",
|
||||
[&] { safe_launch_process(p, actual_cmd, argv, envv); })) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,9 +58,7 @@ static wint_t lookahead_front(void) { return lookahead_list.front(); }
|
|||
/// Callback function for handling interrupts on reading.
|
||||
static int (*interrupt_handler)();
|
||||
|
||||
void input_common_init(int (*ih)()) {
|
||||
interrupt_handler = ih;
|
||||
}
|
||||
void input_common_init(int (*ih)()) { interrupt_handler = ih; }
|
||||
|
||||
void input_common_destroy() {}
|
||||
|
||||
|
|
|
@ -119,15 +119,15 @@ bool child_set_group(job_t *j, process_t *p) {
|
|||
return retval;
|
||||
}
|
||||
|
||||
/// Called only by the parent only after a child forks and successfully calls child_set_group, guaranteeing
|
||||
/// the job control process group has been created and that the child belongs to the correct process group.
|
||||
/// Here we can update our job_t structure to reflect the correct process group in the case of JOB_CONTROL,
|
||||
/// and we can give the new process group control of the terminal if it's to run in the foreground. Note that
|
||||
/// we can guarantee the child won't try to read from the terminal before we've had a chance to run this code,
|
||||
/// because we haven't woken them up with a SIGCONT yet.
|
||||
/// This musn't be called as a part of setup_child_process because that can hang indefinitely until data is
|
||||
/// available to read/write in the case of IO_FILE, which means we'll never reach our SIGSTOP and everything
|
||||
/// hangs.
|
||||
/// Called only by the parent only after a child forks and successfully calls child_set_group,
|
||||
/// guaranteeing the job control process group has been created and that the child belongs to the
|
||||
/// correct process group. Here we can update our job_t structure to reflect the correct process
|
||||
/// group in the case of JOB_CONTROL, and we can give the new process group control of the terminal
|
||||
/// if it's to run in the foreground. Note that we can guarantee the child won't try to read from
|
||||
/// the terminal before we've had a chance to run this code, because we haven't woken them up with a
|
||||
/// SIGCONT yet. This musn't be called as a part of setup_child_process because that can hang
|
||||
/// indefinitely until data is available to read/write in the case of IO_FILE, which means we'll
|
||||
/// never reach our SIGSTOP and everything hangs.
|
||||
bool set_child_group(job_t *j, pid_t child_pid) {
|
||||
bool retval = true;
|
||||
|
||||
|
@ -148,9 +148,7 @@ bool set_child_group(job_t *j, pid_t child_pid) {
|
|||
// a process group, attempting to call tcsetpgrp from the background will cause SIGTTOU
|
||||
// to be sent to everything in our process group (unless we handle it).
|
||||
debug(4, L"Process group %d already has control of terminal\n", j->pgid);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// No need to duplicate the code here, a function already exists that does just this.
|
||||
retval = terminal_give_to_job(j, false /*new job, so not continuing*/);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ class io_chain_t;
|
|||
class job_t;
|
||||
class process_t;
|
||||
|
||||
bool set_child_group(job_t *j, pid_t child_pid); //called by parent
|
||||
bool child_set_group(job_t *j, process_t *p); //called by child
|
||||
bool set_child_group(job_t *j, pid_t child_pid); // called by parent
|
||||
bool child_set_group(job_t *j, process_t *p); // called by child
|
||||
|
||||
/// Initialize a new child process. This should be called right away after forking in the child
|
||||
/// process. If job control is enabled for this job, the process is put in the process group of the
|
||||
|
|
31
src/proc.cpp
31
src/proc.cpp
|
@ -803,9 +803,10 @@ bool terminal_give_to_job(job_t *j, int cont) {
|
|||
// been done.
|
||||
if (tcgetpgrp(STDIN_FILENO) == j->pgid) {
|
||||
debug(2, L"Process group %d already has control of terminal\n", j->pgid);
|
||||
}
|
||||
else {
|
||||
debug(4, L"Attempting to bring process group to foreground via tcsetpgrp for job->pgid %d\n", j->pgid);
|
||||
} else {
|
||||
debug(4,
|
||||
L"Attempting to bring process group to foreground via tcsetpgrp for job->pgid %d\n",
|
||||
j->pgid);
|
||||
|
||||
// The tcsetpgrp(2) man page says that EPERM is thrown if "pgrp has a supported value, but
|
||||
// is not the process group ID of a process in the same session as the calling process."
|
||||
|
@ -820,14 +821,12 @@ bool terminal_give_to_job(job_t *j, int cont) {
|
|||
bool pgroup_terminated = false;
|
||||
if (errno == EINTR) {
|
||||
; // Always retry on EINTR, see comments in tcsetattr EINTR code below.
|
||||
}
|
||||
else if (errno == EINVAL) {
|
||||
} else if (errno == EINVAL) {
|
||||
// OS X returns EINVAL if the process group no longer lives. Probably other OSes,
|
||||
// too. Unlike EPERM below, EINVAL can only happen if the process group has
|
||||
// terminated.
|
||||
pgroup_terminated = true;
|
||||
}
|
||||
else if (errno == EPERM) {
|
||||
} else if (errno == EPERM) {
|
||||
// Retry so long as this isn't because the process group is dead.
|
||||
int wait_result = waitpid(-1 * j->pgid, &wait_result, WNOHANG);
|
||||
if (wait_result == -1) {
|
||||
|
@ -837,16 +836,15 @@ bool terminal_give_to_job(job_t *j, int cont) {
|
|||
// would mean processes from the group still exist but is still running in some
|
||||
// state or the other.
|
||||
pgroup_terminated = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Debug the original tcsetpgrp error (not the waitpid errno) to the log, and
|
||||
// then retry until not EPERM or the process group has exited.
|
||||
debug(2, L"terminal_give_to_job(): EPERM.\n", j->pgid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (errno == ENOTTY) redirect_tty_output();
|
||||
debug(1, _(L"Could not send job %d ('%ls') with pgid %d to foreground"), j->job_id, j->command_wcstr(), j->pgid);
|
||||
debug(1, _(L"Could not send job %d ('%ls') with pgid %d to foreground"), j->job_id,
|
||||
j->command_wcstr(), j->pgid);
|
||||
wperror(L"tcsetpgrp");
|
||||
signal_unblock();
|
||||
return false;
|
||||
|
@ -874,7 +872,8 @@ bool terminal_give_to_job(job_t *j, int cont) {
|
|||
}
|
||||
if (result == -1) {
|
||||
if (errno == ENOTTY) redirect_tty_output();
|
||||
debug(1, _(L"Could not send job %d ('%ls') to foreground"), j->job_id, j->command_wcstr());
|
||||
debug(1, _(L"Could not send job %d ('%ls') to foreground"), j->job_id,
|
||||
j->command_wcstr());
|
||||
wperror(L"tcsetattr");
|
||||
signal_unblock();
|
||||
return false;
|
||||
|
@ -936,10 +935,8 @@ void job_continue(job_t *j, bool cont) {
|
|||
j->set_flag(JOB_NOTIFIED, false);
|
||||
|
||||
CHECK_BLOCK();
|
||||
debug(4, L"%ls job %d, gid %d (%ls), %ls, %ls",
|
||||
cont ? L"Continue" : L"Start",
|
||||
j->job_id, j->pgid, j->command_wcstr(),
|
||||
job_is_completed(j) ? L"COMPLETED" : L"UNCOMPLETED",
|
||||
debug(4, L"%ls job %d, gid %d (%ls), %ls, %ls", cont ? L"Continue" : L"Start", j->job_id,
|
||||
j->pgid, j->command_wcstr(), job_is_completed(j) ? L"COMPLETED" : L"UNCOMPLETED",
|
||||
is_interactive ? L"INTERACTIVE" : L"NON-INTERACTIVE");
|
||||
|
||||
if (!job_is_completed(j)) {
|
||||
|
|
|
@ -417,6 +417,4 @@ void signal_unblock() {
|
|||
}
|
||||
}
|
||||
|
||||
bool signal_is_blocked() {
|
||||
return static_cast<bool>(block_count);
|
||||
}
|
||||
bool signal_is_blocked() { return static_cast<bool>(block_count); }
|
||||
|
|
|
@ -28,7 +28,7 @@ wcstring_range wcstring_tok(wcstring& str, const wcstring& needle,
|
|||
/// If the needle is empty, split on individual elements (characters).
|
||||
template <typename ITER>
|
||||
void split_about(ITER haystack_start, ITER haystack_end, ITER needle_start, ITER needle_end,
|
||||
wcstring_list_t *output, long max) {
|
||||
wcstring_list_t* output, long max) {
|
||||
long remaining = max;
|
||||
ITER haystack_cursor = haystack_start;
|
||||
while (remaining > 0 && haystack_cursor != haystack_end) {
|
||||
|
|
Loading…
Reference in a new issue