static int net_bridge_run_helper(const char *helper, const char *bridge)

{

    sigset_t oldmask, mask;

    int pid, status;

    char *args[5];

    char **parg;

    int sv[2];



    sigemptyset(&mask);

    sigaddset(&mask, SIGCHLD);

    sigprocmask(SIG_BLOCK, &mask, &oldmask);



    if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {

        return -1;

    }



    /* try to launch bridge helper */

    pid = fork();

    if (pid == 0) {

        int open_max = sysconf(_SC_OPEN_MAX), i;

        char fd_buf[6+10];

        char br_buf[6+IFNAMSIZ] = {0};

        char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15];



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

            if (i != sv[1]) {

                close(i);

            }

        }



        snprintf(fd_buf, sizeof(fd_buf), "%s%d", "--fd=", sv[1]);



        if (strrchr(helper, ' ') || strrchr(helper, '\t')) {

            /* assume helper is a command */



            if (strstr(helper, "--br=") == NULL) {

                snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge);

            }



            snprintf(helper_cmd, sizeof(helper_cmd), "%s %s %s %s",

                     helper, "--use-vnet", fd_buf, br_buf);



            parg = args;

            *parg++ = (char *)"sh";

            *parg++ = (char *)"-c";

            *parg++ = helper_cmd;

            *parg++ = NULL;



            execv("/bin/sh", args);

        } else {

            /* assume helper is just the executable path name */



            snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge);



            parg = args;

            *parg++ = (char *)helper;

            *parg++ = (char *)"--use-vnet";

            *parg++ = fd_buf;

            *parg++ = br_buf;

            *parg++ = NULL;



            execv(helper, args);

        }

        _exit(1);



    } else if (pid > 0) {

        int fd;



        close(sv[1]);



        do {

            fd = recv_fd(sv[0]);

        } while (fd == -1 && errno == EINTR);



        close(sv[0]);



        while (waitpid(pid, &status, 0) != pid) {

            /* loop */

        }

        sigprocmask(SIG_SETMASK, &oldmask, NULL);

        if (fd < 0) {

            fprintf(stderr, "failed to recv file descriptor\n");

            return -1;

        }



        if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {

            return fd;

        }

    }

    fprintf(stderr, "failed to launch bridge helper\n");

    return -1;

}

static int net_bridge_run_helper(const char *helper, const char *bridge)

{

    sigset_t oldmask, mask;

    int pid, status;

    char *args[5];

    char **parg;

    int sv[2];



    sigemptyset(&mask);

    sigaddset(&mask, SIGCHLD);

    sigprocmask(SIG_BLOCK, &mask, &oldmask);



    if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {

        return -1;

    }



    

    pid = fork();

    if (pid == 0) {

        int open_max = sysconf(_SC_OPEN_MAX), i;

        char fd_buf[6+10];

        char br_buf[6+IFNAMSIZ] = {0};

        char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15];



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

            if (i != sv[1]) {

                close(i);

            }

        }



        snprintf(fd_buf, sizeof(fd_buf), "%s%d", "--fd=", sv[1]);



        if (strrchr(helper, ' ') || strrchr(helper, '\t')) {

            



            if (strstr(helper, "--br=") == NULL) {

                snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge);

            }



            snprintf(helper_cmd, sizeof(helper_cmd), "%s %s %s %s",

                     helper, "--use-vnet", fd_buf, br_buf);



            parg = args;

            *parg++ = (char *)"sh";

            *parg++ = (char *)"-c";

            *parg++ = helper_cmd;

            *parg++ = NULL;



            execv("/bin/sh", args);

        } else {

            



            snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge);



            parg = args;

            *parg++ = (char *)helper;

            *parg++ = (char *)"--use-vnet";

            *parg++ = fd_buf;

            *parg++ = br_buf;

            *parg++ = NULL;



            execv(helper, args);

        }

        _exit(1);



    } else if (pid > 0) {

        int fd;



        close(sv[1]);



        do {

            fd = recv_fd(sv[0]);

        } while (fd == -1 && errno == EINTR);



        close(sv[0]);



        while (waitpid(pid, &status, 0) != pid) {

            

        }

        sigprocmask(SIG_SETMASK, &oldmask, NULL);

        if (fd < 0) {

            fprintf(stderr, "failed to recv file descriptor\n");

            return -1;

        }



        if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {

            return fd;

        }

    }

    fprintf(stderr, "failed to launch bridge helper\n");

    return -1;

}

