openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/libmount/src/monitor.c
static int monitor_modify_epoll(struct libmnt_monitor* mn,
                                struct monitor_entry* me, int enable)
{
    assert(mn);
    assert(me);

    me->enable = enable ? 1 : 0;
    me->changed = 0;

    if (mn->fd < 0)
        return 0; /* no epoll, ignore request */

    if (enable)
    {
        struct epoll_event ev = {.events = me->events};
        int fd = me->opers->op_get_fd(mn, me);

        if (fd < 0)
            goto err;

        DBG(MONITOR, ul_debugobj(mn, " add fd=%d (for %s)", fd, me->path));

        ev.data.ptr = (void*)me;

        if (epoll_ctl(mn->fd, EPOLL_CTL_ADD, fd, &ev) < 0)
        {
            if (errno != EEXIST)
                goto err;
        }
        if (me->events & (EPOLLIN | EPOLLET))
        {
            /* Drain initial events generated for /proc/self/mountinfo */
            struct epoll_event events[1];
            while (epoll_wait(mn->fd, events, 1, 0) > 0)
                ;
        }
    }
    else if (me->fd)
    {
        DBG(MONITOR,
            ul_debugobj(mn, " remove fd=%d (for %s)", me->fd, me->path));
        if (epoll_ctl(mn->fd, EPOLL_CTL_DEL, me->fd, NULL) < 0)
        {
            if (errno != ENOENT)
                goto err;
        }
    }

    return 0;
err:
    return -errno;
}
/*
 * Add/Remove monitor entry to/from monitor epoll.
 */
Add/Remove monitor entry to/from monitor epoll.
Add / Remove monitor entry to / from monitor epoll .
static int monitor_modify_epoll(struct libmnt_monitor* mn,
                                struct monitor_entry* me, int enable)
{
    assert(mn);
    assert(me);
    me->enable = enable ? 1 : 0;
    me->changed = 0;
    if (mn->fd < 0)
        return 0; 
    if (enable)
    {
        struct epoll_event ev = {.events = me->events};
        int fd = me->opers->op_get_fd(mn, me);
        if (fd < 0)
            goto err;
        DBG(MONITOR, ul_debugobj(mn, " add fd=%d (for %s)", fd, me->path));
        ev.data.ptr = (void*)me;
        if (epoll_ctl(mn->fd, EPOLL_CTL_ADD, fd, &ev) < 0)
        {
            if (errno != EEXIST)
                goto err;
        }
        if (me->events & (EPOLLIN | EPOLLET))
        {
            struct epoll_event events[1];
            while (epoll_wait(mn->fd, events, 1, 0) > 0)
                ;
        }
    }
    else if (me->fd)
    {
        DBG(MONITOR,
            ul_debugobj(mn, " remove fd=%d (for %s)", me->fd, me->path));
        if (epoll_ctl(mn->fd, EPOLL_CTL_DEL, me->fd, NULL) < 0)
        {
            if (errno != ENOENT)
                goto err;
        }
    }
    return 0;
err:
    return -errno;
}
static int monitor_modify_epoll ( struct libmnt_monitor * mn , struct monitor_entry * me , int enable ) { assert ( mn ) ; assert ( me ) ; me -> enable = enable ? 1 : 0 ; me -> changed = 0 ; if ( mn -> fd < 0 ) return 0 ; if ( enable ) { struct epoll_event ev = { . events = me -> events } ; int fd = me -> opers -> op_get_fd ( mn , me ) ; if ( fd < 0 ) goto err ; DBG ( MONITOR , ul_debugobj ( mn , " " , fd , me -> path ) ) ; ev . data . ptr = ( void * ) me ; if ( epoll_ctl ( mn -> fd , EPOLL_CTL_ADD , fd , & ev ) < 0 ) { if ( errno != EEXIST ) goto err ; } if ( me -> events & ( EPOLLIN | EPOLLET ) ) { struct epoll_event events [ 1 ] ; while ( epoll_wait ( mn -> fd , events , 1 , 0 ) > 0 ) ; } } else if ( me -> fd ) { DBG ( MONITOR , ul_debugobj ( mn , " " , me -> fd , me -> path ) ) ; if ( epoll_ctl ( mn -> fd , EPOLL_CTL_DEL , me -> fd , NULL ) < 0 ) { if ( errno != ENOENT ) goto err ; } } return 0 ; err : return - errno ; }
Add/Remove monitor entry to/from monitor epoll.
Add / Remove monitor entry to / from monitor epoll .
/* no epoll, ignore request */ /* Drain initial events generated for /proc/self/mountinfo */