fix: 检测不到ctrl+D的问题 && pid=1被kill的时候没报错的问题 (#1206)

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin
2025-06-12 14:23:29 +08:00
committed by GitHub
parent 774f9eb7ce
commit 2c6e9dee73
3 changed files with 22 additions and 1 deletions

View File

@ -284,6 +284,8 @@ pub trait BitMapOps<T: BitOps> {
fn last_false_index(&self) -> Option<usize>;
/// 获取指定index之后第一个为1的位的index
///
/// **注意**: 这个不包含当前的index位如果index位的值是1那么它是会跳过这个位的
fn next_index(&self, index: usize) -> Option<usize>;
/// 获取指定index之后第一个为0的位的index

View File

@ -1018,7 +1018,13 @@ impl NTtyData {
};
// 找到eol的坐标
let tmp = self.read_flags.next_index(tail);
// 注意next_index可能不包括起始位置所以我们需要手动检查tail位置
let tmp: Option<usize> = if self.read_flags.get(tail).unwrap_or(false) {
Some(tail)
} else {
self.read_flags.next_index(tail)
};
// 找到的话即为坐标未找到的话即为NTTY_BUFSIZE
let mut eol = if let Some(tmp) = tmp { tmp } else { size };
if eol > size {

View File

@ -412,6 +412,19 @@ impl ProcessManager {
///
/// 因此注意,传入的`exit_code`应该是已经完成了移位操作的
pub fn exit(exit_code: usize) -> ! {
// 检查是否是init进程尝试退出如果是则产生panic
let current_pcb = ProcessManager::current_pcb();
if current_pcb.pid() == Pid(1) {
log::error!(
"Init process (pid=1) attempted to exit with code {}. This should not happen and indicates a serious system error.",
exit_code
);
loop {
spin_loop();
}
}
drop(current_pcb);
// 关中断
let _irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
let pid: Pid;