Merge branch 'misc_changes' into 'main'

Couple of improvements

See merge request redox-os/base!4
This commit is contained in:
Jeremy Soller
2025-03-31 20:27:08 +00:00
11 changed files with 9 additions and 79 deletions
+8 -10
View File
@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::env;
use std::ffi::CString;
use std::fs::{read_dir, File};
use std::io::{BufRead, BufReader, Result, Write};
use std::io::{BufRead, BufReader, Result};
use std::path::Path;
use std::process::Command;
@@ -186,15 +186,13 @@ pub fn run(file: &Path) -> Result<()> {
}
match command.spawn() {
Ok(child) => match child.wait_with_output() {
Ok(output) => {
std::io::stdout()
.write_all(output.stdout.as_slice())
.unwrap();
std::io::stderr()
.write_all(output.stderr.as_slice())
.unwrap();
println!("{cmd} done.");
Ok(mut child) => match child.wait() {
Ok(exit_status) => {
if !exit_status.success() {
println!("{cmd} failed with {exit_status}");
} else {
println!("{cmd} done.");
}
}
Err(err) => {
println!("init: failed to wait for '{}': {}", line, err)
-24
View File
@@ -57,30 +57,6 @@ impl SchemeMut for LogScheme {
Ok(id)
}
fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result<usize> {
if !buf.is_empty() {
return Err(Error::new(EINVAL));
}
let context = {
let handle = self.handles.get(&old_id).ok_or(Error::new(EBADF))?;
handle.context.clone()
};
let id = self.next_id;
self.next_id += 1;
self.handles.insert(
id,
LogHandle {
context,
bufs: BTreeMap::new(),
},
);
Ok(id)
}
fn read(&mut self, id: usize, _buf: &mut [u8], _offset: u64, _flags: u32) -> Result<usize> {
let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
-6
View File
@@ -8,7 +8,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyControlTerm {
pty: Rc<RefCell<Pty>>,
flags: usize,
@@ -28,10 +27,6 @@ impl PtyControlTerm {
}
impl Resource for PtyControlTerm {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
Rc::downgrade(&self.pty)
}
@@ -45,7 +40,6 @@ impl Resource for PtyControlTerm {
}
fn read(&mut self, buf: &mut [u8]) -> Result<Option<usize>> {
self.notified_read = false;
let mut pty = self.pty.borrow_mut();
-5
View File
@@ -9,7 +9,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyPgrp {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -25,10 +24,6 @@ impl PtyPgrp {
}
impl Resource for PtyPgrp {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
-1
View File
@@ -7,7 +7,6 @@ use syscall::flag::EventFlags;
use crate::pty::Pty;
pub trait Resource {
fn boxed_clone(&self) -> Box<dyn Resource>;
fn pty(&self) -> Weak<RefCell<Pty>>;
fn flags(&self) -> usize;
+1 -3
View File
@@ -64,9 +64,7 @@ impl SchemeBlock for PtyScheme {
let handle: Box<dyn Resource> = {
let old_handle = self.handles.get(&old_id).ok_or(Error::new(EBADF))?;
if buf.is_empty() {
old_handle.boxed_clone()
} else if buf == b"pgrp" {
if buf == b"pgrp" {
Box::new(PtyPgrp::new(old_handle.pty(), old_handle.flags()))
} else if buf == b"termios" {
Box::new(PtyTermios::new(old_handle.pty(), old_handle.flags()))
-6
View File
@@ -8,7 +8,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtySubTerm {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -28,10 +27,6 @@ impl PtySubTerm {
}
impl Resource for PtySubTerm {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
@@ -49,7 +44,6 @@ impl Resource for PtySubTerm {
}
fn read(&mut self, buf: &mut [u8]) -> Result<Option<usize>> {
self.notified_read = false;
if let Some(pty_lock) = self.pty.upgrade() {
-5
View File
@@ -9,7 +9,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyTermios {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -25,10 +24,6 @@ impl PtyTermios {
}
impl Resource for PtyTermios {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
-5
View File
@@ -9,7 +9,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyWinsize {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -25,10 +24,6 @@ impl PtyWinsize {
}
impl Resource for PtyWinsize {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
-6
View File
@@ -247,12 +247,6 @@ impl SchemeSync for Scheme {
fn unlink(&mut self, path: &str, ctx: &CallerCtx) -> Result<()> {
self.remove_dentry(path, ctx.uid, ctx.gid, false)
}
fn dup(&mut self, old_inode: usize, _buf: &[u8], _ctx: &CallerCtx) -> Result<OpenResult> {
Ok(OpenResult::ThisScheme {
number: old_inode,
flags: NewFdFlags::POSITIONED,
})
}
fn read(
&mut self,
inode: usize,
-8
View File
@@ -10,14 +10,6 @@ impl SchemeMut for ZeroScheme {
Ok(0)
}
fn dup(&mut self, _file: usize, buf: &[u8]) -> Result<usize> {
if !buf.is_empty() {
return Err(Error::new(EINVAL));
}
Ok(0)
}
fn read(&mut self, _file: usize, buf: &mut [u8], _offset: u64, _flags: u32) -> Result<usize> {
match self.0 {
Ty::Null => Ok(0),