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,7 +601,9 @@ 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 = {
let opt = { cfg_if!{
if #[cfg(feature="exec")] {
#[cfg(feature="logging")] #[cfg(feature="logging")]
let _span = debug_span!("args"); let _span = debug_span!("args");
#[cfg(feature="logging")] #[cfg(feature="logging")]
@ -608,7 +611,10 @@ fn main() -> errors::DispersedResult<()> {
let parsed = parse_args()?; let parsed = parse_args()?;
if_trace!(debug!("Parsed arguments: {parsed:?}")); if_trace!(debug!("Parsed arguments: {parsed:?}"));
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,7 +627,10 @@ 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 = { cfg_if! {
if #[cfg(feature="exec")] {
let rc = if let Some(file) = execfile.get_exec_file() { 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))) exec::spawn_from_sync(&file, opt).into_iter().try_fold(0i32, |opt, res| res.map(|x| opt | x.unwrap_or(0)))
} else { } else {
@ -632,6 +641,11 @@ fn main() -> errors::DispersedResult<()> {
0 => trace!("-exec/{{}} operation(s all) returned 0 exit status"), 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), 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