Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix:命名管道读行为不符合posix规范问题" #1065

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 9 additions & 57 deletions kernel/src/ipc/pipe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use core::sync::atomic::compiler_fence;

use crate::{
arch::ipc::signal::{SigCode, Signal},
filesystem::vfs::{
core::generate_inode_id, file::FileMode, syscall::ModeType, FilePrivateData, FileSystem,
FileType, IndexNode, Metadata,
Expand All @@ -11,7 +8,7 @@ use crate::{
wait_queue::WaitQueue,
},
net::event_poll::{EPollEventType, EPollItem, EventPoll},
process::{ProcessManager, ProcessState},
process::ProcessState,
sched::SchedMode,
time::PosixTimeSpec,
};
Expand All @@ -23,8 +20,6 @@ use alloc::{
};
use system_error::SystemError;

use super::signal_types::{SigInfo, SigType};

/// 我们设定pipe_buff的总大小为1024字节
const PIPE_BUFF_SIZE: usize = 1024;

Expand Down Expand Up @@ -64,7 +59,6 @@ pub struct InnerPipeInode {
metadata: Metadata,
reader: u32,
writer: u32,
had_reader: bool,
epitems: SpinLock<LinkedList<Arc<EPollItem>>>,
}

Expand Down Expand Up @@ -137,7 +131,6 @@ impl LockedPipeInode {
valid_cnt: 0,
read_pos: 0,
write_pos: 0,
had_reader: false,
data: [0; PIPE_BUFF_SIZE],

metadata: Metadata {
Expand Down Expand Up @@ -285,27 +278,15 @@ impl IndexNode for LockedPipeInode {
mut data: SpinLockGuard<FilePrivateData>,
mode: &crate::filesystem::vfs::file::FileMode,
) -> Result<(), SystemError> {
let accmode = mode.accmode();
let mut guard = self.inner.lock();
// 不能以读写方式打开管道
if accmode == FileMode::O_RDWR.bits() {
if mode.contains(FileMode::O_RDWR) {
return Err(SystemError::EACCES);
} else if accmode == FileMode::O_RDONLY.bits() {
}
if mode.contains(FileMode::O_RDONLY) {
guard.reader += 1;
guard.had_reader = true;
// println!(
// "FIFO: pipe try open in read mode with reader pid:{:?}",
// ProcessManager::current_pid()
// );
} else if accmode == FileMode::O_WRONLY.bits() {
// println!(
// "FIFO: pipe try open in write mode with {} reader, writer pid:{:?}",
// guard.reader,
// ProcessManager::current_pid()
// );
if guard.reader == 0 && mode.contains(FileMode::O_NONBLOCK) {
return Err(SystemError::ENXIO);
}
}
if mode.contains(FileMode::O_WRONLY) {
guard.writer += 1;
}

Expand All @@ -330,11 +311,10 @@ impl IndexNode for LockedPipeInode {
} else {
return Err(SystemError::EBADF);
}
let accmode = mode.accmode();
let mut guard = self.inner.lock();

// 写端关闭
if accmode == FileMode::O_WRONLY.bits() {
if mode.contains(FileMode::O_WRONLY) {
assert!(guard.writer > 0);
guard.writer -= 1;
// 如果已经没有写端了,则唤醒读端
Expand All @@ -345,7 +325,7 @@ impl IndexNode for LockedPipeInode {
}

// 读端关闭
if accmode == FileMode::O_RDONLY.bits() {
if mode.contains(FileMode::O_RDONLY) {
assert!(guard.reader > 0);
guard.reader -= 1;
// 如果已经没有写端了,则唤醒读端
Expand Down Expand Up @@ -381,35 +361,7 @@ impl IndexNode for LockedPipeInode {
let mut inode = self.inner.lock();

if inode.reader == 0 {
if !inode.had_reader {
// 如果从未有读端,直接返回 ENXIO,无论是否阻塞模式
return Err(SystemError::ENXIO);
} else {
// 如果曾经有读端,现在已关闭
match mode.contains(FileMode::O_NONBLOCK) {
true => {
// 非阻塞模式,直接返回 EPIPE
return Err(SystemError::EPIPE);
}
false => {
let sig = Signal::SIGPIPE;
let mut info = SigInfo::new(
sig,
0,
SigCode::Kernel,
SigType::Kill(ProcessManager::current_pid()),
);
compiler_fence(core::sync::atomic::Ordering::SeqCst);

let _retval = sig
.send_signal_info(Some(&mut info), ProcessManager::current_pid())
.map(|x| x as usize);

compiler_fence(core::sync::atomic::Ordering::SeqCst);
return Err(SystemError::EPIPE);
}
}
}
// TODO: 如果已经没有读端存在了,则向写端进程发送SIGPIPE信号
}

// 如果管道空间不够
Expand Down
20 changes: 0 additions & 20 deletions user/apps/test_fifo_write/Makefile

This file was deleted.

210 changes: 0 additions & 210 deletions user/apps/test_fifo_write/main.c

This file was deleted.

Loading