Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
remove binaries from hypervisor (#1960)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf authored and gavofyork committed Aug 19, 2016
1 parent 070a215 commit 34de330
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
35 changes: 15 additions & 20 deletions ipc/hypervisor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub struct Hypervisor {
ipc_addr: String,
service: Arc<HypervisorService>,
ipc_worker: RwLock<nanoipc::Worker<HypervisorService>>,
processes: RwLock<HashMap<BinaryId, Child>>,
modules: HashMap<IpcModuleId, (BinaryId, BootArgs)>,
processes: RwLock<HashMap<IpcModuleId, Child>>,
modules: HashMap<IpcModuleId, BootArgs>,
}

/// Boot arguments for binary
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

Expand All @@ -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); }
}

Expand All @@ -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);
});
}

Expand All @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion parity/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn sync
-> Result<SyncModules, NetworkError>
{
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();
Expand Down

0 comments on commit 34de330

Please sign in to comment.