Blame SOURCES/0022-nfnl_osf-Improve-error-handling.patch

fc8f74
From acc1fb93b3674f81c9d1daa0e4e855410d2568b0 Mon Sep 17 00:00:00 2001
fc8f74
From: Phil Sutter <phil@nwl.cc>
fc8f74
Date: Sat, 9 May 2020 13:42:56 +0200
fc8f74
Subject: [PATCH] nfnl_osf: Improve error handling
fc8f74
fc8f74
For some error cases, no log message was created - hence apart from the
fc8f74
return code there was no indication of failing execution.
fc8f74
fc8f74
If a line load fails, don't abort but continue with the remaining
fc8f74
file contents. The current pf.os file in this repository serves as
fc8f74
proof-of-concept:
fc8f74
fc8f74
Lines 700 and 701: Duplicates of lines 698 and 699 because 'W*' and 'W0'
fc8f74
parse into the same data.
fc8f74
fc8f74
Line 704: Duplicate of line 702 because apart from 'W*' and 'W0', only
fc8f74
the first three fields on right-hand side are sent to the kernel.
fc8f74
fc8f74
When loading, these dups are ignored (they would bounce if NLM_F_EXCL
fc8f74
was given). Upon deletion, they cause ENOENT response from kernel. In
fc8f74
order to align duplicate-tolerance in both modes, just ignore that
fc8f74
ENOENT.
fc8f74
fc8f74
Signed-off-by: Phil Sutter <phil@nwl.cc>
fc8f74
(cherry picked from commit 3e09bd1888575cfec136574d2b0e810ba33f1cfb)
fc8f74
Signed-off-by: Phil Sutter <psutter@redhat.com>
fc8f74
---
fc8f74
 utils/nfnl_osf.c | 15 ++++++++++-----
fc8f74
 1 file changed, 10 insertions(+), 5 deletions(-)
fc8f74
fc8f74
diff --git a/utils/nfnl_osf.c b/utils/nfnl_osf.c
fc8f74
index 922d90ac135b7..8008e83d8af4b 100644
fc8f74
--- a/utils/nfnl_osf.c
fc8f74
+++ b/utils/nfnl_osf.c
fc8f74
@@ -392,7 +392,7 @@ static int osf_load_line(char *buffer, int len, int del)
fc8f74
 static int osf_load_entries(char *path, int del)
fc8f74
 {
fc8f74
 	FILE *inf;
fc8f74
-	int err = 0;
fc8f74
+	int err = 0, lineno = 0;
fc8f74
 	char buf[1024];
fc8f74
 
fc8f74
 	inf = fopen(path, "r");
fc8f74
@@ -402,7 +402,9 @@ static int osf_load_entries(char *path, int del)
fc8f74
 	}
fc8f74
 
fc8f74
 	while(fgets(buf, sizeof(buf), inf)) {
fc8f74
-		int len;
fc8f74
+		int len, rc;
fc8f74
+
fc8f74
+		lineno++;
fc8f74
 
fc8f74
 		if (buf[0] == '#' || buf[0] == '\n' || buf[0] == '\r')
fc8f74
 			continue;
fc8f74
@@ -414,9 +416,11 @@ static int osf_load_entries(char *path, int del)
fc8f74
 
fc8f74
 		buf[len] = '\0';
fc8f74
 
fc8f74
-		err = osf_load_line(buf, len, del);
fc8f74
-		if (err)
fc8f74
-			break;
fc8f74
+		rc = osf_load_line(buf, len, del);
fc8f74
+		if (rc && (!del || errno != ENOENT)) {
fc8f74
+			ulog_err("Failed to load line %d", lineno);
fc8f74
+			err = rc;
fc8f74
+		}
fc8f74
 
fc8f74
 		memset(buf, 0, sizeof(buf));
fc8f74
 	}
fc8f74
@@ -448,6 +452,7 @@ int main(int argc, char *argv[])
fc8f74
 
fc8f74
 	if (!fingerprints) {
fc8f74
 		err = -ENOENT;
fc8f74
+		ulog("Missing fingerprints file argument.\n");
fc8f74
 		goto err_out_exit;
fc8f74
 	}
fc8f74
 
fc8f74
-- 
fc8f74
2.26.2
fc8f74