From 2102ae13d1471944dbf0666ff5b4a657582858d6 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Fri, 29 Nov 2024 19:36:40 +0100 Subject: [PATCH] Clean cfgs in executors/command.rs (#2735) * clean * triple tick --- libafl/src/executors/command.rs | 41 +++++++++++---------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/libafl/src/executors/command.rs b/libafl/src/executors/command.rs index ac1fe6d07f..946c45a695 100644 --- a/libafl/src/executors/command.rs +++ b/libafl/src/executors/command.rs @@ -5,52 +5,44 @@ use core::{ marker::PhantomData, ops::IndexMut, }; -#[cfg(unix)] -use std::os::unix::ffi::OsStrExt; -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] use std::{ ffi::{CStr, CString}, os::fd::AsRawFd, }; -#[cfg(feature = "std")] use std::{ ffi::{OsStr, OsString}, io::{Read, Write}, + os::unix::ffi::OsStrExt, path::{Path, PathBuf}, - process::Child, - process::{Command, Stdio}, + process::{Child, Command, Stdio}, time::Duration, }; -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] use libafl_bolts::core_affinity::CoreId; use libafl_bolts::{ fs::{get_unique_std_input_file, InputFile}, tuples::{Handle, MatchName, RefIndexable}, AsSlice, }; -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] use libc::STDIN_FILENO; -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] use nix::unistd::Pid; -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] use typed_builder::TypedBuilder; use super::HasTimeout; -#[cfg(all(feature = "std", unix))] -use crate::executors::Executor; -#[cfg(all(feature = "std", any(unix, doc)))] -use crate::executors::ExitKind; use crate::{ corpus::Corpus, - executors::{hooks::ExecutorHooksTuple, HasObservers}, - inputs::{HasTargetBytes, UsesInput}, + executors::{hooks::ExecutorHooksTuple, Executor, ExitKind, HasObservers}, + inputs::{HasTargetBytes, Input, UsesInput}, observers::{ObserversTuple, StdErrObserver, StdOutObserver}, state::{HasCorpus, HasExecutions, State, UsesState}, std::borrow::ToOwned, + Error, }; -#[cfg(feature = "std")] -use crate::{inputs::Input, Error}; /// How to deliver input to an external program /// `StdIn`: The target reads from stdin @@ -178,7 +170,7 @@ where /// /// This configurator was primarly developed to be used in conjunction with /// [`crate::executors::hooks::intel_pt::IntelPTHook`] -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] #[derive(Debug, Clone, PartialEq, Eq, TypedBuilder)] pub struct PTraceCommandConfigurator { #[builder(setter(into))] @@ -195,7 +187,7 @@ pub struct PTraceCommandConfigurator { timeout: u32, } -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] impl CommandConfigurator for PTraceCommandConfigurator where I: HasTargetBytes, @@ -331,7 +323,6 @@ where } // this only works on unix because of the reliance on checking the process signal for detecting OOM -#[cfg(all(feature = "std", unix))] impl CommandExecutor where S: State + HasExecutions + UsesInput, @@ -388,7 +379,6 @@ where } } -#[cfg(all(feature = "std", unix))] impl Executor for CommandExecutor where EM: UsesState, @@ -425,7 +415,7 @@ where } } -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(target_os = "linux")] impl Executor for CommandExecutor where EM: UsesState, @@ -759,8 +749,7 @@ impl CommandExecutorBuilder { /// A `CommandConfigurator` takes care of creating and spawning a [`Command`] for the [`CommandExecutor`]. /// # Example -#[cfg_attr(all(feature = "std", unix), doc = " ```")] -#[cfg_attr(not(all(feature = "std", unix)), doc = " ```ignore")] +/// ``` /// use std::{io::Write, process::{Stdio, Command, Child}, time::Duration}; /// use libafl::{Error, inputs::{BytesInput, HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::{UsesState, HasExecutions}}; /// use libafl_bolts::AsSlice; @@ -801,7 +790,6 @@ impl CommandExecutorBuilder { /// MyExecutor.into_executor(()) /// } /// ``` -#[cfg(all(feature = "std", unix))] pub trait CommandConfigurator: Sized { /// Get the stdout fn stdout_observer(&self) -> Option> { @@ -882,7 +870,6 @@ mod tests { }; #[test] - #[cfg(unix)] #[cfg_attr(miri, ignore)] fn test_builder() { let mut mgr = SimpleEventManager::new(SimpleMonitor::new(|status| {