diff options
| -rw-r--r-- | conf.c | 29 | ||||
| -rw-r--r-- | conf.h | 1 | ||||
| -rw-r--r-- | util.c | 12 |
3 files changed, 23 insertions, 19 deletions
@@ -1154,6 +1154,24 @@ static void conf_sock_listen(const struct ctx *c) } /** + * conf_tap_fd() - Read tap fd as supplied by -F command line option + * @arg: Argument to -F command line option + */ +int conf_tap_fd(const char *arg) +{ + long val; + + errno = 0; + val = strtol(arg, NULL, 0); + + if (errno || (val != STDIN_FILENO && val <= STDERR_FILENO) || + val > INT_MAX) + die("Invalid --fd: %s", arg); + + return val; +} + +/** * conf() - Process command-line arguments and set configuration * @c: Execution context * @argc: Argument count @@ -1253,7 +1271,6 @@ void conf(struct ctx *c, int argc, char **argv) const char *logfile = NULL; char *runas = NULL; size_t logsize = 0; - long fd_tap_opt; int name, ret; uid_t uid; gid_t gid; @@ -1506,15 +1523,7 @@ void conf(struct ctx *c, int argc, char **argv) c->fd_control_listen = c->fd_control = -1; break; case 'F': - errno = 0; - fd_tap_opt = strtol(optarg, NULL, 0); - - if (errno || - (fd_tap_opt != STDIN_FILENO && fd_tap_opt <= STDERR_FILENO) || - fd_tap_opt > INT_MAX) - die("Invalid --fd: %s", optarg); - - c->fd_tap = fd_tap_opt; + c->fd_tap = conf_tap_fd(optarg); c->one_off = true; *c->sock_path = 0; break; @@ -7,6 +7,7 @@ #define CONF_H enum passt_modes conf_mode(int argc, char *argv[]); +int conf_tap_fd(const char *arg); void conf(struct ctx *c, int argc, char **argv); void conf_listen_handler(struct ctx *c, uint32_t events); void conf_handler(struct ctx *c, uint32_t events); @@ -38,6 +38,7 @@ #include "epoll_ctl.h" #include "pasta.h" #include "serialise.h" +#include "conf.h" #ifdef HAS_GETRANDOM #include <sys/random.h> #endif @@ -939,15 +940,8 @@ void close_open_files(int argc, char **argv) do { name = getopt_long(argc, argv, "-:F:", optfd, NULL); - if (name == 'F') { - errno = 0; - fd = strtol(optarg, NULL, 0); - - if (errno || - (fd != STDIN_FILENO && fd <= STDERR_FILENO) || - fd > INT_MAX) - die("Invalid --fd: %s", optarg); - } + if (name == 'F') + fd = conf_tap_fd(optarg); } while (name != -1); if (fd == -1) { |
