launcher: add launch_delay option (#2227)

* launcher: add launch_delay option

* Centralized too

* Use in test

* Undo

* Windows too

* Format

* Fix cfg guard
This commit is contained in:
s1341 2024-05-20 10:06:33 +03:00 committed by GitHub
parent f324c60b02
commit 864c2259e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -461,6 +461,7 @@ unsafe fn fuzz(options: &FuzzerOptions) -> Result<(), Error> {
.configuration(EventConfig::AlwaysUnique)
.shmem_provider(shmem_provider)
.monitor(monitor)
.launch_delay(100)
.run_client(&mut run_client)
.cores(&options.cores)
.broker_port(options.broker_port)

View File

@ -15,7 +15,7 @@
use alloc::string::ToString;
#[cfg(feature = "std")]
use core::marker::PhantomData;
#[cfg(all(unix, feature = "std", feature = "fork"))]
#[cfg(feature = "std")]
use core::time::Duration;
use core::{
fmt::{self, Debug, Formatter},
@ -107,6 +107,9 @@ where
#[cfg(all(unix, feature = "std"))]
#[builder(default = None)]
stdout_file: Option<&'a str>,
/// The time in milliseconds to delay between child launches
#[builder(default = 10)]
launch_delay: u64,
/// The actual, opened, `stdout_file` - so that we keep it open until the end
#[cfg(all(unix, feature = "std", feature = "fork"))]
#[builder(setter(skip), default = None)]
@ -251,7 +254,7 @@ where
self.shmem_provider.post_fork(true)?;
#[cfg(feature = "std")]
std::thread::sleep(Duration::from_millis(index * 10));
std::thread::sleep(Duration::from_millis(index * self.launch_delay));
#[cfg(feature = "std")]
if !debug_output {
@ -399,6 +402,10 @@ where
stderr = Stdio::inherit();
};
}
#[cfg(feature = "std")]
std::thread::sleep(Duration::from_millis(id as u64 * self.launch_delay));
std::env::set_var(_AFL_LAUNCHER_CLIENT, id.to_string());
let mut child = startable_self()?;
let child = (if debug_output {
@ -508,6 +515,9 @@ where
/// A file name to write all client output to
#[builder(default = None)]
stdout_file: Option<&'a str>,
/// The time in milliseconds to delay between child launches
#[builder(default = 10)]
launch_delay: u64,
/// The actual, opened, `stdout_file` - so that we keep it open until the end
#[cfg(all(unix, feature = "std", feature = "fork"))]
#[builder(setter(skip), default = None)]
@ -659,7 +669,7 @@ where
log::info!("{:?} PostFork", unsafe { libc::getpid() });
self.shmem_provider.post_fork(true)?;
std::thread::sleep(Duration::from_millis(index * 10));
std::thread::sleep(Duration::from_millis(index * self.launch_delay));
if !debug_output {
if let Some(file) = &self.opened_stdout_file {