Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/npf/npfctl centralize error handling and print what...



details:   https://anonhg.NetBSD.org/src/rev/bc54d9e17dd8
branches:  trunk
changeset: 785370:bc54d9e17dd8
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 10 23:59:00 2013 +0000

description:
centralize error handling and print what went wrong instead of "ioctl"

diffstat:

 usr.sbin/npf/npfctl/npfctl.c |  23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diffs (95 lines):

diff -r 4cc9d71a4988 -r bc54d9e17dd8 usr.sbin/npf/npfctl/npfctl.c
--- a/usr.sbin/npf/npfctl/npfctl.c      Sun Mar 10 23:57:07 2013 +0000
+++ b/usr.sbin/npf/npfctl/npfctl.c      Sun Mar 10 23:59:00 2013 +0000
@@ -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.
@@ -30,7 +30,7 @@
  */
 
 #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/stat.h>
@@ -339,7 +339,7 @@
                }
                /* FALLTHROUGH */
        default:
-               err(EXIT_FAILURE, "ioctl");
+               err(EXIT_FAILURE, "ioctl(IOC_NPF_TABLE)");
        }
 
        if (nct.nct_cmd == NPF_CMD_TABLE_LIST) {
@@ -484,7 +484,7 @@
                err(EXIT_FAILURE, "cannot open '%s'", NPF_DEV_PATH);
        }
        if (ioctl(fd, IOC_NPF_VERSION, &ver) == -1) {
-               err(EXIT_FAILURE, "ioctl");
+               err(EXIT_FAILURE, "ioctl(IOC_NPF_VERSION)");
        }
        if (ver != NPF_VERSION) {
                errx(EXIT_FAILURE,
@@ -492,33 +492,37 @@
                    "Hint: update userland?", NPF_VERSION, ver);
        }
 
+       const char *fun = "";
        switch (action) {
        case NPFCTL_START:
                boolval = true;
                ret = ioctl(fd, IOC_NPF_SWITCH, &boolval);
+               fun = "ioctl(IOC_NPF_SWITCH)";
                break;
        case NPFCTL_STOP:
                boolval = false;
                ret = ioctl(fd, IOC_NPF_SWITCH, &boolval);
+               fun = "ioctl(IOC_NPF_SWITCH)";
                break;
        case NPFCTL_RELOAD:
                npfctl_config_init(false);
                npfctl_parse_file(argc < 3 ? NPF_CONF_PATH : argv[2]);
-               ret = npfctl_config_send(fd, NULL);
-               if (ret) {
-                       errx(EXIT_FAILURE, "ioctl: %s", strerror(ret));
-               }
+               errno = ret = npfctl_config_send(fd, NULL);
+               fun = "npfctl_config_send";
                break;
        case NPFCTL_SHOWCONF:
                ret = npfctl_config_show(fd);
+               fun = "npfctl_config_show";
                break;
        case NPFCTL_FLUSH:
                ret = npf_config_flush(fd);
+               fun = "npf_config_flush";
                break;
        case NPFCTL_VALIDATE:
                npfctl_config_init(false);
                npfctl_parse_file(argc < 3 ? NPF_CONF_PATH : argv[2]);
                ret = npfctl_config_show(0);
+               fun = "npfctl_config_show";
                break;
        case NPFCTL_TABLE:
                if ((argc -= 2) < 2) {
@@ -536,6 +540,7 @@
                break;
        case NPFCTL_STATS:
                ret = npfctl_print_stats(fd);
+               fun = "npfctl_print_stats";
                break;
        case NPFCTL_SESSIONS_SAVE:
                if (npf_sessions_recv(fd, NPF_SESSDB_PATH) != 0) {
@@ -551,7 +556,7 @@
                break;
        }
        if (ret) {
-               err(EXIT_FAILURE, "ioctl");
+               err(EXIT_FAILURE, "%s", fun);
        }
        close(fd);
 }



Home | Main Index | Thread Index | Old Index