make style-all time again

Recent changes have introduced some style deviations so clean them up.
This commit is contained in:
Kurtis Rader 2017-08-06 16:05:51 -07:00
parent acdb81bbca
commit 975a5bfbde
10 changed files with 57 additions and 68 deletions

View file

@ -199,12 +199,12 @@ extern bool has_working_tty_timestamps;
// from within a `switch` block. As of the time I'm writing this oclint doesn't recognize the // from within a `switch` block. As of the time I'm writing this oclint doesn't recognize the
// `__attribute__((noreturn))` on the exit_without_destructors() function. // `__attribute__((noreturn))` on the exit_without_destructors() function.
// TODO: we use C++11 [[noreturn]] now, does that change things? // TODO: we use C++11 [[noreturn]] now, does that change things?
#define FATAL_EXIT() \ #define FATAL_EXIT() \
{ \ { \
char exit_read_buff; \ char exit_read_buff; \
show_stackframe(L'E'); \ show_stackframe(L'E'); \
(void)read(0, &exit_read_buff, 1); \ (void)read(0, &exit_read_buff, 1); \
exit_without_destructors(1); \ exit_without_destructors(1); \
} }
/// Exit the program at once after emitting an error message and stack trace if possible. /// Exit the program at once after emitting an error message and stack trace if possible.

View file