static int net_bridge_run_helper(const char *helper, const char *bridge)     } else if (pid > 0) {             fprintf(stderr, "failed to recv file descriptor\n");         if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {             return fd;     fprintf(stderr, "failed to launch bridge helper\n");     return -1;
static int FUNC_0(const char *VAR_0, const char *VAR_1)

{

    sigset_t oldmask, mask;

    int VAR_2, VAR_3;

    char *VAR_4[5];

    char **VAR_5;

    int VAR_6[2];



    sigemptyset(&mask);

    sigaddset(&mask, SIGCHLD);

    sigprocmask(SIG_BLOCK, &mask, &oldmask);



    if (socketpair(PF_UNIX, SOCK_STREAM, 0, VAR_6) == -1) {

        return -1;

    }



    

    VAR_2 = fork();

    if (VAR_2 == 0) {

        int VAR_7 = sysconf(_SC_OPEN_MAX), VAR_8;

        char VAR_9[6+10];

        char VAR_10[6+IFNAMSIZ] = {0};

        char VAR_11[PATH_MAX + sizeof(VAR_9) + sizeof(VAR_10) + 15];



        for (VAR_8 = 3; VAR_8 < VAR_7; VAR_8++) {

            if (VAR_8 != VAR_6[1]) {

                close(VAR_8);

            }

        }



        snprintf(VAR_9, sizeof(VAR_9), "%s%d", "--VAR_12=", VAR_6[1]);



        if (strrchr(VAR_0, ' ') || strrchr(VAR_0, '\t')) {

            



            if (strstr(VAR_0, "--br=") == NULL) {

                snprintf(VAR_10, sizeof(VAR_10), "%s%s", "--br=", VAR_1);

            }



            snprintf(VAR_11, sizeof(VAR_11), "%s %s %s %s",

                     VAR_0, "--use-vnet", VAR_9, VAR_10);



            VAR_5 = VAR_4;

            *VAR_5++ = (char *)"sh";

            *VAR_5++ = (char *)"-c";

            *VAR_5++ = VAR_11;

            *VAR_5++ = NULL;



            execv("/bin/sh", VAR_4);

        } else {

            



            snprintf(VAR_10, sizeof(VAR_10), "%s%s", "--br=", VAR_1);



            VAR_5 = VAR_4;

            *VAR_5++ = (char *)VAR_0;

            *VAR_5++ = (char *)"--use-vnet";

            *VAR_5++ = VAR_9;

            *VAR_5++ = VAR_10;

            *VAR_5++ = NULL;



            execv(VAR_0, VAR_4);

        }

        _exit(1);



    } else if (VAR_2 > 0) {

        int VAR_12;



        close(VAR_6[1]);



        do {

            VAR_12 = recv_fd(VAR_6[0]);

        } while (VAR_12 == -1 && errno == EINTR);



        close(VAR_6[0]);



        while (waitpid(VAR_2, &VAR_3, 0) != VAR_2) {

            

        }

        sigprocmask(SIG_SETMASK, &oldmask, NULL);

        if (VAR_12 < 0) {

            fprintf(stderr, "failed to recv file descriptor\n");

            return -1;

        }



        if (WIFEXITED(VAR_3) && WEXITSTATUS(VAR_3) == 0) {

            return VAR_12;

        }

    }

    fprintf(stderr, "failed to launch VAR_1 VAR_0\n");

    return -1;

}

static int FUNC_0(const char *VAR_0, const char *VAR_1)
{ sigset_t oldmask, mask; int VAR_2, VAR_3; char *VAR_4[5]; char **VAR_5; int VAR_6[2]; sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigprocmask(SIG_BLOCK, &mask, &oldmask); if (socketpair(PF_UNIX, SOCK_STREAM, 0, VAR_6) == -1) { return -1; } VAR_2 = fork(); if (VAR_2 == 0) { int VAR_7 = sysconf(_SC_OPEN_MAX), VAR_8; char VAR_9[6+10]; char VAR_10[6+IFNAMSIZ] = {0}; char VAR_11[PATH_MAX + sizeof(VAR_9) + sizeof(VAR_10) + 15]; for (VAR_8 = 3; VAR_8 < VAR_7; VAR_8++) { if (VAR_8 != VAR_6[1]) { close(VAR_8); } } snprintf(VAR_9, sizeof(VAR_9), "%s%d", "--VAR_12=", VAR_6[1]); if (strrchr(VAR_0, ' ') || strrchr(VAR_0, '\t')) { if (strstr(VAR_0, "--br=") == NULL) { snprintf(VAR_10, sizeof(VAR_10), "%s%s", "--br=", VAR_1); } snprintf(VAR_11, sizeof(VAR_11), "%s %s %s %s",
VAR_0, "--use-vnet", VAR_9, VAR_10); VAR_5 = VAR_4; *VAR_5++ = (char *)"sh"; *VAR_5++ = (char *)"-c"; *VAR_5++ = VAR_11; *VAR_5++ = NULL; execv("/bin/sh", VAR_4); } else { snprintf(VAR_10, sizeof(VAR_10), "%s%s", "--br=", VAR_1); VAR_5 = VAR_4; *VAR_5++ = (char *)VAR_0; *VAR_5++ = (char *)"--use-vnet"; *VAR_5++ = VAR_9; *VAR_5++ = VAR_10; *VAR_5++ = NULL; execv(VAR_0, VAR_4); } _exit(1); } else if (VAR_2 > 0) { int VAR_12; close(VAR_6[1]); do { VAR_12 = recv_fd(VAR_6[0]); } while (VAR_12 == -1 && errno == EINTR); close(VAR_6[0]); while (waitpid(VAR_2, &VAR_3, 0) != VAR_2) { } sigprocmask(SIG_SETMASK, &oldmask, NULL); if (VAR_12 < 0) { fprintf(stderr, "failed to recv file descriptor\n"); return -1; } if (WIFEXITED(VAR_3) && WEXITSTATUS(VAR_3) == 0) { return VAR_12; } } fprintf(stderr, "failed to launch VAR_1 VAR_0\n"); return -1; }