Clarify some API usages

This commit is contained in:
Ruihan Li 2025-04-21 23:51:16 +08:00 committed by Jianfeng Jiang
parent a993264265
commit d0719efcb4
4 changed files with 23 additions and 14 deletions

View File

@ -85,17 +85,13 @@ impl FileOps for StatFileOps {
let pid = process.pid(); let pid = process.pid();
let comm = process.executable_path(); let comm = process.executable_path();
let ppid = process.parent().pid();
let state = if process.status().is_zombie() { let state = if process.status().is_zombie() {
'Z' 'Z'
} else { } else {
'R' 'R'
}; };
let pgrp = if let Some(pgrp) = process.process_group() { let ppid = process.parent().pid();
pgrp.pgid() let pgrp = process.pgid();
} else {
0
};
let mut stat_output = String::new(); let mut stat_output = String::new();
writeln!( writeln!(

View File

@ -166,7 +166,7 @@ fn current_thread_sender_ids(signum: Option<&SigNum>, ctx: &Context) -> SignalSe
let euid = credentials.euid(); let euid = credentials.euid();
let sid = signum.and_then(|signum| { let sid = signum.and_then(|signum| {
if *signum == SIGCONT { if *signum == SIGCONT {
Some(ctx.process.session().unwrap().sid()) Some(ctx.process.sid())
} else { } else {
None None
} }

View File

@ -149,7 +149,7 @@ impl PosixThread {
if let Some(signum) = signum if let Some(signum) = signum
&& *signum == SIGCONT && *signum == SIGCONT
{ {
let receiver_sid = self.process().session().unwrap().sid(); let receiver_sid = self.process().sid();
if receiver_sid == sender.sid().unwrap() { if receiver_sid == sender.sid().unwrap() {
return Ok(()); return Ok(());
} }

View File

@ -344,11 +344,6 @@ impl Process {
// *********** Process group & Session *********** // *********** Process group & Session ***********
/// Returns the process group to which the process belongs.
pub fn process_group(&self) -> Option<Arc<ProcessGroup>> {
self.process_group.lock().upgrade()
}
/// Returns the process group ID of the process. /// Returns the process group ID of the process.
// //
// FIXME: If we call this method without holding the process table lock, it may return zero if // FIXME: If we call this method without holding the process table lock, it may return zero if
@ -365,9 +360,27 @@ impl Process {
self.session().map_or(0, |session| session.sid()) self.session().map_or(0, |session| session.sid())
} }
/// Returns the process group to which the process belongs.
///
/// **Deprecated:** This is a very poorly designed API. Almost every use of this API is wrong
/// because some race condition is not handled correctly. Such usages are being refactored and
/// this API will be removed soon. So DO NOT ATTEMPT TO USE THIS API IN NEW CODE unless you
/// know exactly what you're doing.
pub fn process_group(&self) -> Option<Arc<ProcessGroup>> {
self.process_group.lock().upgrade()
}
/// Returns the session to which the process belongs. /// Returns the session to which the process belongs.
///
/// **Deprecated:** This is a very poorly designed API. Almost every use of this API is wrong
/// because some race condition is not handled correctly. Such usages are being refactored and
/// this API will be removed soon. So DO NOT ATTEMPT TO USE THIS API IN NEW CODE unless you
/// know exactly what you're doing.
pub fn session(&self) -> Option<Arc<Session>> { pub fn session(&self) -> Option<Arc<Session>> {
self.process_group()?.session() self.process_group
.lock()
.upgrade()
.and_then(|group| group.session())
} }
/// Returns whether the process is session leader. /// Returns whether the process is session leader.