Compare commits

..

1 Commits
exec ... master

@ -18,10 +18,13 @@ license = "GPL-3.0-or-later"
# #
# # Logging # # Logging
# Tracing can be disabled at compile-time for higher performance by disabling the `logging` feature (see above, but remove `,logging` from the features.) # Tracing can be disabled at compile-time for higher performance by disabling the `logging` feature (see above, but remove `,logging` from the features.)
default = ["mode-memfile", "logging"] default = ["mode-memfile", "mode-flags", "logging"]
## --- Modes --- ## ## --- Modes --- ##
# Enable all flag options
mode-flags = ["exec"]
# Mode: default # Mode: default
# Use physical-memory backed kernel file-descriptors. (see feature `memfile`.) # Use physical-memory backed kernel file-descriptors. (see feature `memfile`.)
mode-memfile = ["memfile"] #, "tracing/release_max_level_warn"] mode-memfile = ["memfile"] #, "tracing/release_max_level_warn"]
@ -32,6 +35,9 @@ mode-buffered = ["jemalloc", "bytes"]
## --- Individual features --- ## ## --- Individual features --- ##
# Enable `-exec/{}` flag options
exec = []
# Use an in-memory file for storage instead of a byte-buffer. # Use an in-memory file for storage instead of a byte-buffer.
# #
# This can draastically improve performance as it allows for the use of `splice()` and `send_file()` syscalls instead of many `read()` and `write()` ones. # This can draastically improve performance as it allows for the use of `splice()` and `send_file()` syscalls instead of many `read()` and `write()` ones.

@ -87,6 +87,7 @@ use sys::{
tell_file, tell_file,
}; };
#[cfg(feature="exec")]
mod exec; mod exec;
mod buffers; mod buffers;
@ -600,15 +601,20 @@ fn main() -> errors::DispersedResult<()> {
if_trace!(debug!("initialised")); if_trace!(debug!("initialised"));
//TODO: How to cleanly feature-gate `args`? //TODO: How to cleanly feature-gate `args`?
let opt = {
#[cfg(feature="logging")] let opt = { cfg_if!{
let _span = debug_span!("args"); if #[cfg(feature="exec")] {
#[cfg(feature="logging")] #[cfg(feature="logging")]
let _in_span = _span.enter(); let _span = debug_span!("args");
let parsed = parse_args()?; #[cfg(feature="logging")]
if_trace!(debug!("Parsed arguments: {parsed:?}")); let _in_span = _span.enter();
parsed let parsed = parse_args()?;
}; if_trace!(debug!("Parsed arguments: {parsed:?}"));
parsed
} else {
()
}
} };
//TODO: maybe look into fd SEALing? Maybe we can prevent a consumer process from reading from stdout until we've finished the transfer. The name SEAL sounds like it might have something to do with that? //TODO: maybe look into fd SEALing? Maybe we can prevent a consumer process from reading from stdout until we've finished the transfer. The name SEAL sounds like it might have something to do with that?
let execfile; let execfile;
@ -621,17 +627,25 @@ fn main() -> errors::DispersedResult<()> {
.wrap_err("Operation failed").with_note(|| "Strategy was `buffered`")?; .wrap_err("Operation failed").with_note(|| "Strategy was `buffered`")?;
} }
} }
// Transfer complete, run exec. // Transfer complete, run exec if enabled
let rc = if let Some(file) = execfile.get_exec_file() {
exec::spawn_from_sync(&file, opt).into_iter().try_fold(0i32, |opt, res| res.map(|x| opt | x.unwrap_or(0))) let rc = { cfg_if! {
} else { if #[cfg(feature="exec")] {
if_trace!(debug!("there is no file to apply potential -exec/{{}} to")); let rc = if let Some(file) = execfile.get_exec_file() {
Ok(0i32) exec::spawn_from_sync(&file, opt).into_iter().try_fold(0i32, |opt, res| res.map(|x| opt | x.unwrap_or(0)))
}.wrap_err("-exec/{} operations failed")?; } else {
if_trace!(match rc { if_trace!(debug!("there is no file to apply potential -exec/{{}} to"));
0 => trace!("-exec/{{}} operation(s all) returned 0 exit status"), Ok(0i32)
n => error!("-exec/{{}} operation(s) returned non-zero exit code (total: {}) or were killed by signal", n), }.wrap_err("-exec/{} operations failed")?;
}); if_trace!(match rc {
0 => trace!("-exec/{{}} operation(s all) returned 0 exit status"),
n => error!("-exec/{{}} operation(s) returned non-zero exit code (total: {}) or were killed by signal", n),
});
rc
} else {
0i32
}
} };
// Now that transfer is complete from buffer to `stdout`, close `stdout` pipe before exiting process. // Now that transfer is complete from buffer to `stdout`, close `stdout` pipe before exiting process.
if_trace!(info!("Transfer complete, closing `stdout` pipe")); if_trace!(info!("Transfer complete, closing `stdout` pipe"));
@ -644,7 +658,9 @@ fn main() -> errors::DispersedResult<()> {
}.wrap_err(eyre!("Failed to close stdout"))?; }.wrap_err(eyre!("Failed to close stdout"))?;
if rc != 0 { if rc != 0 {
if_trace!(error!("Exiting with non-zero code due to child(s) returning non-zero exit status")); //TODO: A flag to disable this? TODO: Also, a flag to stop printing to stdout so consumers of output can use just `-exec/{}` child process `stdout`s is enabled if cfg!(feature="exec") {
if_trace!(error!("Exiting with non-zero code due to child(s) returning non-zero exit status")); //TODO: A runtime flag to disable this? TODO: Also, a flag to stop printing to stdout so consumers of output can use just `-exec/{}` child process `stdout`s is enabled
}
std::process::exit(rc); std::process::exit(rc);
} }

Loading…
Cancel
Save