Store process name.
This commit is contained in:
Generated
+7
@@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.4.0"
|
||||
@@ -18,6 +24,7 @@ checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
||||
name = "bootstrap"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"hashbrown",
|
||||
"linked_list_allocator",
|
||||
"log",
|
||||
|
||||
@@ -24,6 +24,7 @@ redox-scheme = { git = "https://gitlab.redox-os.org/redox-os/redox-scheme.git" }
|
||||
redox-rt = { git = "https://gitlab.redox-os.org/4lDO2/relibc.git", branch = "userspace_proc", default-features = false }
|
||||
redox-path = "0.3.1"
|
||||
slab = { version = "0.4.9", default-features = false }
|
||||
arrayvec = { version = "0.7.6", default-features = false }
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
@@ -5,6 +5,7 @@ use core::mem::size_of;
|
||||
use core::num::{NonZeroU8, NonZeroUsize};
|
||||
use core::ops::Deref;
|
||||
use core::ptr::NonNull;
|
||||
use core::str::FromStr;
|
||||
use core::sync::atomic::Ordering;
|
||||
use core::task::Poll::*;
|
||||
use core::task::{Context, Poll};
|
||||
@@ -15,6 +16,7 @@ use alloc::rc::{Rc, Weak};
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use arrayvec::ArrayString;
|
||||
use hashbrown::hash_map::{Entry, OccupiedEntry, VacantEntry};
|
||||
use hashbrown::{DefaultHashBuilder, HashMap, HashSet};
|
||||
|
||||
@@ -294,12 +296,15 @@ impl<T> Drop for Page<T> {
|
||||
}
|
||||
}
|
||||
|
||||
const NAME_CAPAC: usize = 32;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Process {
|
||||
threads: Vec<Rc<RefCell<Thread>>>,
|
||||
ppid: ProcessId,
|
||||
pgid: ProcessId,
|
||||
sid: ProcessId,
|
||||
name: ArrayString<NAME_CAPAC>,
|
||||
|
||||
ruid: u32,
|
||||
euid: u32,
|
||||
@@ -546,6 +551,7 @@ impl<'a> ProcScheme<'a> {
|
||||
sgid: 0,
|
||||
rns: 1,
|
||||
ens: 1,
|
||||
name: ArrayString::<32>::from_str("[init]").unwrap(),
|
||||
|
||||
status: ProcessStatus::PossiblyRunnable,
|
||||
awaiting_threads_term: Vec::new(),
|
||||
@@ -588,6 +594,7 @@ impl<'a> ProcScheme<'a> {
|
||||
sgid,
|
||||
ens,
|
||||
rns,
|
||||
name,
|
||||
..
|
||||
} = *proc_guard.borrow();
|
||||
|
||||
@@ -603,6 +610,7 @@ impl<'a> ProcScheme<'a> {
|
||||
euid,
|
||||
egid,
|
||||
ens,
|
||||
debug_name: arraystring_to_bytes(name),
|
||||
},
|
||||
)?;
|
||||
let status_fd = FdGuard::new(syscall::dup(
|
||||
@@ -635,6 +643,7 @@ impl<'a> ProcScheme<'a> {
|
||||
sgid,
|
||||
rns,
|
||||
ens,
|
||||
name,
|
||||
|
||||
status: ProcessStatus::PossiblyRunnable,
|
||||
awaiting_threads_term: Vec::new(),
|
||||
@@ -675,6 +684,7 @@ impl<'a> ProcScheme<'a> {
|
||||
euid: proc.euid,
|
||||
egid: proc.egid,
|
||||
ens: proc.ens,
|
||||
debug_name: arraystring_to_bytes(proc.name),
|
||||
},
|
||||
)?;
|
||||
|
||||
@@ -935,6 +945,10 @@ impl<'a> ProcScheme<'a> {
|
||||
self.on_sigdeq(fd_pid, payload).map(|()| 0),
|
||||
op,
|
||||
)),
|
||||
ProcCall::Rename => Ready(Response::new(
|
||||
self.on_proc_rename(fd_pid, payload).map(|()| 0),
|
||||
op,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2110,6 +2124,16 @@ impl<'a> ProcScheme<'a> {
|
||||
(buf.proc_control_addr % PAGE_SIZE) as u16,
|
||||
])
|
||||
}
|
||||
fn on_proc_rename(&mut self, pid: ProcessId, new_name_raw: &[u8]) -> Result<()> {
|
||||
let new_name = core::str::from_utf8(new_name_raw).map_err(|_| Error::new(EINVAL))?;
|
||||
let mut proc = self
|
||||
.processes
|
||||
.get(&pid)
|
||||
.ok_or(Error::new(ESRCH))?
|
||||
.borrow_mut();
|
||||
proc.name = ArrayString::from_str(&new_name[..new_name.len().min(NAME_CAPAC)]).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
fn on_sync_sigtctl(thread: &mut Thread) -> Result<()> {
|
||||
log::trace!("Sync tctl {:?}", thread.pid);
|
||||
let sigcontrol_fd = FdGuard::new(syscall::dup(*thread.fd, b"sighandler")?);
|
||||
@@ -2204,3 +2228,9 @@ enum KillTarget {
|
||||
Proc(ProcessId),
|
||||
Thread(Rc<RefCell<Thread>>),
|
||||
}
|
||||
fn arraystring_to_bytes<const C: usize>(s: ArrayString<C>) -> [u8; C] {
|
||||
let mut buf = [0_u8; C];
|
||||
let min = buf.len().min(s.len());
|
||||
buf[..min].copy_from_slice(&s.as_bytes()[..min]);
|
||||
buf
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user