static void do_getfd(Monitor *mon, const QDict *qdict)

{

    const char *fdname = qdict_get_str(qdict, "fdname");

    mon_fd_t *monfd;

    int fd;



    fd = qemu_chr_get_msgfd(mon->chr);

    if (fd == -1) {

        monitor_printf(mon, "getfd: no file descriptor supplied via SCM_RIGHTS\n");

        return;

    }



    if (qemu_isdigit(fdname[0])) {

        monitor_printf(mon, "getfd: monitor names may not begin with a number\n");

        return;

    }



    fd = dup(fd);

    if (fd == -1) {

        monitor_printf(mon, "Failed to dup() file descriptor: %s\n",

                       strerror(errno));

        return;

    }



    LIST_FOREACH(monfd, &mon->fds, next) {

        if (strcmp(monfd->name, fdname) != 0) {

            continue;

        }



        close(monfd->fd);

        monfd->fd = fd;

        return;

    }



    monfd = qemu_mallocz(sizeof(mon_fd_t));

    monfd->name = qemu_strdup(fdname);

    monfd->fd = fd;



    LIST_INSERT_HEAD(&mon->fds, monfd, next);

}

static void do_getfd(Monitor *mon, const QDict *qdict)

{

    const char *fdname = qdict_get_str(qdict, "fdname");

    mon_fd_t *monfd;

    int fd;



    fd = qemu_chr_get_msgfd(mon->chr);

    if (fd == -1) {

        monitor_printf(mon, "getfd: no file descriptor supplied via SCM_RIGHTS\n");

        return;

    }



    if (qemu_isdigit(fdname[0])) {

        monitor_printf(mon, "getfd: monitor names may not begin with a number\n");

        return;

    }



    fd = dup(fd);

    if (fd == -1) {

        monitor_printf(mon, "Failed to dup() file descriptor: %s\n",

                       strerror(errno));

        return;

    }



    LIST_FOREACH(monfd, &mon->fds, next) {

        if (strcmp(monfd->name, fdname) != 0) {

            continue;

        }



        close(monfd->fd);

        monfd->fd = fd;

        return;

    }



    monfd = qemu_mallocz(sizeof(mon_fd_t));

    monfd->name = qemu_strdup(fdname);

    monfd->fd = fd;



    LIST_INSERT_HEAD(&mon->fds, monfd, next);

}

static void FUNC_0(Monitor *VAR_0, const QDict *VAR_1)

{

    const char *VAR_2 = qdict_get_str(VAR_1, "VAR_2");

    mon_fd_t *monfd;

    int VAR_3;



    VAR_3 = qemu_chr_get_msgfd(VAR_0->chr);

    if (VAR_3 == -1) {

        monitor_printf(VAR_0, "getfd: no file descriptor supplied via SCM_RIGHTS\n");

        return;

    }



    if (qemu_isdigit(VAR_2[0])) {

        monitor_printf(VAR_0, "getfd: monitor names may not begin with a number\n");

        return;

    }



    VAR_3 = dup(VAR_3);

    if (VAR_3 == -1) {

        monitor_printf(VAR_0, "Failed to dup() file descriptor: %s\n",

                       strerror(errno));

        return;

    }



    LIST_FOREACH(monfd, &VAR_0->fds, next) {

        if (strcmp(monfd->name, VAR_2) != 0) {

            continue;

        }



        close(monfd->VAR_3);

        monfd->VAR_3 = VAR_3;

        return;

    }



    monfd = qemu_mallocz(sizeof(mon_fd_t));

    monfd->name = qemu_strdup(VAR_2);

    monfd->VAR_3 = VAR_3;



    LIST_INSERT_HEAD(&VAR_0->fds, monfd, next);

}

static void FUNC_0(Monitor *VAR_0, const QDict *VAR_1)
{ const char *VAR_2 = qdict_get_str(VAR_1, "VAR_2"); mon_fd_t *monfd; int VAR_3; VAR_3 = qemu_chr_get_msgfd(VAR_0->chr); if (VAR_3 == -1) { monitor_printf(VAR_0, "getfd: no file descriptor supplied via SCM_RIGHTS\n"); return; } if (qemu_isdigit(VAR_2[0])) { monitor_printf(VAR_0, "getfd: monitor names may not begin with a number\n"); return; } VAR_3 = dup(VAR_3); if (VAR_3 == -1) { monitor_printf(VAR_0, "Failed to dup() file descriptor: %s\n",
strerror(errno)); return; } LIST_FOREACH(monfd, &VAR_0->fds, next) { if (strcmp(monfd->name, VAR_2) != 0) { continue; } close(monfd->VAR_3); monfd->VAR_3 = VAR_3; return; } monfd = qemu_mallocz(sizeof(mon_fd_t)); monfd->name = qemu_strdup(VAR_2); monfd->VAR_3 = VAR_3; LIST_INSERT_HEAD(&VAR_0->fds, monfd, next); }