centralize error handling and print what went wrong instead of "ioctl"
This commit is contained in:
parent
8c8be406dd
commit
2acab3345b
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: npfctl.c,v 1.31 2013/02/16 21:11:15 rmind Exp $ */
|
/* $NetBSD: npfctl.c,v 1.32 2013/03/10 23:59:00 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
|
* Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__RCSID("$NetBSD: npfctl.c,v 1.31 2013/02/16 21:11:15 rmind Exp $");
|
__RCSID("$NetBSD: npfctl.c,v 1.32 2013/03/10 23:59:00 christos Exp $");
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -339,7 +339,7 @@ again:
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
default:
|
default:
|
||||||
err(EXIT_FAILURE, "ioctl");
|
err(EXIT_FAILURE, "ioctl(IOC_NPF_TABLE)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nct.nct_cmd == NPF_CMD_TABLE_LIST) {
|
if (nct.nct_cmd == NPF_CMD_TABLE_LIST) {
|
||||||
|
@ -484,7 +484,7 @@ npfctl(int action, int argc, char **argv)
|
||||||
err(EXIT_FAILURE, "cannot open '%s'", NPF_DEV_PATH);
|
err(EXIT_FAILURE, "cannot open '%s'", NPF_DEV_PATH);
|
||||||
}
|
}
|
||||||
if (ioctl(fd, IOC_NPF_VERSION, &ver) == -1) {
|
if (ioctl(fd, IOC_NPF_VERSION, &ver) == -1) {
|
||||||
err(EXIT_FAILURE, "ioctl");
|
err(EXIT_FAILURE, "ioctl(IOC_NPF_VERSION)");
|
||||||
}
|
}
|
||||||
if (ver != NPF_VERSION) {
|
if (ver != NPF_VERSION) {
|
||||||
errx(EXIT_FAILURE,
|
errx(EXIT_FAILURE,
|
||||||
|
@ -492,33 +492,37 @@ npfctl(int action, int argc, char **argv)
|
||||||
"Hint: update userland?", NPF_VERSION, ver);
|
"Hint: update userland?", NPF_VERSION, ver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *fun = "";
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case NPFCTL_START:
|
case NPFCTL_START:
|
||||||
boolval = true;
|
boolval = true;
|
||||||
ret = ioctl(fd, IOC_NPF_SWITCH, &boolval);
|
ret = ioctl(fd, IOC_NPF_SWITCH, &boolval);
|
||||||
|
fun = "ioctl(IOC_NPF_SWITCH)";
|
||||||
break;
|
break;
|
||||||
case NPFCTL_STOP:
|
case NPFCTL_STOP:
|
||||||
boolval = false;
|
boolval = false;
|
||||||
ret = ioctl(fd, IOC_NPF_SWITCH, &boolval);
|
ret = ioctl(fd, IOC_NPF_SWITCH, &boolval);
|
||||||
|
fun = "ioctl(IOC_NPF_SWITCH)";
|
||||||
break;
|
break;
|
||||||
case NPFCTL_RELOAD:
|
case NPFCTL_RELOAD:
|
||||||
npfctl_config_init(false);
|
npfctl_config_init(false);
|
||||||
npfctl_parse_file(argc < 3 ? NPF_CONF_PATH : argv[2]);
|
npfctl_parse_file(argc < 3 ? NPF_CONF_PATH : argv[2]);
|
||||||
ret = npfctl_config_send(fd, NULL);
|
errno = ret = npfctl_config_send(fd, NULL);
|
||||||
if (ret) {
|
fun = "npfctl_config_send";
|
||||||
errx(EXIT_FAILURE, "ioctl: %s", strerror(ret));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case NPFCTL_SHOWCONF:
|
case NPFCTL_SHOWCONF:
|
||||||
ret = npfctl_config_show(fd);
|
ret = npfctl_config_show(fd);
|
||||||
|
fun = "npfctl_config_show";
|
||||||
break;
|
break;
|
||||||
case NPFCTL_FLUSH:
|
case NPFCTL_FLUSH:
|
||||||
ret = npf_config_flush(fd);
|
ret = npf_config_flush(fd);
|
||||||
|
fun = "npf_config_flush";
|
||||||
break;
|
break;
|
||||||
case NPFCTL_VALIDATE:
|
case NPFCTL_VALIDATE:
|
||||||
npfctl_config_init(false);
|
npfctl_config_init(false);
|
||||||
npfctl_parse_file(argc < 3 ? NPF_CONF_PATH : argv[2]);
|
npfctl_parse_file(argc < 3 ? NPF_CONF_PATH : argv[2]);
|
||||||
ret = npfctl_config_show(0);
|
ret = npfctl_config_show(0);
|
||||||
|
fun = "npfctl_config_show";
|
||||||
break;
|
break;
|
||||||
case NPFCTL_TABLE:
|
case NPFCTL_TABLE:
|
||||||
if ((argc -= 2) < 2) {
|
if ((argc -= 2) < 2) {
|
||||||
|
@ -536,6 +540,7 @@ npfctl(int action, int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case NPFCTL_STATS:
|
case NPFCTL_STATS:
|
||||||
ret = npfctl_print_stats(fd);
|
ret = npfctl_print_stats(fd);
|
||||||
|
fun = "npfctl_print_stats";
|
||||||
break;
|
break;
|
||||||
case NPFCTL_SESSIONS_SAVE:
|
case NPFCTL_SESSIONS_SAVE:
|
||||||
if (npf_sessions_recv(fd, NPF_SESSDB_PATH) != 0) {
|
if (npf_sessions_recv(fd, NPF_SESSDB_PATH) != 0) {
|
||||||
|
@ -551,7 +556,7 @@ npfctl(int action, int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
err(EXIT_FAILURE, "ioctl");
|
err(EXIT_FAILURE, "%s", fun);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue