pub struct RunOptions<'a> { /* private fields */ }Expand description
Options which can be used to customize arguments, environment and how the ELF is executed.
Implementations§
Source§impl<'a> RunOptions<'a>
impl<'a> RunOptions<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a blank new set of options ready for configuration.
All options are initially empty / set to false.
Sourcepub fn with_replace(self, replace: bool) -> Self
pub fn with_replace(self, replace: bool) -> Self
Toggles the replace mode. If set to true, the current process will be replaced by the executed binary.
Otherwise, fork() will be called and the current process will be able to wait for the child.
Sourcepub fn with_args(self, args: &'a [&'a str]) -> Self
pub fn with_args(self, args: &'a [&'a str]) -> Self
Set command line arguments for the executed binary.
These are the actual arguments passed to the program (argv[1], argv[2], etc.). The program name (argv[0]) is automatically set to the memfd path.
§Example
use memfd_runner::{run_with_options, RunOptions};
let elf_bytes = std::fs::read("/usr/bin/echo").unwrap();
let options = RunOptions::new().with_args(&["Hello", "World!"]);
let exit_code = run_with_options(&elf_bytes, options).unwrap();
// This executes: /proc/self/fd/X "Hello" "World!"Sourcepub fn with_env(self, env: &'a [&'a str]) -> Self
pub fn with_env(self, env: &'a [&'a str]) -> Self
Set environment variables for the executed binary. Environment variables should be in “KEY=value” format.
§Example
use memfd_runner::{run_with_options, RunOptions};
let elf_bytes = std::fs::read("/usr/bin/env").unwrap();
let options = RunOptions::new().with_env(&["PATH=/usr/bin", "HOME=/tmp"]);
let exit_code = run_with_options(&elf_bytes, options).unwrap();Sourcepub fn with_argv0(self, argv0: &'a str) -> Self
pub fn with_argv0(self, argv0: &'a str) -> Self
Set a custom argv[0] for the executed binary.
By default, argv[0] is set to the memfd path (/proc/self/fd/N). This method
allows you to customize what the executed program sees as its program name.
§Example
use memfd_runner::{run_with_options, RunOptions};
let elf_bytes = std::fs::read("/usr/bin/echo").unwrap();
let options = RunOptions::new()
.with_argv0("my-custom-program")
.with_args(&["Hello", "World!"]);
let exit_code = run_with_options(&elf_bytes, options).unwrap();
// The program sees argv[0] as "my-custom-program"Trait Implementations§
Source§impl<'a> Clone for RunOptions<'a>
impl<'a> Clone for RunOptions<'a>
Source§fn clone(&self) -> RunOptions<'a>
fn clone(&self) -> RunOptions<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more