From ffef36c736303a22fc8ee211a2412cd64f85a741 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 11 Aug 2020 00:03:33 +0900 Subject: [PATCH] sys/io: Rename cxio_pipe() to sys_pipe(); change several functions so they behave as documented --- sys/io/filedesc.c | 1 + sys/io/main.c | 2 ++ sys/io/pipe.c | 25 ++++++++++++++++++++++++- sys/io/pipe.h | 6 +++++- sys/io/proc.c | 10 +++++++--- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/sys/io/filedesc.c b/sys/io/filedesc.c index 7897001..9c7f40e 100644 --- a/sys/io/filedesc.c +++ b/sys/io/filedesc.c @@ -107,6 +107,7 @@ int fd_new(struct filedesc **dst) if(fd) { memset(fd, 0, sizeof(*fd)); fd->fd_refcnt = 1; + *dst = fd; ret_val = 0; } diff --git a/sys/io/main.c b/sys/io/main.c index c0be2d8..ab19875 100644 --- a/sys/io/main.c +++ b/sys/io/main.c @@ -4,6 +4,7 @@ #include #include #include +#include "pipe.h" static int _handle_msg(struct cxmsg *msg) { @@ -26,6 +27,7 @@ static int _handle_msg(struct cxmsg *msg) break; case CXIO_PIPE: + sys_pipe(msg->cm_src, (struct cxio_pipe*)msg->cm_data); memset(str, 0, sizeof(str)); len = snprintf(str, sizeof(str), "CXIO_PIPE from %u\n", msg->cm_src); debug(str, len); diff --git a/sys/io/pipe.c b/sys/io/pipe.c index 73953e7..cf1f234 100644 --- a/sys/io/pipe.c +++ b/sys/io/pipe.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "file.h" #include "proc.h" #include "filedesc.h" @@ -28,11 +30,23 @@ struct pipe { static ssize_t _pipe_read(struct file *file, void *dst, const size_t dst_size) { + char buf[128]; + int len; + + len = snprintf(buf, sizeof(buf), "%s(%p, %p, %lu)\n", __func__, file, dst, dst_size); + debug(buf, len); + return(-ENOSYS); } static ssize_t _pipe_write(struct file *file, const void *src, const size_t src_size) { + char buf[128]; + int len; + + len = snprintf(buf, sizeof(buf), "%s(%p, %p, %lu)\n", __func__, file, src, src_size); + debug(buf, len); + return(-ENOSYS); } @@ -63,7 +77,7 @@ int pipe_new(const int flags, struct file **dst) return(ret_val); } -void cxio_pipe(pid_t pid, struct cxio_pipe *req) +void sys_pipe(pid_t pid, struct cxio_pipe *req) { struct proc *proc; struct file *file; @@ -73,10 +87,16 @@ void cxio_pipe(pid_t pid, struct cxio_pipe *req) int err; int i; + char buf[128]; + int len; + file = NULL; memset(&fd, 0, sizeof(fd)); memset(&fildes, 0, sizeof(fildes)); + len = snprintf(buf, sizeof(buf), "%s(%d, %p)\n", __func__, pid, req); + debug(buf, len); + err = proc_lookup(pid, &proc); if(err < 0) { @@ -102,6 +122,9 @@ void cxio_pipe(pid_t pid, struct cxio_pipe *req) fd_set_file(fildes[i], file); fd[i] = proc_add_fd(proc, fildes[i]); + + len = snprintf(buf, sizeof(buf), "%s: pipe[%d]=%d fd=%p file=%p\n", __func__, i, fd[i], fildes[i], file); + debug(buf, len); } cleanup: diff --git a/sys/io/pipe.h b/sys/io/pipe.h index 951672a..2411147 100644 --- a/sys/io/pipe.h +++ b/sys/io/pipe.h @@ -1,7 +1,11 @@ #ifndef PIPE_H #define PIPE_H +#include + +struct file; + int pipe_new(const int, struct file**); -void cxio_pipe(pid_t, struct cxio_pipe*); +void sys_pipe(pid_t, struct cxio_pipe*); #endif /* PIPE_H */ diff --git a/sys/io/proc.c b/sys/io/proc.c index 0579490..ef49397 100644 --- a/sys/io/proc.c +++ b/sys/io/proc.c @@ -7,6 +7,7 @@ #include "filedesc.h" #define PROC_INITFDS 8 +#define PROC_MAXFDS 128 struct filedesc; @@ -145,10 +146,11 @@ int proc_new(const pid_t pid, struct proc **dst) new = malloc(sizeof(*new)); if(new) { - new->p_pid = pid; - memset(new, 0, sizeof(*new)); + new->p_pid = pid; + new->p_maxfds = PROC_MAXFDS; + ret_val = cx_array_new(PROC_INITFDS, &new->p_fds); if(!ret_val) { @@ -217,12 +219,14 @@ int proc_add_fd(struct proc *proc, struct filedesc *fd) if(proc && fd) { ret_val = -EMFILE; - if(proc->p_openfds <= proc->p_maxfds) { + if(proc->p_openfds < proc->p_maxfds) { ret_val = cx_array_set(proc->p_fds, proc->p_nextfd, fd); if(!ret_val) { fd_ref(fd); + ret_val = proc->p_nextfd; + proc->p_nextfd++; proc->p_openfds++; } -- 2.47.3