static void *nbd_client_thread(void *arg)

{

    int fd = *(int *)arg;

    off_t size;

    size_t blocksize;

    uint32_t nbdflags;

    int sock;

    int ret;

    pthread_t show_parts_thread;



    do {

        sock = unix_socket_outgoing(sockpath);

        if (sock == -1) {

            goto out;

        }

    } while (sock == -1);



    ret = nbd_receive_negotiate(sock, NULL, &nbdflags,

                                &size, &blocksize);

    if (ret == -1) {

        goto out;

    }



    ret = nbd_init(fd, sock, nbdflags, size, blocksize);

    if (ret == -1) {

        goto out;

    }



    /* update partition table */

    pthread_create(&show_parts_thread, NULL, show_parts, NULL);



    if (verbose) {

        fprintf(stderr, "NBD device %s is now connected to %s\n",

                device, srcpath);

    } else {

        /* Close stderr so that the qemu-nbd process exits.  */

        dup2(STDOUT_FILENO, STDERR_FILENO);

    }



    ret = nbd_client(fd);

    if (ret) {

        goto out;

    }

    close(fd);

    kill(getpid(), SIGTERM);

    return (void *) EXIT_SUCCESS;



out:

    kill(getpid(), SIGTERM);

    return (void *) EXIT_FAILURE;

}

static void *nbd_client_thread(void *arg)

{

    int fd = *(int *)arg;

    off_t size;

    size_t blocksize;

    uint32_t nbdflags;

    int sock;

    int ret;

    pthread_t show_parts_thread;



    do {

        sock = unix_socket_outgoing(sockpath);

        if (sock == -1) {

            goto out;

        }

    } while (sock == -1);



    ret = nbd_receive_negotiate(sock, NULL, &nbdflags,

                                &size, &blocksize);

    if (ret == -1) {

        goto out;

    }



    ret = nbd_init(fd, sock, nbdflags, size, blocksize);

    if (ret == -1) {

        goto out;

    }



    

    pthread_create(&show_parts_thread, NULL, show_parts, NULL);



    if (verbose) {

        fprintf(stderr, "NBD device %s is now connected to %s\n",

                device, srcpath);

    } else {

        

        dup2(STDOUT_FILENO, STDERR_FILENO);

    }



    ret = nbd_client(fd);

    if (ret) {

        goto out;

    }

    close(fd);

    kill(getpid(), SIGTERM);

    return (void *) EXIT_SUCCESS;



out:

    kill(getpid(), SIGTERM);

    return (void *) EXIT_FAILURE;

}

static void *FUNC_0(void *VAR_0)

{

    int VAR_1 = *(int *)VAR_0;

    off_t size;

    size_t blocksize;

    uint32_t nbdflags;

    int VAR_2;

    int VAR_3;

    pthread_t show_parts_thread;



    do {

        VAR_2 = unix_socket_outgoing(sockpath);

        if (VAR_2 == -1) {

            goto out;

        }

    } while (VAR_2 == -1);



    VAR_3 = nbd_receive_negotiate(VAR_2, NULL, &nbdflags,

                                &size, &blocksize);

    if (VAR_3 == -1) {

        goto out;

    }



    VAR_3 = nbd_init(VAR_1, VAR_2, nbdflags, size, blocksize);

    if (VAR_3 == -1) {

        goto out;

    }



    

    pthread_create(&show_parts_thread, NULL, show_parts, NULL);



    if (verbose) {

        fprintf(stderr, "NBD device %s is now connected to %s\n",

                device, srcpath);

    } else {

        

        dup2(STDOUT_FILENO, STDERR_FILENO);

    }



    VAR_3 = nbd_client(VAR_1);

    if (VAR_3) {

        goto out;

    }

    close(VAR_1);

    kill(getpid(), SIGTERM);

    return (void *) EXIT_SUCCESS;



out:

    kill(getpid(), SIGTERM);

    return (void *) EXIT_FAILURE;

}

static void *FUNC_0(void *VAR_0)
{ int VAR_1 = *(int *)VAR_0; off_t size; size_t blocksize; uint32_t nbdflags; int VAR_2; int VAR_3; pthread_t show_parts_thread; do { VAR_2 = unix_socket_outgoing(sockpath); if (VAR_2 == -1) { goto out; } } while (VAR_2 == -1); VAR_3 = nbd_receive_negotiate(VAR_2, NULL, &nbdflags,
&size, &blocksize); if (VAR_3 == -1) { goto out; } VAR_3 = nbd_init(VAR_1, VAR_2, nbdflags, size, blocksize); if (VAR_3 == -1) { goto out; } pthread_create(&show_parts_thread, NULL, show_parts, NULL); if (verbose) { fprintf(stderr, "NBD device %s is now connected to %s\n",
device, srcpath); } else { dup2(STDOUT_FILENO, STDERR_FILENO); } VAR_3 = nbd_client(VAR_1); if (VAR_3) { goto out; } close(VAR_1); kill(getpid(), SIGTERM); return (void *) EXIT_SUCCESS; out:
kill(getpid(), SIGTERM); return (void *) EXIT_FAILURE; }