]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-event: Implement the EFD_NONBLOCK flag for eventfd
authorMarco Schlumpp <marco@unikraft.io>
Wed, 1 Feb 2023 13:40:47 +0000 (14:40 +0100)
committerUnikraft <monkey@unikraft.io>
Wed, 26 Apr 2023 11:03:55 +0000 (11:03 +0000)
This flag allows conveniently setting O_NONBLOCK without having to use
a separate `fcntl` call.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #754

lib/posix-event/eventfd.c

index ee88c8256cde1ea28465398fd8f77eacc2afb245..1434d9d64007eebb327f6671d59f39df375980f6 100644 (file)
@@ -323,7 +323,7 @@ static int do_eventfd(struct uk_alloc *a, unsigned int initval, int flags)
        struct dentry *vfs_dentry;
        struct vnode *vfs_vnode;
 
-       if (unlikely(flags & ~(EFD_CLOEXEC | EFD_SEMAPHORE)))
+       if (unlikely(flags & ~(EFD_CLOEXEC | EFD_SEMAPHORE | EFD_NONBLOCK)))
                return -EINVAL;
 
        /* Reserve a file descriptor number */
@@ -388,6 +388,12 @@ static int do_eventfd(struct uk_alloc *a, unsigned int initval, int flags)
        /* Only the dentry should hold a reference; release ours */
        vput(vfs_vnode);
 
+       if (flags & EFD_NONBLOCK) {
+               ret = fcntl(vfs_fd, F_SETFL, O_NONBLOCK);
+               /* Setting the O_NONBLOCK here must not fail */
+               UK_ASSERT(ret != -1);
+       }
+
        return vfs_fd;
 
 ERR_VFS_INSTALL: