Check file_table in PID directory before access

This commit is contained in:
Marsman1996
2025-06-22 17:21:14 +08:00
committed by Ruihan Li
parent 1c56fbc871
commit 826f56aeed
2 changed files with 8 additions and 7 deletions

View File

@ -27,7 +27,7 @@ impl FdDirOps {
.parent(parent)
.build()
.unwrap();
// Guard against the race condition when procfs is being accessed for an exiting process,
// This is for an exiting process that has not yet been reaped by its parent,
// whose file table may have already been released.
if let Some(file_table_ref) = file_table.lock().as_ref() {
file_table_ref

View File

@ -36,12 +36,13 @@ impl PidDirOps {
.volatile()
.build()
.unwrap();
file_table
.lock()
.as_ref()
.unwrap()
.read()
.register_observer(Arc::downgrade(&pid_inode) as _);
// This is for an exiting process that has not yet been reaped by its parent,
// whose file table may have already been released.
if let Some(file_table_ref) = file_table.lock().as_ref() {
file_table_ref
.read()
.register_observer(Arc::downgrade(&pid_inode) as _);
}
pid_inode
}