static int v9fs_receivefd(int sockfd, int *status)

{

    struct iovec iov;

    struct msghdr msg;

    struct cmsghdr *cmsg;

    int retval, data, fd;

    union MsgControl msg_control;



    iov.iov_base = &data;

    iov.iov_len = sizeof(data);



    memset(&msg, 0, sizeof(msg));

    msg.msg_iov = &iov;

    msg.msg_iovlen = 1;

    msg.msg_control = &msg_control;

    msg.msg_controllen = sizeof(msg_control);



    do {

        retval = recvmsg(sockfd, &msg, 0);

    } while (retval < 0 && errno == EINTR);

    if (retval <= 0) {

        return retval;

    }

    /*

     * data is set to V9FS_FD_VALID, if ancillary data is sent.  If this

     * request doesn't need ancillary data (fd) or an error occurred,

     * data is set to negative errno value.

     */

    if (data != V9FS_FD_VALID) {

        *status = data;

        return 0;

    }

    /*

     * File descriptor (fd) is sent in the ancillary data. Check if we

     * indeed received it. One of the reasons to fail to receive it is if

     * we exceeded the maximum number of file descriptors!

     */

    for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {

        if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||

            cmsg->cmsg_level != SOL_SOCKET ||

            cmsg->cmsg_type != SCM_RIGHTS) {

            continue;

        }

        fd = *((int *)CMSG_DATA(cmsg));

        *status = fd;

        return 0;

    }

    *status = -ENFILE;  /* Ancillary data sent but not received */

    return 0;

}

static int v9fs_receivefd(int sockfd, int *status)

{

    struct iovec iov;

    struct msghdr msg;

    struct cmsghdr *cmsg;

    int retval, data, fd;

    union MsgControl msg_control;



    iov.iov_base = &data;

    iov.iov_len = sizeof(data);



    memset(&msg, 0, sizeof(msg));

    msg.msg_iov = &iov;

    msg.msg_iovlen = 1;

    msg.msg_control = &msg_control;

    msg.msg_controllen = sizeof(msg_control);



    do {

        retval = recvmsg(sockfd, &msg, 0);

    } while (retval < 0 && errno == EINTR);

    if (retval <= 0) {

        return retval;

    }

    









    if (data != V9FS_FD_VALID) {

        *status = data;

        return 0;

    }

    









    for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {

        if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||

            cmsg->cmsg_level != SOL_SOCKET ||

            cmsg->cmsg_type != SCM_RIGHTS) {

            continue;

        }

        fd = *((int *)CMSG_DATA(cmsg));

        *status = fd;

        return 0;

    }

    *status = -ENFILE;  

    return 0;

}

static int FUNC_0(int VAR_0, int *VAR_1)

{

    struct iovec VAR_2;

    struct msghdr VAR_3;

    struct cmsghdr *VAR_4;

    int VAR_5, VAR_6, VAR_7;

    union MsgControl VAR_8;



    VAR_2.iov_base = &VAR_6;

    VAR_2.iov_len = sizeof(VAR_6);



    memset(&VAR_3, 0, sizeof(VAR_3));

    VAR_3.msg_iov = &VAR_2;

    VAR_3.msg_iovlen = 1;

    VAR_3.VAR_8 = &VAR_8;

    VAR_3.msg_controllen = sizeof(VAR_8);



    do {

        VAR_5 = recvmsg(VAR_0, &VAR_3, 0);

    } while (VAR_5 < 0 && errno == EINTR);

    if (VAR_5 <= 0) {

        return VAR_5;

    }

    









    if (VAR_6 != V9FS_FD_VALID) {

        *VAR_1 = VAR_6;

        return 0;

    }

    









    for (VAR_4 = CMSG_FIRSTHDR(&VAR_3); VAR_4; VAR_4 = CMSG_NXTHDR(&VAR_3, VAR_4)) {

        if (VAR_4->cmsg_len != CMSG_LEN(sizeof(int)) ||

            VAR_4->cmsg_level != SOL_SOCKET ||

            VAR_4->cmsg_type != SCM_RIGHTS) {

            continue;

        }

        VAR_7 = *((int *)CMSG_DATA(VAR_4));

        *VAR_1 = VAR_7;

        return 0;

    }

    *VAR_1 = -ENFILE;  

    return 0;

}

static int FUNC_0(int VAR_0, int *VAR_1)
{ struct iovec VAR_2; struct msghdr VAR_3; struct cmsghdr *VAR_4; int VAR_5, VAR_6, VAR_7; union MsgControl VAR_8; VAR_2.iov_base = &VAR_6; VAR_2.iov_len = sizeof(VAR_6); memset(&VAR_3, 0, sizeof(VAR_3)); VAR_3.msg_iov = &VAR_2; VAR_3.msg_iovlen = 1; VAR_3.VAR_8 = &VAR_8; VAR_3.msg_controllen = sizeof(VAR_8); do { VAR_5 = recvmsg(VAR_0, &VAR_3, 0); } while (VAR_5 < 0 && errno == EINTR); if (VAR_5 <= 0) { return VAR_5; } if (VAR_6 != V9FS_FD_VALID) { *VAR_1 = VAR_6; return 0; } for (VAR_4 = CMSG_FIRSTHDR(&VAR_3); VAR_4; VAR_4 = CMSG_NXTHDR(&VAR_3, VAR_4)) { if (VAR_4->cmsg_len != CMSG_LEN(sizeof(int)) ||
VAR_4->cmsg_level != SOL_SOCKET ||
VAR_4->cmsg_type != SCM_RIGHTS) { continue; } VAR_7 = *((int *)CMSG_DATA(VAR_4)); *VAR_1 = VAR_7; return 0; } *VAR_1 = -ENFILE; return 0; }