NetBSD-Bugs archive

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

bin/56307: npfctl's error messages obscure the failing filename



>Number:         56307
>Category:       bin
>Synopsis:       npfctl's error messages obscure the failing filename
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 12 19:05:00 +0000 2021
>Originator:     Konrad Schroder
>Release:        NetBSD 9.99.7 (sources from 2021-07-10)
>Organization:
	Happy Hopeless Hacker House
>Environment:
System: NetBSD nbdev.hhhh.org 9.99.7 NetBSD 9.99.7 (XEN3_DOMU) #5: Mon Aug 12 21:43:10 PDT 2019 root%nbdev.hhhh.org@localhost:/home/perseant/src-current/sys/arch/amd64/compile/obj/XEN3_DOMU amd64
Architecture: x86_64
Machine: amd64
>Description:
When reporting file-related errors, npfctl does not name the file in question.  If /dev/npf is missing, for example, the error is "npfctl: fstat: file not found".  Reporting the failing filename helps immensely in debugging this type of issue.
>How-To-Repeat:
	rm /dev/npf
	npfctl show
>Fix:
Happy to commit if rmind@ gives the green light:

Index: usr.sbin/npf/npfctl/npfctl.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/npf/npfctl/npfctl.c,v
retrieving revision 1.64
diff -u -r1.64 npfctl.c
--- usr.sbin/npf/npfctl/npfctl.c	30 May 2020 14:16:56 -0000	1.64
+++ usr.sbin/npf/npfctl/npfctl.c	12 Jul 2021 03:31:48 -0000
@@ -301,17 +301,17 @@
 	 * just leaving this responsibility for the caller.
 	 */
 	if ((fd = open(path, O_RDONLY)) == -1) {
-		err(EXIT_FAILURE, "could not open `%s'", path);
+		err(EXIT_FAILURE, "open: %s", path);
 	}
 	if (fstat(fd, &sb) == -1) {
-		err(EXIT_FAILURE, "stat");
+		err(EXIT_FAILURE, "stat: %s", path);
 	}
 	if ((blen = sb.st_size) == 0) {
-		err(EXIT_FAILURE, "the binary configuration file is empty");
+		err(EXIT_FAILURE, "the binary configuration file '%s' is empty", path);
 	}
 	blob = mmap(NULL, blen, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0);
 	if (blob == MAP_FAILED) {
-		err(EXIT_FAILURE, "mmap");
+		err(EXIT_FAILURE, "mmap: %s", path);
 	}
 	ncf = npf_config_import(blob, blen);
 	munmap(blob, blen);
@@ -329,7 +329,7 @@
 	 */
 	ncf = npfctl_import(NPF_DB_PATH);
 	if (ncf == NULL) {
-		err(EXIT_FAILURE, "npf_config_import");
+		err(EXIT_FAILURE, "npf_config_import: %s", NPF_DB_PATH);
 	}
 	if ((errno = npf_config_submit(ncf, fd, &errinfo)) != 0) {
 		npfctl_print_error(&errinfo);
@@ -345,7 +345,7 @@
 	int fd;
 
 	if (lstat(path, &st) == -1) {
-		err(EXIT_FAILURE, "fstat");
+		err(EXIT_FAILURE, "fstat: %s", path);
 	}
 	if ((st.st_mode & S_IFMT) == S_IFSOCK) {
 		struct sockaddr_un addr;
@@ -358,11 +358,11 @@
 		strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
 
 		if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-			err(EXIT_FAILURE, "connect");
+			err(EXIT_FAILURE, "connect: %s", path);
 		}
 	} else {
 		if ((fd = open(path, O_RDONLY)) == -1) {
-			err(EXIT_FAILURE, "cannot open '%s'", path);
+			err(EXIT_FAILURE, "open: %s", path);
 		}
 	}
 	return fd;
@@ -416,7 +416,7 @@
 		puts("Loading the active configuration");
 		fd = npfctl_open_dev(NPF_DEV_PATH);
 		if ((ncf = npf_config_retrieve(fd)) == NULL) {
-			err(EXIT_FAILURE, "npf_config_retrieve");
+			err(EXIT_FAILURE, "npf_config_retrieve: %s", NPF_DEV_PATH);
 		}
 	}



Home | Main Index | Thread Index | Old Index