diff --git a/samply/src/mac/codesign_setup.rs b/samply/src/mac/codesign_setup.rs index 418116d5..6af3b09b 100644 --- a/samply/src/mac/codesign_setup.rs +++ b/samply/src/mac/codesign_setup.rs @@ -10,9 +10,10 @@ const ENTITLEMENTS_XML: &str = r#" "#; -pub fn codesign_setup() { - print!( - r#" +pub fn codesign_setup(skip_prompt: bool) { + if !skip_prompt { + print!( + r#" On macOS, attaching to an existing process is only allowed to binaries with the com.apple.security.cs.debugger entitlement. The samply binary will be signed with this entitlement for your local machine only. The following command @@ -27,14 +28,15 @@ entitlements.xml contains: Press any key to continue, or Ctrl-C to cancel. "#, - env::current_exe().unwrap().display(), - ENTITLEMENTS_XML - ); + env::current_exe().unwrap().display(), + ENTITLEMENTS_XML + ); - let mut input = String::new(); - std::io::stdin() - .read_line(&mut input) - .expect("Failed to read input?"); + let mut input = String::new(); + std::io::stdin() + .read_line(&mut input) + .expect("Failed to read input?"); + } let mut entitlements_file = tempfile::Builder::new() .prefix("samply_entitlements") diff --git a/samply/src/main.rs b/samply/src/main.rs index f285b1e5..86193ff7 100644 --- a/samply/src/main.rs +++ b/samply/src/main.rs @@ -95,7 +95,7 @@ enum Action { /// Codesign the samply binary on macOS to allow attaching to processes. #[cfg(target_os = "macos")] - Setup, + Setup(SetupArgs), } #[derive(Debug, Args)] @@ -333,6 +333,13 @@ struct SymbolArgs { simpleperf_binary_cache: Option, } +#[derive(Debug, Args, Clone)] +pub struct SetupArgs { + /// Don't wait for confirmation to codesign. + #[arg(short = 'y', long)] + yes: bool, +} + #[derive(Debug, Args, Clone)] pub struct ProfileCreationArgs { /// Set a custom name for the recorded profile. @@ -491,8 +498,8 @@ fn main() { } #[cfg(target_os = "macos")] - Action::Setup => { - mac::codesign_setup::codesign_setup(); + Action::Setup(SetupArgs { yes }) => { + mac::codesign_setup::codesign_setup(yes); } } }