]> git.corax.cc Git - corax/commitdiff
sys/io: Send a response at the end of sys_pipe()
authorMatthias Kruk <m@m10k.eu>
Mon, 10 Aug 2020 15:47:46 +0000 (00:47 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 10 Aug 2020 15:47:46 +0000 (00:47 +0900)
sys/io/pipe.c

index cf1f2344d8431f3cbc740ad89630243c338d9556..e3a6ab56e17836bc1f0edc0b095d9bcc1142a0d5 100644 (file)
@@ -82,20 +82,22 @@ void sys_pipe(pid_t pid, struct cxio_pipe *req)
        struct proc *proc;
        struct file *file;
        struct filedesc *fildes[2];
+       struct cxmsg resp;
+       struct cxio_response *ioresp;
+
        int fd[2];
 
        int err;
        int i;
 
-       char buf[128];
-       int len;
-
        file = NULL;
-       memset(&fd, 0, sizeof(fd));
-       memset(&fildes, 0, sizeof(fildes));
+       fd[0] = -1;
+       fd[1] = -1;
 
-       len = snprintf(buf, sizeof(buf), "%s(%d, %p)\n", __func__, pid, req);
-       debug(buf, len);
+       ioresp = (struct cxio_response*)resp.cm_data;
+
+       memset(&resp, 0, sizeof(resp));
+       memset(&fildes, 0, sizeof(fildes));
 
        err = proc_lookup(pid, &proc);
 
@@ -114,6 +116,9 @@ void sys_pipe(pid_t pid, struct cxio_pipe *req)
        }
 
        for(i = 0; i < 2; i++) {
+               char buf[128];
+               int len;
+
                err = fd_new(&fildes[i]);
 
                if(err < 0) {
@@ -121,7 +126,13 @@ void sys_pipe(pid_t pid, struct cxio_pipe *req)
                }
 
                fd_set_file(fildes[i], file);
-               fd[i] = proc_add_fd(proc, fildes[i]);
+               err = proc_add_fd(proc, fildes[i]);
+
+               if(err < 0) {
+                       goto cleanup;
+               }
+
+               fd[i] = err;
 
                len = snprintf(buf, sizeof(buf), "%s: pipe[%d]=%d fd=%p file=%p\n", __func__, i, fd[i], fildes[i], file);
                debug(buf, len);
@@ -138,7 +149,22 @@ cleanup:
                                fd_free(fildes[i]);
                        }
                }
+
+               ioresp->retval = -1;
+               ioresp->error = -err;
+       } else {
+               ioresp->retval = 0;
+               ioresp->error = 0;
+
+               ioresp->extralen = sizeof(fd);
+               memcpy(ioresp->extradata, &fd, sizeof(fd));
        }
 
+       ioresp->fd = -1;
+       resp.cm_type = CXIO_RESPONSE;
+       resp.cm_len = ioresp->extralen + sizeof(*ioresp);
+
+       cxsend(pid, &resp);
+
        return;
 }