Blob Blame History Raw
From 4c211953b1e6290653fa3bb151b85be29d02288f Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Wed, 10 Oct 2018 19:19:18 +0200
Subject: [PATCH] segtree: set proper error cause on existing elements

Adding new elements result in a confusing "Success" error message.

 # nft add element x y { 0-3 }
 [...]
 Error: Could not process rule: Success
 add element x y { 0-3 }
 ^^^^^^^^^^^^^^^^^^^^^^^^

after this patch, this reports:

 Error: Could not process rule: File exists
 add element x y { 0-3 }
 ^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
(cherry picked from commit 8ef0efb97006081e7f6054a950cb3614dd57729f)
Signed-off-by: Phil Sutter <psutter@redhat.com>
---
 src/segtree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/segtree.c b/src/segtree.c
index 4ee09884cbde6..5685618b3724a 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -270,6 +270,7 @@ static int ei_insert(struct list_head *msgs, struct seg_tree *tree,
 
 	return 0;
 err:
+	errno = EEXIST;
 	return expr_binary_error(msgs, lei->expr, new->expr,
 				 "conflicting intervals specified");
 }
@@ -371,6 +372,7 @@ static int set_overlap(struct list_head *msgs, const struct set *set,
 
 			expr_error(msgs, new_intervals[i]->expr,
 				   "interval overlaps with an existing one");
+			errno = EEXIST;
 			ret = -1;
 			goto out;
 		}
-- 
2.21.0