Keep track of process stdio FDs
This commit is contained in:
parent
134bc41511
commit
35b8f3b441
12
src/main.rs
12
src/main.rs
@ -10,6 +10,7 @@ use parking_lot::RwLock;
|
||||
struct Serv {
|
||||
fs_map: RwLock<HashMap<String, u64>>,
|
||||
mount_list: RwLock<HashMap<PathBuf, (u64, u64)>>,
|
||||
process_stdio: RwLock<HashMap<u64, [Option<(u64, u64)>; 3]>>,
|
||||
}
|
||||
|
||||
impl vfs_rpc::Server for Serv {
|
||||
@ -61,12 +62,23 @@ impl vfs_rpc::Server for Serv {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn set_stdio(&self, pid: u64, stdio: [Option<(u64, u64)>; 3]) -> Result<(), ()> {
|
||||
self.process_stdio.write().insert(pid, stdio);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_stdio(&self, from: u64) -> [Option<(u64, u64)>; 3] {
|
||||
let stdio = self.process_stdio.read().get(&from).copied().unwrap_or([None; 3]);
|
||||
stdio
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
vfs_rpc::register_server(Box::new(Serv {
|
||||
fs_map: RwLock::new(HashMap::new()),
|
||||
mount_list: RwLock::new(HashMap::new()),
|
||||
process_stdio: RwLock::new(HashMap::new()),
|
||||
}));
|
||||
syscalls::register(0);
|
||||
loop {
|
||||
|
@ -16,6 +16,8 @@ pub trait Server: Send + Sync {
|
||||
fn mount(&self, dev: &Path, kind: &str, path: &Path) -> Result<(), ()>;
|
||||
fn open(&self, path: &Path) -> Result<(u64, u64), ()>;
|
||||
fn unmount(&self, path: &Path) -> Result<(), ()>;
|
||||
fn set_stdio(&self, pid: u64, stdio: [Option<(u64, u64)>; 3]) -> Result<(), ()>;
|
||||
fn get_stdio(&self, from: u64) -> [Option<(u64, u64)>; 3];
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -65,6 +67,32 @@ impl Client {
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn set_stdio(&self, pid: u64, stdio: [Option<(u64, u64)>; 3]) -> Result<(), ()> {
|
||||
postcard::from_bytes(
|
||||
&rpc::send_call(
|
||||
self.0,
|
||||
PROTO,
|
||||
4,
|
||||
&postcard::to_stdvec(&(pid, stdio)).unwrap(),
|
||||
)
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_stdio(&self) -> [Option<(u64, u64)>; 3] {
|
||||
postcard::from_bytes(
|
||||
&rpc::send_call(
|
||||
self.0,
|
||||
PROTO,
|
||||
5,
|
||||
&[],
|
||||
)
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_server(server: Box<dyn Server>) {
|
||||
@ -96,5 +124,12 @@ fn callback(call: IncomingCall) {
|
||||
let path = postcard::from_bytes(call.args()).unwrap();
|
||||
let ret = postcard::to_stdvec(&server.unmount(path)).unwrap();
|
||||
call.send_return(&ret);
|
||||
} else if call.func == 4 {
|
||||
let (pid, stdio) = postcard::from_bytes(call.args()).unwrap();
|
||||
let ret = postcard::to_stdvec(&server.set_stdio(pid, stdio)).unwrap();
|
||||
call.send_return(&ret);
|
||||
} else if call.func == 5 {
|
||||
let ret = postcard::to_stdvec(&server.get_stdio(call.from)).unwrap();
|
||||
call.send_return(&ret);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user