Page MenuHomeFreeBSD

Linux epoll: Check both read and write kqueue events existence in EPOLL_CTL_ADD
ClosedPublic

Authored by wulf on Nov 23 2019, 12:07 PM.

Details

Summary

Linux epoll EPOLL_CTL_ADD op handler should always check registration
of both EVFILT_READ and EVFILT_WRITE kevents to deceide if supplied
file descriptor fd is already registered with epoll instance.

Test Plan
/* Sample testcase */

#include <sys/epoll.h> 
#include <assert.h>
#include <stdio.h> 
#include <stdlib.h>
#include <unistd.h>
   
int
main (int argc, char *argv[])
{
        struct epoll_event event;
        int epfd, err;

        epfd = epoll_create1(EPOLL_CLOEXEC);
        assert(epfd);

        event.events = EPOLLIN; 
        err = epoll_ctl(epfd, EPOLL_CTL_ADD, STDIN_FILENO, &event);
        assert(err == 0);

        event.events = EPOLLOUT;
        if (epoll_ctl(epfd, EPOLL_CTL_ADD, STDIN_FILENO, &event) == 0) {
                printf("EPOLL_CTL_ADD (erroneously) succeed\n");
                exit(EXIT_FAILURE);
        }

        printf("ok\n");
        return (EXIT_SUCCESS);
}

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Do you think we could add all of these test cases to the tree somewhere? (Not integrated w/ ATF presumably as we wouldn't have a convenient way to build Linux binaries.)

This revision is now accepted and ready to land.Nov 23 2019, 4:27 PM

Do you think we could add all of these test cases to the tree somewhere?

Good idea. I think we can add other permissive licensed epoll unit tests like https://github.com/jiixyj/epoll-shim/blob/master/test/epoll-test.c and https://github.com/cloudius-systems/osv/blob/master/tests/tst-epoll.cc . I will try to take a look at that.

(Not integrated w/ ATF presumably as we wouldn't have a convenient way to build Linux binaries.)

We can store precompiled i386 or amd64 binaries in VCS like we do with firmware blobs