mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-30 00:00:15 +01:00
Fixed missing path in Uhyve
A missing path due to the isle kind shouldn't be treated as an error. Add the clap library to support commands.
This commit is contained in:
parent
abbcee0b46
commit
937d064450
6 changed files with 46 additions and 24 deletions
|
@ -12,6 +12,7 @@ errno = "0.2.3"
|
|||
inotify = "0.4"
|
||||
byteorder = "1"
|
||||
log = "0.3"
|
||||
clap = "2.24.2"
|
||||
|
||||
[dependencies.env_logger]
|
||||
version = "0.3"
|
||||
|
|
|
@ -32,14 +32,17 @@ pub fn new_isle(path: &str) -> Result<Box<Isle>> {
|
|||
|
||||
pub trait Isle {
|
||||
fn num(&self) -> u8;
|
||||
fn log_file(&self) -> Result<String>;
|
||||
fn log_path(&self) -> Result<String>;
|
||||
fn cpu_path(&self) -> Result<String>;
|
||||
fn log_file(&self) -> Option<String>;
|
||||
fn log_path(&self) -> Option<String>;
|
||||
fn cpu_path(&self) -> Option<String>;
|
||||
|
||||
fn run(&mut self) -> Result<()>;
|
||||
|
||||
fn is_available(&self) -> Result<bool> {
|
||||
let log = self.log_file()?;
|
||||
let log = match self.log_file() {
|
||||
Some(f) => f,
|
||||
None => return Ok(false)
|
||||
};
|
||||
|
||||
// open the log file
|
||||
let mut file = File::open(log)
|
||||
|
@ -63,7 +66,11 @@ pub trait Isle {
|
|||
let mut ino = Inotify::init().unwrap();
|
||||
|
||||
// watch on the log path
|
||||
let log_path = self.log_path()?;
|
||||
let log_path = match self.log_path() {
|
||||
Some(f) => f,
|
||||
None => return Ok(())
|
||||
};
|
||||
|
||||
ino.add_watch(Path::new(&log_path), watch_mask::MODIFY | watch_mask::CREATE).unwrap();
|
||||
|
||||
let mut buffer = [0; 1024];
|
||||
|
@ -92,7 +99,10 @@ pub trait Isle {
|
|||
fn stop(&self) -> Result<()> {
|
||||
debug!("Stop the HermitIsle");
|
||||
|
||||
let cpu_path = self.cpu_path()?;
|
||||
let cpu_path = match self.cpu_path() {
|
||||
Some(f) => f,
|
||||
None => return Ok(())
|
||||
};
|
||||
|
||||
let mut cpus_file = File::create(&cpu_path)
|
||||
.map_err(|_| Error::InvalidFile(cpu_path.clone()))?;
|
||||
|
|
|
@ -56,16 +56,16 @@ impl Isle for Multi {
|
|||
self.num
|
||||
}
|
||||
|
||||
fn log_file(&self) -> Result<String> {
|
||||
Ok(format!("/sys/hermit/isle{}/log", self.num))
|
||||
fn log_file(&self) -> Option<String> {
|
||||
Some(format!("/sys/hermit/isle{}/log", self.num))
|
||||
}
|
||||
|
||||
fn log_path(&self) -> Result<String> {
|
||||
Ok("/sys/hermit/".into())
|
||||
fn log_path(&self) -> Option<String> {
|
||||
Some("/sys/hermit/".into())
|
||||
}
|
||||
|
||||
fn cpu_path(&self) -> Result<String> {
|
||||
Ok(format!("/sys/hermit/isle{}/cpus", self.num))
|
||||
fn cpu_path(&self) -> Option<String> {
|
||||
Some(format!("/sys/hermit/isle{}/cpus", self.num))
|
||||
}
|
||||
|
||||
fn run(&mut self) -> Result<()> {
|
||||
|
|
|
@ -127,14 +127,14 @@ impl QEmu {
|
|||
|
||||
impl Isle for QEmu {
|
||||
fn num(&self) -> u8 { 0 }
|
||||
fn log_file(&self) -> Result<String> {
|
||||
Ok(self.tmp_file.clone())
|
||||
fn log_file(&self) -> Option<String> {
|
||||
Some(self.tmp_file.clone())
|
||||
}
|
||||
fn log_path(&self) -> Result<String> {
|
||||
Ok("/tmp".into())
|
||||
fn log_path(&self) -> Option<String> {
|
||||
Some("/tmp".into())
|
||||
}
|
||||
fn cpu_path(&self) -> Result<String> {
|
||||
Err(Error::InternalError)
|
||||
fn cpu_path(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn run(&mut self) -> Result<()> {
|
||||
|
|
|
@ -123,16 +123,16 @@ impl Isle for Uhyve {
|
|||
0
|
||||
}
|
||||
|
||||
fn log_file(&self) -> Result<String> {
|
||||
Err(Error::InternalError)
|
||||
fn log_file(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn log_path(&self) -> Result<String> {
|
||||
Err(Error::InternalError)
|
||||
fn log_path(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn cpu_path(&self) -> Result<String> {
|
||||
Err(Error::InternalError)
|
||||
fn cpu_path(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn run(&mut self) -> Result<()> {
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
extern crate log;
|
||||
extern crate env_logger;
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
|
||||
extern crate libc;
|
||||
extern crate memmap;
|
||||
extern crate elf;
|
||||
|
@ -37,6 +40,14 @@ fn main() {
|
|||
signal::sigaction(signal::SIGTERM, &sig_action).unwrap();
|
||||
}
|
||||
|
||||
/* let matches = clap_app!(proxy =>
|
||||
(version: "0.0.1")
|
||||
(author: "Lorenz Schmidt <bytesnake@mailbox.org>")
|
||||
(about: "Allows you to start and manage HermitCore isles")
|
||||
(@arg debug: -d ... "Sets the level of debugging information")
|
||||
).get_matches();
|
||||
*/
|
||||
|
||||
// create the isle, wait to be available and start it
|
||||
env::args().skip(1).next().ok_or(error::Error::MissingBinary)
|
||||
.and_then(|path| hermit::new_isle(&path))
|
||||
|
|
Loading…
Add table
Reference in a new issue