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

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