]> git.corax.cc Git - corax/commitdiff
sys/io: Rename cxio_pipe() to sys_pipe(); change several functions so they behave...
authorMatthias Kruk <m@m10k.eu>
Mon, 10 Aug 2020 15:03:33 +0000 (00:03 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 10 Aug 2020 15:03:33 +0000 (00:03 +0900)
sys/io/filedesc.c
sys/io/main.c
sys/io/pipe.c
sys/io/pipe.h
sys/io/proc.c

index 7897001acd7615d002da379e7291e789f817493e..9c7f40e1e539213fdd348981c72c5e42148cbc72 100644 (file)
@@ -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;
        }
 
index c0be2d8c823df1a2cd98ca50b8b29ebea1ab972f..ab19875b4f72bd589bbf21c068f15bd578d5bcee 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
+#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);
index 73953e77bb4e27e80dbf8bb598326b2d25854852..cf1f2344d8431f3cbc740ad89630243c338d9556 100644 (file)
@@ -4,6 +4,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <stdio.h>
+#include <crxstd.h>
 #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:
index 951672a5f0735f01fe40c5a1dbead2c463be0ec7..24111473c0463e93a932f66808c79133192ece8e 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef PIPE_H
 #define PIPE_H
 
+#include <corax/ipc/io.h>
+
+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 */
index 05794900a0df85c51af984354c901f31fd846160..ef49397eb73b1b1ff842ee5da3e2f33a0d0a4563 100644 (file)
@@ -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++;
                        }