mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-02 22:21:15 -03:00
Adopt Rust naming conventions in JobControl and ProcessType
This commit is contained in:
@@ -369,9 +369,9 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
||||
streams.out.append(wgettext!("This is not a login shell\n"));
|
||||
}
|
||||
let job_control_mode = match get_job_control_mode() {
|
||||
JobControl::interactive => wgettext!("Only on interactive jobs"),
|
||||
JobControl::none => wgettext!("Never"),
|
||||
JobControl::all => wgettext!("Always"),
|
||||
JobControl::Interactive => wgettext!("Only on interactive jobs"),
|
||||
JobControl::None => wgettext!("Never"),
|
||||
JobControl::All => wgettext!("Always"),
|
||||
};
|
||||
streams
|
||||
.out
|
||||
@@ -639,14 +639,14 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
||||
}
|
||||
}
|
||||
STATUS_IS_FULL_JOB_CTRL => {
|
||||
if get_job_control_mode() == JobControl::all {
|
||||
if get_job_control_mode() == JobControl::All {
|
||||
return Ok(SUCCESS);
|
||||
} else {
|
||||
return Err(STATUS_CMD_ERROR);
|
||||
}
|
||||
}
|
||||
STATUS_IS_INTERACTIVE_JOB_CTRL => {
|
||||
if get_job_control_mode() == JobControl::interactive {
|
||||
if get_job_control_mode() == JobControl::Interactive {
|
||||
return Ok(SUCCESS);
|
||||
} else {
|
||||
return Err(STATUS_CMD_ERROR);
|
||||
@@ -660,7 +660,7 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
||||
}
|
||||
}
|
||||
STATUS_IS_NO_JOB_CTRL => {
|
||||
if get_job_control_mode() == JobControl::none {
|
||||
if get_job_control_mode() == JobControl::None {
|
||||
return Ok(SUCCESS);
|
||||
} else {
|
||||
return Err(STATUS_CMD_ERROR);
|
||||
|
||||
30
src/exec.rs
30
src/exec.rs
@@ -74,7 +74,7 @@ pub fn exec_job(parser: &Parser, job: &Job, block_io: IoChain) -> bool {
|
||||
}
|
||||
|
||||
// Handle an exec call.
|
||||
if job.processes()[0].typ == ProcessType::exec {
|
||||
if job.processes()[0].typ == ProcessType::Exec {
|
||||
// If we are interactive, perhaps disallow exec if there are background jobs.
|
||||
if !allow_exec_with_background_jobs(parser) {
|
||||
for p in job.processes().iter() {
|
||||
@@ -807,7 +807,7 @@ fn handle_builtin_output(
|
||||
out: &OutputStream,
|
||||
err: &OutputStream,
|
||||
) {
|
||||
assert!(p.typ == ProcessType::builtin, "Process is not a builtin");
|
||||
assert!(p.typ == ProcessType::Builtin, "Process is not a builtin");
|
||||
|
||||
// Figure out any data remaining to write. We may have none, in which case we can short-circuit.
|
||||
let outbuff = wcs2string(out.contents());
|
||||
@@ -834,7 +834,7 @@ fn exec_external_command(
|
||||
p: &Process,
|
||||
proc_io_chain: &IoChain,
|
||||
) -> LaunchResult {
|
||||
assert!(p.typ == ProcessType::external, "Process is not external");
|
||||
assert!(p.typ == ProcessType::External, "Process is not external");
|
||||
// Get argv and envv before we fork.
|
||||
let narrow_argv = p.argv().iter().map(|s| wcs2zstring(s)).collect();
|
||||
let argv = OwningNullTerminatedArray::new(narrow_argv);
|
||||
@@ -976,14 +976,14 @@ fn get_performer_for_process(
|
||||
io_chain: &IoChain,
|
||||
) -> Option<Box<ProcPerformer>> {
|
||||
assert!(
|
||||
[ProcessType::function, ProcessType::block_node].contains(&p.typ),
|
||||
matches!(p.typ, ProcessType::Function | ProcessType::BlockNode),
|
||||
"Unexpected process type"
|
||||
);
|
||||
// We want to capture the job group.
|
||||
let job_group = job.group.clone();
|
||||
let io_chain = io_chain.clone();
|
||||
|
||||
if p.typ == ProcessType::block_node {
|
||||
if p.typ == ProcessType::BlockNode {
|
||||
Some(Box::new(move |parser: &Parser, p: &Process, _out, _err| {
|
||||
let source = p
|
||||
.block_node_source
|
||||
@@ -1004,7 +1004,7 @@ fn get_performer_for_process(
|
||||
.status
|
||||
}))
|
||||
} else {
|
||||
assert!(p.typ == ProcessType::function);
|
||||
assert!(p.typ == ProcessType::Function);
|
||||
let Some(props) = function::get_props(p.argv0().unwrap()) else {
|
||||
FLOG!(
|
||||
error,
|
||||
@@ -1090,7 +1090,7 @@ fn exec_block_or_func_process(
|
||||
}
|
||||
|
||||
fn get_performer_for_builtin(p: &Process, j: &Job, io_chain: &IoChain) -> Box<ProcPerformer> {
|
||||
assert!(p.typ == ProcessType::builtin, "Process must be a builtin");
|
||||
assert!(p.typ == ProcessType::Builtin, "Process must be a builtin");
|
||||
|
||||
// Determine if we have a "direct" redirection for stdin.
|
||||
let mut stdin_is_directly_redirected = false;
|
||||
@@ -1172,7 +1172,7 @@ fn exec_builtin_process(
|
||||
io_chain: &IoChain,
|
||||
piped_output_needs_buffering: bool,
|
||||
) -> LaunchResult {
|
||||
assert!(p.typ == ProcessType::builtin, "Process is not a builtin");
|
||||
assert!(p.typ == ProcessType::Builtin, "Process is not a builtin");
|
||||
let mut out =
|
||||
create_output_stream_for_builtin(STDOUT_FILENO, io_chain, piped_output_needs_buffering);
|
||||
let mut err =
|
||||
@@ -1274,7 +1274,7 @@ fn exec_process_in_job(
|
||||
process_net_io_chain.push(Arc::new(IoClose::new(afd.as_raw_fd())));
|
||||
}
|
||||
|
||||
if p.typ != ProcessType::block_node {
|
||||
if p.typ != ProcessType::BlockNode {
|
||||
// A simple `begin ... end` should not be considered an execution of a command.
|
||||
parser.libdata_mut().exec_count += 1;
|
||||
}
|
||||
@@ -1310,21 +1310,21 @@ fn exec_process_in_job(
|
||||
// Execute the process.
|
||||
p.check_generations_before_launch();
|
||||
match p.typ {
|
||||
ProcessType::function | ProcessType::block_node => exec_block_or_func_process(
|
||||
ProcessType::Function | ProcessType::BlockNode => exec_block_or_func_process(
|
||||
parser,
|
||||
j,
|
||||
p,
|
||||
process_net_io_chain,
|
||||
piped_output_needs_buffering,
|
||||
),
|
||||
ProcessType::builtin => exec_builtin_process(
|
||||
ProcessType::Builtin => exec_builtin_process(
|
||||
parser,
|
||||
j,
|
||||
p,
|
||||
&process_net_io_chain,
|
||||
piped_output_needs_buffering,
|
||||
),
|
||||
ProcessType::external => {
|
||||
ProcessType::External => {
|
||||
parser.libdata_mut().exec_external_count += 1;
|
||||
exec_external_command(parser, j, p, &process_net_io_chain)?;
|
||||
// It's possible (though unlikely) that this is a background process which recycled a
|
||||
@@ -1332,7 +1332,7 @@ fn exec_process_in_job(
|
||||
parser.mut_wait_handles().remove_by_pid(p.pid().unwrap());
|
||||
Ok(())
|
||||
}
|
||||
ProcessType::exec => {
|
||||
ProcessType::Exec => {
|
||||
// We should have handled exec up above.
|
||||
panic!("process_type_t::exec process found in pipeline, where it should never be. Aborting.");
|
||||
}
|
||||
@@ -1353,13 +1353,13 @@ fn get_deferred_process(j: &Job) -> Option<usize> {
|
||||
}
|
||||
|
||||
// Skip execs, which can only appear at the front.
|
||||
if j.processes()[0].typ == ProcessType::exec {
|
||||
if j.processes()[0].typ == ProcessType::Exec {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Find the last non-external process, and return it if it pipes into an external process.
|
||||
for (i, p) in j.processes().iter().enumerate().rev() {
|
||||
if p.typ != ProcessType::external {
|
||||
if p.typ != ProcessType::External {
|
||||
return if p.is_last_in_job { None } else { Some(i) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,16 +565,16 @@ fn process_type_for_command(
|
||||
// Determine the process type, which depends on the statement decoration (command, builtin,
|
||||
// etc).
|
||||
match statement.decoration() {
|
||||
StatementDecoration::exec => ProcessType::exec,
|
||||
StatementDecoration::command => ProcessType::external,
|
||||
StatementDecoration::builtin => ProcessType::builtin,
|
||||
StatementDecoration::exec => ProcessType::Exec,
|
||||
StatementDecoration::command => ProcessType::External,
|
||||
StatementDecoration::builtin => ProcessType::Builtin,
|
||||
StatementDecoration::none => {
|
||||
if function::exists(cmd, ctx.parser()) {
|
||||
ProcessType::function
|
||||
ProcessType::Function
|
||||
} else if builtin_exists(cmd) {
|
||||
ProcessType::builtin
|
||||
ProcessType::Builtin
|
||||
} else {
|
||||
ProcessType::external
|
||||
ProcessType::External
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -720,7 +720,7 @@ fn populate_plain_process(
|
||||
|
||||
// Determine the process type.
|
||||
let mut process_type = self.process_type_for_command(ctx, statement, &cmd);
|
||||
let external_cmd = if [ProcessType::external, ProcessType::exec].contains(&process_type) {
|
||||
let external_cmd = if [ProcessType::External, ProcessType::Exec].contains(&process_type) {
|
||||
let parser = ctx.parser();
|
||||
// Determine the actual command. This may be an implicit cd.
|
||||
let external_cmd = path_try_get_path(&cmd, parser.vars());
|
||||
@@ -771,9 +771,9 @@ fn populate_plain_process(
|
||||
|
||||
// If we have defined a wrapper around cd, use it, otherwise use the cd builtin.
|
||||
process_type = if function::exists(L!("cd"), ctx.parser()) {
|
||||
ProcessType::function
|
||||
ProcessType::Function
|
||||
} else {
|
||||
ProcessType::builtin
|
||||
ProcessType::Builtin
|
||||
};
|
||||
} else {
|
||||
// Not implicit cd.
|
||||
@@ -831,7 +831,7 @@ fn populate_block_process(
|
||||
let mut redirections = RedirectionSpecList::new();
|
||||
let reason = self.determine_redirections(ctx, args_or_redirs, &mut redirections);
|
||||
if reason == EndExecutionReason::ok {
|
||||
proc.typ = ProcessType::block_node;
|
||||
proc.typ = ProcessType::BlockNode;
|
||||
proc.block_node_source = Some(Arc::clone(self.pstree()));
|
||||
proc.internal_block_node = Some(statement.into());
|
||||
proc.set_redirection_specs(redirections);
|
||||
@@ -1879,9 +1879,9 @@ fn use_job_control(&self, ctx: &OperationContext<'_>) -> bool {
|
||||
return false;
|
||||
}
|
||||
match get_job_control_mode() {
|
||||
JobControl::all => true,
|
||||
JobControl::interactive => ctx.parser().is_interactive(),
|
||||
JobControl::none => false,
|
||||
JobControl::All => true,
|
||||
JobControl::Interactive => ctx.parser().is_interactive(),
|
||||
JobControl::None => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
src/proc.rs
40
src/proc.rs
@@ -50,23 +50,23 @@
|
||||
pub enum ProcessType {
|
||||
/// A regular external command.
|
||||
#[default]
|
||||
external,
|
||||
External,
|
||||
/// A builtin command.
|
||||
builtin,
|
||||
Builtin,
|
||||
/// A shellscript function.
|
||||
function,
|
||||
Function,
|
||||
/// A block of commands, represented as a node.
|
||||
block_node,
|
||||
BlockNode,
|
||||
/// The exec builtin.
|
||||
exec,
|
||||
Exec,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum JobControl {
|
||||
all,
|
||||
interactive,
|
||||
none,
|
||||
All,
|
||||
Interactive,
|
||||
None,
|
||||
}
|
||||
|
||||
impl TryFrom<&wstr> for JobControl {
|
||||
@@ -74,11 +74,11 @@ impl TryFrom<&wstr> for JobControl {
|
||||
|
||||
fn try_from(value: &wstr) -> Result<Self, Self::Error> {
|
||||
if value == "full" {
|
||||
Ok(JobControl::all)
|
||||
Ok(JobControl::All)
|
||||
} else if value == "interactive" {
|
||||
Ok(JobControl::interactive)
|
||||
Ok(JobControl::Interactive)
|
||||
} else if value == "none" {
|
||||
Ok(JobControl::none)
|
||||
Ok(JobControl::None)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
@@ -582,13 +582,13 @@ pub fn swap(&self, pid: Pid) -> Option<Pid> {
|
||||
/// represents it. Shellscript functions, builtins and blocks of code may all need to spawn an
|
||||
/// external process that handles the piping and redirecting of IO for them.
|
||||
///
|
||||
/// If the process is of type [`ProcessType::external`] or [`ProcessType::exec`], `argv` is the argument
|
||||
/// If the process is of type [`ProcessType::External`] or [`ProcessType::Exec`], `argv` is the argument
|
||||
/// array and `actual_cmd` is the absolute path of the command to execute.
|
||||
///
|
||||
/// If the process is of type [`ProcessType::builtin`], `argv` is the argument vector, and `argv[0]` is
|
||||
/// If the process is of type [`ProcessType::Builtin`], `argv` is the argument vector, and `argv[0]` is
|
||||
/// the name of the builtin command.
|
||||
///
|
||||
/// If the process is of type [`ProcessType::function`], `argv` is the argument vector, and `argv[0]` is
|
||||
/// If the process is of type [`ProcessType::Function`], `argv` is the argument vector, and `argv[0]` is
|
||||
/// the name of the shellscript function.
|
||||
#[derive(Default)]
|
||||
pub struct Process {
|
||||
@@ -607,7 +607,7 @@ pub struct Process {
|
||||
/// The expanded variable assignments for this process, as specified by the `a=b cmd` syntax.
|
||||
pub variable_assignments: Vec<ConcreteAssignment>,
|
||||
|
||||
/// Actual command to pass to exec in case of process_type_t::external or process_type_t::exec.
|
||||
/// Actual command to pass to exec in case of ProcessType::External or ProcessType::Exec.
|
||||
pub actual_cmd: WString,
|
||||
|
||||
/// Generation counts for reaping.
|
||||
@@ -742,8 +742,8 @@ pub fn mark_aborted_before_launch(&self) {
|
||||
/// Return whether this process type is internal (block, function, or builtin).
|
||||
pub fn is_internal(&self) -> bool {
|
||||
match self.typ {
|
||||
ProcessType::builtin | ProcessType::function | ProcessType::block_node => true,
|
||||
ProcessType::external | ProcessType::exec => false,
|
||||
ProcessType::Builtin | ProcessType::Function | ProcessType::BlockNode => true,
|
||||
ProcessType::External | ProcessType::Exec => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,7 +764,7 @@ pub fn is_completed(&self) -> bool {
|
||||
/// As a process does not know its job id, we pass it in.
|
||||
/// Note this will return null if the process is not waitable (has no pid).
|
||||
pub fn make_wait_handle(&self, jid: InternalJobId) -> Option<WaitHandleRef> {
|
||||
if self.typ != ProcessType::external || self.pid().is_none() {
|
||||
if self.typ != ProcessType::External || self.pid().is_none() {
|
||||
// Not waitable.
|
||||
None
|
||||
} else {
|
||||
@@ -1203,13 +1203,13 @@ pub fn set_job_control_mode(mode: JobControl) {
|
||||
// tcsetpgrp(), but as fish is now a background process it will receive SIGTTOU and stop! Ensure
|
||||
// that doesn't happen by ignoring SIGTTOU.
|
||||
// Note that if we become interactive, we also ignore SIGTTOU.
|
||||
if mode == JobControl::all {
|
||||
if mode == JobControl::All {
|
||||
unsafe {
|
||||
libc::signal(SIGTTOU, SIG_IGN);
|
||||
}
|
||||
}
|
||||
}
|
||||
static JOB_CONTROL_MODE: AtomicU8 = AtomicU8::new(JobControl::interactive as u8);
|
||||
static JOB_CONTROL_MODE: AtomicU8 = AtomicU8::new(JobControl::Interactive as u8);
|
||||
|
||||
/// Notify the user about stopped or terminated jobs, and delete completed jobs from the job list.
|
||||
/// If `interactive` is set, allow removing interactive jobs; otherwise skip them.
|
||||
|
||||
Reference in New Issue
Block a user