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