NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/57369: unexpected poll timeout on pipe



>Number:         57369
>Category:       kern
>Synopsis:       unexpected poll timeout on pipe
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 19 11:05:02 +0000 2023
>Originator:     YAMAMOTO Takashi
>Release:        NetBSD 9.3
>Organization:
>Environment:
NetBSD ushi 9.3 NetBSD 9.3 (GENERIC) #0: Thu Aug  4 15:30:37 UTC 2022  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
please see the following test code.
(it's available on github as well: https://github.com/yamt/garbage/blob/master/c/poll/test.c)
it succeeds on macOS and ubuntu.
but on netbsd, poll times out. (returns 0)
its 9.3 GENERIC kernel + older userland if it matters.

#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int
main()
{
        int pipefds[2];
        int ret;
        ret = pipe(pipefds);
        if (ret != 0) {
                printf("pipe failed\n");
                exit(1);
        }
        pid_t p = fork();
        if (p == -1) {
                printf("fork failed\n");
                exit(1);
        }
        if (p == 0) {
                /* sleep to ensure the parent starts poll before we exit */
                sleep(1);
                _Exit(0);
        }
        ret = close(pipefds[0]); /* read side */
        if (ret != 0) {
                printf("close failed unexpectdly\n");
                exit(1);
        }
        struct pollfd pfd;
        memset(&pfd, 0, sizeof(pfd));
        pfd.fd = pipefds[1]; /* write side */
        pfd.events = POLLHUP;
        ret = poll(&pfd, 1, 3000);
        if (ret != 1) {
                printf("poll returned unexpectd value %d\n", ret);
                exit(1);
        }
        printf("success\n");
        exit(0);
}

>How-To-Repeat:
see above
>Fix:



Home | Main Index | Thread Index | Old Index