#include #include #include #include int main(int argc, char **argv) { char *ifname = argv[1]; pid_t pid_ifconfig, pid_brconfig; int status; int ret = 0; if (ifname == NULL) errx(1, "missing ifname"); if (posix_spawn(&pid_ifconfig, "/sbin/ifconfig", NULL, NULL, (char *const[]){"ifconfig", ifname, "up", NULL}, NULL) == -1) err(1, "spawn ifconfig"); if (posix_spawn(&pid_brconfig, "/sbin/brconfig", NULL, NULL, (char *const[]){"brconfig", "bridge0", "add", ifname, NULL}, NULL) == -1) err(1, "spawn brconfig"); if (waitpid(pid_ifconfig, &status, 0) == -1) err(1, "wait for ifconfig"); if (WIFSIGNALED(status)) { warnx("ifconfig terminated on signal %d", WTERMSIG(status)); ret = 1; } if (WIFEXITED(status) && WEXITSTATUS(status)) { warnx("ifconfig exited with status %d", WEXITSTATUS(status)); ret = 1; } if (waitpid(pid_brconfig, &status, 0) == -1) err(1, "wait for brconfig"); if (WIFSIGNALED(status)) { warnx("brconfig terminated on signal %d", WTERMSIG(status)); ret = 1; } if (WIFEXITED(status) && WEXITSTATUS(status)) { warnx("brconfig exited with status %d", WEXITSTATUS(status)); ret = 1; } return ret; }