]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Fix pipe error codes
authorAndrei Tatar <andrei@unikraft.io>
Thu, 14 Sep 2023 08:58:45 +0000 (11:58 +0300)
committerRazvan Deaconescu <razvand@unikraft.io>
Fri, 20 Oct 2023 16:32:28 +0000 (19:32 +0300)
This change fixes incorrect return of error codes in the pipe module of
vfscore. Specifically:
- Return positive error codes from internal functions; syscall handlers
  expect positive errors and will negate them as required
- Do not set errno, rather return the error code
- Correctly return EINVAL when attempting to open a pipe with O_DIRECT,
  as we do not support packet mode pipes, and calling code needs to be
  made aware of this

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1093

lib/vfscore/pipe.c

index ac33cd97405bd2fb180c5239b3ff6ead5bb589f2..3b24cb52efebe82d8d820cab23ca99cd1f135f4f 100644 (file)
@@ -309,7 +309,7 @@ static int pipe_write(struct vnode *vnode,
 
        if (!pipe_file->r_refcount) {
                /* TODO before returning the error, send a SIGPIPE signal */
-               return -EPIPE;
+               return EPIPE;
        }
 
        uk_mutex_lock(&pipe_buf->wrlock);
@@ -447,8 +447,7 @@ static int pipe_seek(struct vnode *vnode __unused,
                        struct vfscore_file *vfscore_file __unused,
                        off_t off1 __unused, off_t off2 __unused)
 {
-       errno = ESPIPE;
-       return -1;
+       return ESPIPE;
 }
 
 static int pipe_ioctl(struct vnode *vnode,
@@ -468,7 +467,7 @@ static int pipe_ioctl(struct vnode *vnode,
                /* sys_ioctl() already sets f_flags, no need to do anything */
                return 0;
        default:
-               return -EINVAL;
+               return EINVAL;
        }
 }
 
@@ -699,6 +698,9 @@ UK_SYSCALL_R_DEFINE(int, pipe2, int*, pipefd, int, flags)
 {
        int rc;
 
+       if (flags & O_DIRECT)
+               return -EINVAL;
+
        rc = uk_syscall_r_pipe((long) pipefd);
        if (rc)
                return rc;