From 34de330ed90c729d93291526461738a77cc66c89 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 19 Aug 2016 16:49:58 +0400 Subject: [PATCH] remove binaries from hypervisor (#1960) --- ipc/hypervisor/src/lib.rs | 35 +++++++++++++++-------------------- parity/modules.rs | 2 +- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/ipc/hypervisor/src/lib.rs b/ipc/hypervisor/src/lib.rs index 16b6896bd..3e82908cd 100644 --- a/ipc/hypervisor/src/lib.rs +++ b/ipc/hypervisor/src/lib.rs @@ -41,8 +41,8 @@ pub struct Hypervisor { ipc_addr: String, service: Arc, ipc_worker: RwLock>, - processes: RwLock>, - modules: HashMap, + processes: RwLock>, + modules: HashMap, } /// Boot arguments for binary @@ -79,8 +79,8 @@ impl Hypervisor { Hypervisor::with_url(HYPERVISOR_IPC_URL) } - pub fn module(mut self, module_id: IpcModuleId, binary_id: BinaryId, args: BootArgs) -> Hypervisor { - self.modules.insert(module_id, (binary_id, args)); + pub fn module(mut self, module_id: IpcModuleId, args: BootArgs) -> Hypervisor { + self.modules.insert(module_id, args); self.service.add_module(module_id); self } @@ -106,7 +106,7 @@ impl Hypervisor { /// Since one binary can host multiple modules /// we match binaries - fn match_module(&self, module_id: &IpcModuleId) -> Option<&(BinaryId, BootArgs)> { + fn match_module(&self, module_id: &IpcModuleId) -> Option<&BootArgs> { self.modules.get(module_id) } @@ -126,24 +126,19 @@ impl Hypervisor { fn start_module(&self, module_id: IpcModuleId) { use std::io::Write; - self.match_module(&module_id).map(|&(ref binary_id, ref binary_args)| { + self.match_module(&module_id).map(|boot_args| { let mut processes = self.processes.write().unwrap(); { - if processes.get(binary_id).is_some() { + if processes.get(&module_id).is_some() { // already started for another module return; } } - let mut executable_path = std::env::current_exe().unwrap(); - executable_path.pop(); - executable_path.push(binary_id); - - let executable_path = executable_path.to_str().unwrap(); - let mut command = Command::new(&executable_path); + let mut command = Command::new(&std::env::current_exe().unwrap()); command.stderr(std::process::Stdio::inherit()); - if let Some(ref cli_args) = binary_args.cli { + if let Some(ref cli_args) = boot_args.cli { for arg in cli_args { command.arg(arg); } } @@ -152,18 +147,18 @@ impl Hypervisor { trace!(target: "hypervisor", "Spawn executable: {:?}", command); let mut child = command.spawn().unwrap_or_else( - |e| panic!("Hypervisor cannot start binary ({:?}): {}", executable_path, e)); + |e| panic!("Hypervisor cannot execute command ({:?}): {}", command, e)); - if let Some(ref std_in) = binary_args.stdin { + if let Some(ref std_in) = boot_args.stdin { trace!(target: "hypervisor", "Pushing std-in payload..."); child.stdin.as_mut() .expect("std-in should be piped above") .write(std_in) - .unwrap_or_else(|e| panic!(format!("Error trying to pipe stdin for {}: {:?}", &executable_path, e))); + .unwrap_or_else(|e| panic!(format!("Error trying to pipe stdin for {:?}: {:?}", &command, e))); drop(child.stdin.take()); } - processes.insert(binary_id, child); + processes.insert(module_id, child); }); } @@ -185,8 +180,8 @@ impl Hypervisor { if wait_time.is_some() { std::thread::sleep(wait_time.unwrap()) } let mut childs = self.processes.write().unwrap(); - for (ref mut binary, ref mut child) in childs.iter_mut() { - trace!(target: "hypervisor", "Stopping process module: {}", binary); + for (ref mut module, ref mut child) in childs.iter_mut() { + trace!(target: "hypervisor", "Stopping process module: {}", module); child.kill().unwrap(); } } diff --git a/parity/modules.rs b/parity/modules.rs index 5ae5db231..a41fc58b6 100644 --- a/parity/modules.rs +++ b/parity/modules.rs @@ -105,7 +105,7 @@ pub fn sync -> Result { let mut hypervisor = hypervisor_ref.take().expect("There should be hypervisor for ipc configuration"); - hypervisor = hypervisor.module(SYNC_MODULE_ID, "parity", sync_arguments(sync_cfg, net_cfg, log_settings)); + hypervisor = hypervisor.module(SYNC_MODULE_ID, sync_arguments(sync_cfg, net_cfg, log_settings)); hypervisor.start(); hypervisor.wait_for_startup();