static int xen_domain_watcher(void)

{

    int qemu_running = 1;

    int fd[2], i, n, rc;

    char byte;



    if (pipe(fd) != 0) {

        qemu_log("%s: Huh? pipe error: %s\n", __FUNCTION__, strerror(errno));

        return -1;

    }

    if (fork() != 0)

        return 0; /* not child */



    /* close all file handles, except stdio/out/err,

     * our watch pipe and the xen interface handle */

    n = getdtablesize();

    for (i = 3; i < n; i++) {

        if (i == fd[0])

            continue;

        if (i == xen_xc)

            continue;

        close(i);

    }



    /* ignore term signals */

    signal(SIGINT,  SIG_IGN);

    signal(SIGTERM, SIG_IGN);



    /* wait for qemu exiting */

    while (qemu_running) {

        rc = read(fd[0], &byte, 1);

        switch (rc) {

        case -1:

            if (errno == EINTR)

                continue;

            qemu_log("%s: Huh? read error: %s\n", __FUNCTION__, strerror(errno));

            qemu_running = 0;

            break;

        case 0:

            /* EOF -> qemu exited */

            qemu_running = 0;

            break;

        default:

            qemu_log("%s: Huh? data on the watch pipe?\n", __FUNCTION__);

            break;

        }

    }



    /* cleanup */

    qemu_log("%s: destroy domain %d\n", __FUNCTION__, xen_domid);

    xc_domain_destroy(xen_xc, xen_domid);

    _exit(0);

}

static int xen_domain_watcher(void)

{

    int qemu_running = 1;

    int fd[2], i, n, rc;

    char byte;



    if (pipe(fd) != 0) {

        qemu_log("%s: Huh? pipe error: %s\n", __FUNCTION__, strerror(errno));

        return -1;

    }

    if (fork() != 0)

        return 0; 



    



    n = getdtablesize();

    for (i = 3; i < n; i++) {

        if (i == fd[0])

            continue;

        if (i == xen_xc)

            continue;

        close(i);

    }



    

    signal(SIGINT,  SIG_IGN);

    signal(SIGTERM, SIG_IGN);



    

    while (qemu_running) {

        rc = read(fd[0], &byte, 1);

        switch (rc) {

        case -1:

            if (errno == EINTR)

                continue;

            qemu_log("%s: Huh? read error: %s\n", __FUNCTION__, strerror(errno));

            qemu_running = 0;

            break;

        case 0:

            

            qemu_running = 0;

            break;

        default:

            qemu_log("%s: Huh? data on the watch pipe?\n", __FUNCTION__);

            break;

        }

    }



    

    qemu_log("%s: destroy domain %d\n", __FUNCTION__, xen_domid);

    xc_domain_destroy(xen_xc, xen_domid);

    _exit(0);

}

static int FUNC_0(void)

{

    int VAR_0 = 1;

    int VAR_1[2], VAR_2, VAR_3, VAR_4;

    char VAR_5;



    if (pipe(VAR_1) != 0) {

        qemu_log("%s: Huh? pipe error: %s\VAR_3", __FUNCTION__, strerror(errno));

        return -1;

    }

    if (fork() != 0)

        return 0; 



    



    VAR_3 = getdtablesize();

    for (VAR_2 = 3; VAR_2 < VAR_3; VAR_2++) {

        if (VAR_2 == VAR_1[0])

            continue;

        if (VAR_2 == xen_xc)

            continue;

        close(VAR_2);

    }



    

    signal(SIGINT,  SIG_IGN);

    signal(SIGTERM, SIG_IGN);



    

    while (VAR_0) {

        VAR_4 = read(VAR_1[0], &VAR_5, 1);

        switch (VAR_4) {

        case -1:

            if (errno == EINTR)

                continue;

            qemu_log("%s: Huh? read error: %s\VAR_3", __FUNCTION__, strerror(errno));

            VAR_0 = 0;

            break;

        case 0:

            

            VAR_0 = 0;

            break;

        default:

            qemu_log("%s: Huh? data on the watch pipe?\VAR_3", __FUNCTION__);

            break;

        }

    }



    

    qemu_log("%s: destroy domain %d\VAR_3", __FUNCTION__, xen_domid);

    xc_domain_destroy(xen_xc, xen_domid);

    _exit(0);

}

static int FUNC_0(void)
{ int VAR_0 = 1; int VAR_1[2], VAR_2, VAR_3, VAR_4; char VAR_5; if (pipe(VAR_1) != 0) { qemu_log("%s: Huh? pipe error: %s\VAR_3", __FUNCTION__, strerror(errno)); return -1; } if (fork() != 0)
return 0; VAR_3 = getdtablesize(); for (VAR_2 = 3; VAR_2 < VAR_3; VAR_2++) { if (VAR_2 == VAR_1[0])
continue; if (VAR_2 == xen_xc)
continue; close(VAR_2); } signal(SIGINT,  SIG_IGN); signal(SIGTERM, SIG_IGN); while (VAR_0) { VAR_4 = read(VAR_1[0], &VAR_5, 1); switch (VAR_4) { case -1:
if (errno == EINTR)
continue; qemu_log("%s: Huh? read error: %s\VAR_3", __FUNCTION__, strerror(errno)); VAR_0 = 0; break; case 0:
VAR_0 = 0; break; default:
qemu_log("%s: Huh? data on the watch pipe?\VAR_3", __FUNCTION__); break; } } qemu_log("%s: destroy domain %d\VAR_3", __FUNCTION__, xen_domid); xc_domain_destroy(xen_xc, xen_domid); _exit(0); }