int unix_listen_opts(QemuOpts *opts, Error **errp)

{

    struct sockaddr_un un;

    const char *path = qemu_opt_get(opts, "path");

    int sock, fd;



    sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);

    if (sock < 0) {

        error_setg_errno(errp, errno, "Failed to create socket");

        return -1;

    }



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

    un.sun_family = AF_UNIX;

    if (path && strlen(path)) {

        snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);

    } else {

        char *tmpdir = getenv("TMPDIR");

        snprintf(un.sun_path, sizeof(un.sun_path), "%s/qemu-socket-XXXXXX",

                 tmpdir ? tmpdir : "/tmp");

        /*

         * This dummy fd usage silences the mktemp() unsecure warning.

         * Using mkstemp() doesn't make things more secure here

         * though.  bind() complains about existing files, so we have

         * to unlink first and thus re-open the race window.  The

         * worst case possible is bind() failing, i.e. a DoS attack.

         */

        fd = mkstemp(un.sun_path); close(fd);

        qemu_opt_set(opts, "path", un.sun_path);

    }



    unlink(un.sun_path);

    if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {

        error_setg_errno(errp, errno, "Failed to bind socket");

        goto err;

    }

    if (listen(sock, 1) < 0) {

        error_setg_errno(errp, errno, "Failed to listen on socket");

        goto err;

    }



    return sock;



err:

    closesocket(sock);

    return -1;

}

int unix_listen_opts(QemuOpts *opts, Error **errp)

{

    struct sockaddr_un un;

    const char *path = qemu_opt_get(opts, "path");

    int sock, fd;



    sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);

    if (sock < 0) {

        error_setg_errno(errp, errno, "Failed to create socket");

        return -1;

    }



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

    un.sun_family = AF_UNIX;

    if (path && strlen(path)) {

        snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);

    } else {

        char *tmpdir = getenv("TMPDIR");

        snprintf(un.sun_path, sizeof(un.sun_path), "%s/qemu-socket-XXXXXX",

                 tmpdir ? tmpdir : "/tmp");

        













        fd = mkstemp(un.sun_path); close(fd);

        qemu_opt_set(opts, "path", un.sun_path);

    }



    unlink(un.sun_path);

    if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {

        error_setg_errno(errp, errno, "Failed to bind socket");

        goto err;

    }

    if (listen(sock, 1) < 0) {

        error_setg_errno(errp, errno, "Failed to listen on socket");

        goto err;

    }



    return sock;



err:

    closesocket(sock);

    return -1;

}

int FUNC_0(QemuOpts *VAR_0, Error **VAR_1)

{

    struct sockaddr_un VAR_2;

    const char *VAR_3 = qemu_opt_get(VAR_0, "VAR_3");

    int VAR_4, VAR_5;



    VAR_4 = qemu_socket(PF_UNIX, SOCK_STREAM, 0);

    if (VAR_4 < 0) {

        error_setg_errno(VAR_1, errno, "Failed to create socket");

        return -1;

    }



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

    VAR_2.sun_family = AF_UNIX;

    if (VAR_3 && strlen(VAR_3)) {

        snprintf(VAR_2.sun_path, sizeof(VAR_2.sun_path), "%s", VAR_3);

    } else {

        char *VAR_6 = getenv("TMPDIR");

        snprintf(VAR_2.sun_path, sizeof(VAR_2.sun_path), "%s/qemu-socket-XXXXXX",

                 VAR_6 ? VAR_6 : "/tmp");

        













        VAR_5 = mkstemp(VAR_2.sun_path); close(VAR_5);

        qemu_opt_set(VAR_0, "VAR_3", VAR_2.sun_path);

    }



    unlink(VAR_2.sun_path);

    if (bind(VAR_4, (struct sockaddr*) &VAR_2, sizeof(VAR_2)) < 0) {

        error_setg_errno(VAR_1, errno, "Failed to bind socket");

        goto err;

    }

    if (listen(VAR_4, 1) < 0) {

        error_setg_errno(VAR_1, errno, "Failed to listen on socket");

        goto err;

    }



    return VAR_4;



err:

    closesocket(VAR_4);

    return -1;

}

int FUNC_0(QemuOpts *VAR_0, Error **VAR_1)
{ struct sockaddr_un VAR_2; const char *VAR_3 = qemu_opt_get(VAR_0, "VAR_3"); int VAR_4, VAR_5; VAR_4 = qemu_socket(PF_UNIX, SOCK_STREAM, 0); if (VAR_4 < 0) { error_setg_errno(VAR_1, errno, "Failed to create socket"); return -1; } memset(&VAR_2, 0, sizeof(VAR_2)); VAR_2.sun_family = AF_UNIX; if (VAR_3 && strlen(VAR_3)) { snprintf(VAR_2.sun_path, sizeof(VAR_2.sun_path), "%s", VAR_3); } else { char *VAR_6 = getenv("TMPDIR"); snprintf(VAR_2.sun_path, sizeof(VAR_2.sun_path), "%s/qemu-socket-XXXXXX",
VAR_6 ? VAR_6 : "/tmp"); VAR_5 = mkstemp(VAR_2.sun_path); close(VAR_5); qemu_opt_set(VAR_0, "VAR_3", VAR_2.sun_path); } unlink(VAR_2.sun_path); if (bind(VAR_4, (struct sockaddr*) &VAR_2, sizeof(VAR_2)) < 0) { error_setg_errno(VAR_1, errno, "Failed to bind socket"); goto err; } if (listen(VAR_4, 1) < 0) { error_setg_errno(VAR_1, errno, "Failed to listen on socket"); goto err; } return VAR_4; err:
closesocket(VAR_4); return -1; }