mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-16 14:17:16 +00:00
main: Refine event monitor control
Replace "--monitor-fd" with "--event-monitor" which can either take "fd=<int>" or "path=<path>" which can point to e.g. a named pipe and allow more flexibility. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
3ef7c8eac5
commit
b65502c3c1
34
src/main.rs
34
src/main.rs
@ -17,6 +17,7 @@ extern crate event_monitor;
|
|||||||
use clap::{App, Arg, ArgGroup, ArgMatches};
|
use clap::{App, Arg, ArgGroup, ArgMatches};
|
||||||
use libc::EFD_NONBLOCK;
|
use libc::EFD_NONBLOCK;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
|
use option_parser::OptionParser;
|
||||||
use seccomp::SeccompAction;
|
use seccomp::SeccompAction;
|
||||||
use signal_hook::{
|
use signal_hook::{
|
||||||
consts::SIGSYS,
|
consts::SIGSYS,
|
||||||
@ -321,9 +322,9 @@ fn create_app<'a, 'b>(
|
|||||||
.group("vmm-config"),
|
.group("vmm-config"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("monitor-fd")
|
Arg::with_name("event-monitor")
|
||||||
.long("monitor-fd")
|
.long("event-monitor")
|
||||||
.help("File descriptor to report events on")
|
.help("File to report events on: file=<file> or fd=<fd>")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.min_values(1)
|
.min_values(1)
|
||||||
.group("vmm-config"),
|
.group("vmm-config"),
|
||||||
@ -516,11 +517,28 @@ fn main() {
|
|||||||
.expect("Missing argument: api-socket")
|
.expect("Missing argument: api-socket")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
if let Some(fd) = cmd_arguments
|
if let Some(monitor_config) = cmd_arguments.value_of("event-monitor") {
|
||||||
.value_of("monitor-fd")
|
let mut parser = OptionParser::new();
|
||||||
.map(|s| s.parse::<i32>().expect("Expect integral file descriptor"))
|
parser.add("path").add("fd");
|
||||||
{
|
parser
|
||||||
let file = unsafe { File::from_raw_fd(fd) };
|
.parse(monitor_config)
|
||||||
|
.expect("Error parsing event monitor config");
|
||||||
|
|
||||||
|
let file = if parser.is_set("fd") {
|
||||||
|
let fd = parser
|
||||||
|
.convert("fd")
|
||||||
|
.expect("Integral file descriptor expected")
|
||||||
|
.unwrap();
|
||||||
|
unsafe { File::from_raw_fd(fd) }
|
||||||
|
} else if parser.is_set("path") {
|
||||||
|
std::fs::OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open(parser.get("path").unwrap())
|
||||||
|
.expect("Error opening event monitor path")
|
||||||
|
} else {
|
||||||
|
panic!("--event-monitor requires either a fd or path provided")
|
||||||
|
};
|
||||||
event_monitor::set_monitor(file).expect("Expected setting monitor to succeed");
|
event_monitor::set_monitor(file).expect("Expected setting monitor to succeed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user