@ -19,8 +19,8 @@
#include <set> #include <set>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <utility>
#include <unordered_set> #include <unordered_set>
#include <utility>
#include "autoload.h" #include "autoload.h"
#include "builtin.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; typedef typename std::iterator_traits<Iterator>::value_type T;
std::unordered_set<size_t> temp; std::unordered_set<size_t> temp;
return std::remove_if(begin, end, [&](const T& val) { return std::remove_if(begin, end, [&](const T &val) { return !temp.insert(hash(val)).second; });
return !temp.insert(hash(val)).second;
});
} }
void completions_sort_and_prioritize(std::vector<completion_t> *comps) { 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 // Sort, provided COMPLETION_DONT_SORT isn't set
stable_sort(comps->begin(), comps->end(), completion_t::is_naturally_less_than); stable_sort(comps->begin(), comps->end(), completion_t::is_naturally_less_than);
// Deduplicate both sorted and unsorted results // Deduplicate both sorted and unsorted results
comps->erase(unique_unsorted(comps->begin(), comps->end(), [](const completion_t &c) { comps->erase(
return std::hash<wcstring>{}(c.completion); unique_unsorted(comps->begin(), comps->end(),
}), 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. // Sort the remainder by match type. They're already sorted alphabetically.
stable_sort(comps->begin(), comps->end(), compare_completions_by_match_type); stable_sort(comps->begin(), comps->end(), compare_completions_by_match_type);

View file

@ -929,7 +929,8 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
// Set g_use_posix_spawn. Default to true. // Set g_use_posix_spawn. Default to true.
env_var_t use_posix_spawn = env_get(L"fish_use_posix_spawn"); 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". // Set fish_bind_mode to "default".
env_set(FISH_BIND_MODE_VAR, DEFAULT_BIND_MODE, ENV_GLOBAL); env_set(FISH_BIND_MODE_VAR, DEFAULT_BIND_MODE, ENV_GLOBAL);

View file

@ -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) { void exec_job(parser_t &parser, job_t *j) {
pid_t pid = 0; 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. // 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)); 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] auto do_fork = [&j, &p, &pid, &exec_error, &process_net_io_chain, &block_child,
(bool drain_threads, const char *fork_type, std::function<void()> child_action) -> bool { &child_forked](bool drain_threads, const char *fork_type,
std::function<void()> child_action) -> bool {
pid = execute_fork(drain_threads); pid = execute_fork(drain_threads);
if (pid == 0) { if (pid == 0) {
// This is the child process. Setup redirections, print correct output to // 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(); p->pid = getpid();
blocked_pid = -1; blocked_pid = -1;
child_set_group(j, p); child_set_group(j, p);
// Make child processes pause after executing setup_child_process() to give down-chain // Make child processes pause after executing setup_child_process() to give
// commands in the job a chance to join their process group and read their pipes. // down-chain commands in the job a chance to join their process group and read
// The process will be resumed when the next command in the chain is started. // their pipes. The process will be resumed when the next command in the chain is
// started.
if (block_child) { if (block_child) {
kill(p->pid, SIGSTOP); 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); setup_child_process(p, process_net_io_chain);
child_action(); child_action();
DIE("Child process returned control to do_fork lambda!"); DIE("Child process returned control to do_fork lambda!");
} } else {
else {
if (pid < 0) { if (pid < 0) {
debug(1, L"Failed to fork %s!\n", fork_type); debug(1, L"Failed to fork %s!\n", fork_type);
job_mark_process_as_failed(j, p); 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 // This is the parent process. Store away information on the child, and
// possibly give it control over the terminal. // 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; child_forked = true;
if (block_child) { if (block_child) {
debug(2, L"Blocking process %d waiting for next command in chain.\n", pid); 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 // 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 // output buffer exists in case there is another command in the job chain that will be
// reading from this command's output. // reading from this command's output.
auto verify_buffer_output = [&] () { auto verify_buffer_output = [&]() {
if (!p->is_last_in_job) { if (!p->is_last_in_job) {
// Be careful to handle failure, e.g. too many open fds. // Be careful to handle failure, e.g. too many open fds.
block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios); 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) { switch (p->type) {
case INTERNAL_FUNCTION: { case INTERNAL_FUNCTION: {
const wcstring func_name = p->argv0(); const wcstring func_name = p->argv0();
@ -1082,16 +1082,14 @@ void exec_job(parser_t &parser, job_t *j) {
if (pid == 0) { if (pid == 0) {
job_mark_process_as_failed(j, p); job_mark_process_as_failed(j, p);
exec_error = true; exec_error = true;
} } else {
else {
child_spawned = true; child_spawned = true;
} }
} else } else
#endif #endif
{ {
if (!do_fork(false, "external command", [&] { if (!do_fork(false, "external command",
safe_launch_process(p, actual_cmd, argv, envv); [&] { safe_launch_process(p, actual_cmd, argv, envv); })) {
})) {
break; break;
} }
} }

View file

@ -58,9 +58,7 @@ static wint_t lookahead_front(void) { return lookahead_list.front(); }
/// Callback function for handling interrupts on reading. /// Callback function for handling interrupts on reading.
static int (*interrupt_handler)(); static int (*interrupt_handler)();
void input_common_init(int (*ih)()) { void input_common_init(int (*ih)()) { interrupt_handler = ih; }
interrupt_handler = ih;
}
void input_common_destroy() {} void input_common_destroy() {}

View file

@ -119,15 +119,15 @@ bool child_set_group(job_t *j, process_t *p) {
return retval; return retval;
} }
/// Called only by the parent only after a child forks and successfully calls child_set_group, guaranteeing /// Called only by the parent only after a child forks and successfully calls child_set_group,
/// the job control process group has been created and that the child belongs to the correct process group. /// guaranteeing the job control process group has been created and that the child belongs to the
/// Here we can update our job_t structure to reflect the correct process group in the case of JOB_CONTROL, /// correct process group. Here we can update our job_t structure to reflect the correct process
/// and we can give the new process group control of the terminal if it's to run in the foreground. Note that /// group in the case of JOB_CONTROL, and we can give the new process group control of the terminal
/// we can guarantee the child won't try to read from the terminal before we've had a chance to run this code, /// if it's to run in the foreground. Note that we can guarantee the child won't try to read from
/// because we haven't woken them up with a SIGCONT yet. /// the terminal before we've had a chance to run this code, because we haven't woken them up with a
/// This musn't be called as a part of setup_child_process because that can hang indefinitely until data is /// SIGCONT yet. This musn't be called as a part of setup_child_process because that can hang
/// available to read/write in the case of IO_FILE, which means we'll never reach our SIGSTOP and everything /// indefinitely until data is available to read/write in the case of IO_FILE, which means we'll
/// hangs. /// never reach our SIGSTOP and everything hangs.
bool set_child_group(job_t *j, pid_t child_pid) { bool set_child_group(job_t *j, pid_t child_pid) {
bool retval = true; 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 // 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). // 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); 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. // 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*/); retval = terminal_give_to_job(j, false /*new job, so not continuing*/);
} }

View file

@ -18,8 +18,8 @@ class io_chain_t;
class job_t; class job_t;
class process_t; class process_t;
bool set_child_group(job_t *j, pid_t child_pid); //called by parent 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 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 /// 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 /// process. If job control is enabled for this job, the process is put in the process group of the

View file

@ -803,9 +803,10 @@ bool terminal_give_to_job(job_t *j, int cont) {
// been done. // been done.
if (tcgetpgrp(STDIN_FILENO) == j->pgid) { if (tcgetpgrp(STDIN_FILENO) == j->pgid) {
debug(2, L"Process group %d already has control of terminal\n", j->pgid); debug(2, L"Process group %d already has control of terminal\n", j->pgid);
} } else {
else { debug(4,
debug(4, L"Attempting to bring process group to foreground via tcsetpgrp for job->pgid %d\n", j->pgid); 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 // 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." // is not the process group ID of a process in the same session as the calling process."
@ -819,15 +820,13 @@ bool terminal_give_to_job(job_t *j, int cont) {
while (tcsetpgrp(STDIN_FILENO, j->pgid) != 0) { while (tcsetpgrp(STDIN_FILENO, j->pgid) != 0) {
bool pgroup_terminated = false; bool pgroup_terminated = false;
if (errno == EINTR) { if (errno == EINTR) {
; // Always retry on EINTR, see comments in tcsetattr EINTR code below. ; // 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, // 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 // too. Unlike EPERM below, EINVAL can only happen if the process group has
// terminated. // terminated.
pgroup_terminated = true; pgroup_terminated = true;
} } else if (errno == EPERM) {
else if (errno == EPERM) {
// Retry so long as this isn't because the process group is dead. // Retry so long as this isn't because the process group is dead.
int wait_result = waitpid(-1 * j->pgid, &wait_result, WNOHANG); int wait_result = waitpid(-1 * j->pgid, &wait_result, WNOHANG);
if (wait_result == -1) { 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 // would mean processes from the group still exist but is still running in some
// state or the other. // state or the other.
pgroup_terminated = true; pgroup_terminated = true;
} } else {
else {
// Debug the original tcsetpgrp error (not the waitpid errno) to the log, and // Debug the original tcsetpgrp error (not the waitpid errno) to the log, and
// then retry until not EPERM or the process group has exited. // then retry until not EPERM or the process group has exited.
debug(2, L"terminal_give_to_job(): EPERM.\n", j->pgid); debug(2, L"terminal_give_to_job(): EPERM.\n", j->pgid);
} }
} } else {
else {
if (errno == ENOTTY) redirect_tty_output(); 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"); wperror(L"tcsetpgrp");
signal_unblock(); signal_unblock();
return false; return false;
@ -874,7 +872,8 @@ bool terminal_give_to_job(job_t *j, int cont) {
} }
if (result == -1) { if (result == -1) {
if (errno == ENOTTY) redirect_tty_output(); 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"); wperror(L"tcsetattr");
signal_unblock(); signal_unblock();
return false; return false;
@ -936,10 +935,8 @@ void job_continue(job_t *j, bool cont) {
j->set_flag(JOB_NOTIFIED, false); j->set_flag(JOB_NOTIFIED, false);
CHECK_BLOCK(); CHECK_BLOCK();
debug(4, L"%ls job %d, gid %d (%ls), %ls, %ls", debug(4, L"%ls job %d, gid %d (%ls), %ls, %ls", cont ? L"Continue" : L"Start", j->job_id,
cont ? L"Continue" : L"Start", j->pgid, j->command_wcstr(), job_is_completed(j) ? L"COMPLETED" : L"UNCOMPLETED",
j->job_id, j->pgid, j->command_wcstr(),
job_is_completed(j) ? L"COMPLETED" : L"UNCOMPLETED",
is_interactive ? L"INTERACTIVE" : L"NON-INTERACTIVE"); is_interactive ? L"INTERACTIVE" : L"NON-INTERACTIVE");
if (!job_is_completed(j)) { if (!job_is_completed(j)) {

View file

@ -417,6 +417,4 @@ void signal_unblock() {
} }
} }
bool signal_is_blocked() { bool signal_is_blocked() { return static_cast<bool>(block_count); }
return static_cast<bool>(block_count);
}

View file

@ -28,7 +28,7 @@ wcstring_range wcstring_tok(wcstring& str, const wcstring& needle,
/// If the needle is empty, split on individual elements (characters). /// If the needle is empty, split on individual elements (characters).
template <typename ITER> template <typename ITER>
void split_about(ITER haystack_start, ITER haystack_end, ITER needle_start, ITER needle_end, 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; long remaining = max;
ITER haystack_cursor = haystack_start; ITER haystack_cursor = haystack_start;
while (remaining > 0 && haystack_cursor != haystack_end) { while (remaining > 0 && haystack_cursor != haystack_end) {