X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=utils.c;h=dbc713cd36e8ff675813b6d0a5f0f7117bd293c4;hb=6da847c446c29c349b0edd757c1afd529565c619;hp=1942cbc71068effda0c923f4e4f0ec55cfaf0aa9;hpb=62863ea95d3c2c7dd0b56ac0f1dee5a4590ca70c;p=project%2Ffirewall3.git diff --git a/utils.c b/utils.c index 1942cbc..dbc713c 100644 --- a/utils.c +++ b/utils.c @@ -244,6 +244,7 @@ __fw3_command_pipe(bool silent, const char *command, ...) signal(SIGPIPE, SIG_IGN); pipe_pid = pid; close(pfds[0]); + fcntl(pfds[1], F_SETFD, fcntl(pfds[1], F_GETFD) | FD_CLOEXEC); } pipe_fd = fdopen(pfds[1], "w"); @@ -597,3 +598,43 @@ fw3_pr_rulespec(int table, int family, uint32_t *flags, uint32_t mask, return rv; } + + +bool +fw3_hotplug(bool add, void *zone, void *device) +{ + struct fw3_zone *z = zone; + struct fw3_device *d = device; + + if (!d->network) + return false; + + switch (fork()) + { + case -1: + warn("Unable to fork(): %s\n", strerror(errno)); + return false; + + case 0: + break; + + default: + return true; + } + + close(0); + close(1); + close(2); + chdir("/"); + + clearenv(); + setenv("ACTION", add ? "add" : "remove", 1); + setenv("ZONE", z->name, 1); + setenv("INTERFACE", d->network->name, 1); + setenv("DEVICE", d->name, 1); + + execl(FW3_HOTPLUG, FW3_HOTPLUG, "firewall", NULL); + + /* unreached */ + return false; +}