NetBSD Problem Report #56718

From wiz@yt.nih.at  Wed Feb 16 15:22:51 2022
Return-Path: <wiz@yt.nih.at>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id DAF371A9239
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 16 Feb 2022 15:22:51 +0000 (UTC)
Message-Id: <20220216135123.4ABB81CB6A9C@yt.nih.at>
Date: Wed, 16 Feb 2022 14:51:23 +0100 (CET)
From: Thomas Klausner <wiz@NetBSD.org>
Reply-To: Thomas Klausner <wiz@NetBSD.org>
To: gnats-bugs@NetBSD.org
Subject: eventfd: fcntl(O_NONBLOCK) doesn't work
X-Send-Pr-Version: 3.95

>Number:         56718
>Category:       kern
>Synopsis:       eventfd: fcntl(O_NONBLOCK) doesn't work
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    thorpej
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 16 15:25:00 +0000 2022
>Closed-Date:    Fri Feb 18 14:00:32 +0000 2022
>Last-Modified:  Fri Feb 18 14:00:32 +0000 2022
>Originator:     Thomas Klausner
>Release:        NetBSD 9.99.93
>Organization:

>Environment:


Architecture: x86_64
Machine: amd64
>Description:
Setting an eventfd() to non-blocking mode using fcntl() returns
'operation not supported'.
However, software expects this to work (e.g. net/zeromq).
>How-To-Repeat:
Run net/zeromq's self tests.

Or this program:

#include <sys/eventfd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

int main() {
    int cflags = 0x400000;
    int s_ = eventfd (0, cflags);

    int flags = fcntl (s_, F_GETFL, 0);
    printf("eventfd flags are %d, O_NONBLOCK is %d\n", flags, O_NONBLOCK);
    if (flags == -1)
        flags = 0;
    int rc = fcntl (s_, F_SETFL, flags | O_NONBLOCK);
    printf("fcntl returned %d: %s\n", rc, strerror(errno));
}

It should return a success, but currently it prints

eventfd flags are 2, O_NONBLOCK is 4
fcntl returned -1: Operation not supported

>Fix:
Please.

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: kern-bug-people->thorpej
Responsible-Changed-By: thorpej@NetBSD.org
Responsible-Changed-When: Wed, 16 Feb 2022 15:49:37 +0000
Responsible-Changed-Why:
Take.


State-Changed-From-To: open->feedback
State-Changed-By: thorpej@NetBSD.org
State-Changed-When: Thu, 17 Feb 2022 16:29:32 +0000
State-Changed-Why:
Thanks for testing the patch out-of-band.  Please confirm with changes
checked into tree.


From: "Jason R Thorpe" <thorpej@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56718 CVS commit: src/sys/kern
Date: Thu, 17 Feb 2022 16:28:29 +0000

 Module Name:	src
 Committed By:	thorpej
 Date:		Thu Feb 17 16:28:29 UTC 2022

 Modified Files:
 	src/sys/kern: sys_eventfd.c sys_timerfd.c

 Log Message:
 Implement eventfd_ioctl() and handle FIONBIO so that fcntl(O_NONBLOCK)
 works.  While here, also implement FIONREAD and FIONWRITE, and document
 why we don't implement FIONSPACE.

 Also implement FIONBIO and FIONREAD for in timerfd_ioctl() (for the same
 reason).

 PR kern/56718


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/sys/kern/sys_eventfd.c
 cvs rdiff -u -r1.7 -r1.8 src/sys/kern/sys_timerfd.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: feedback->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Fri, 18 Feb 2022 14:00:32 +0000
State-Changed-Why:
Committed patch fixes the problem too, thank you!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.