]> git.corax.cc Git - corax/commitdiff
Clean up message handling in the stdio daemon by moving it into a separate function
authorMatthias Kruk <m@m10k.eu>
Fri, 31 Jan 2020 11:32:06 +0000 (20:32 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 31 Jan 2020 11:32:06 +0000 (20:32 +0900)
kernel/core/stdio.c

index 72c3c331261d1bc079197cf5b5b367b2e0b69071..3cc888cc3df5b05d3fab3700a8cdab2549c1e3d8 100644 (file)
@@ -30,8 +30,20 @@ static int stdio_flush(int fd)
        return(0);
 }
 
+struct fd {
+       int f_id;
+};
+
+struct proc {
+       pid_t p_pid;
+       int   p_nfds;
+
+       struct fd *p_fds;
+};
+
 void _stdio(void)
 {
+       struct state state;
        struct cxmsg msg;
        int err;
 
@@ -58,34 +70,10 @@ void _stdio(void)
                }
 
                /* msg.cm_len now contains the number of bytes in sio_data */
-
                if(err > 0) {
-                       switch(msg.cm_type) {
-                       case CX_MSG_READ:
-                               err = stdio_read(msg.cm_stdio.sio_fd,
-                                                                msg.cm_stdio.sio_data,
-                                                                msg.cm_len);
-                               break;
-
-                       case CX_MSG_WRITE:
-                               err = stdio_write(msg.cm_stdio.sio_fd,
-                                                                 msg.cm_stdio.sio_data,
-                                                                 msg.cm_len);
-                               break;
-
-                       case CX_MSG_FLUSH:
-                               err = stdio_flush(msg.cm_stdio.sio_fd);
-                               break;
-
-                       default:
-                               /* malformed input? */
-                               err = -EINVAL;
-                               break;
-                       }
-
                        msg.cm_dst = msg.cm_src;
                        msg.cm_type = CX_MSG_RETVAL;
-                       msg.cm_retval = err;
+                       msg.cm_retval = _handle_msg(&msg);
                        msg.cm_len = sizeof(msg.cm_hdr) + sizeof(int);
 
                        cxsend(msg.cm_dst, &msg);
@@ -94,3 +82,37 @@ void _stdio(void)
 
        return;
 }
+
+static int _handle_msg(struct cxmsg *msg)
+{
+       switch(msg->cm_type) {
+       case CX_OPEN:
+       case CX_CLOSE:
+       case CX_READ:
+       case CX_WRITE:
+       case CX_FCNTL:
+               err = -ENOSYS;
+               break;
+
+       case CX_MSG_READ:
+               err = stdio_read(msg->cm_stdio.sio_fd,
+                                                msg->cm_stdio.sio_data,
+                                                msg->cm_len);
+               break;
+
+       case CX_MSG_WRITE:
+               err = stdio_write(msg->cm_stdio.sio_fd,
+                                                 msg->cm_stdio.sio_data,
+                                                 msg->cm_len);
+               break;
+
+       case CX_MSG_FLUSH:
+               err = stdio_flush(msg->cm_stdio.sio_fd);
+               break;
+
+       default:
+               /* malformed input? */
+               err = -EINVAL;
+               break;
+       }
+}