From: Jozsef Kadlecsik Date: Tue, 18 Jan 2011 16:17:46 +0000 (+0100) Subject: Show correct line numbers in restore output for parser errors X-Git-Tag: v5.3~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cac607bd8850e00356e4d97b05e7c8adfb3fa640;p=thirdparty%2Fipset.git Show correct line numbers in restore output for parser errors Parser errors are reported by a wrong lineno at restore, bug reported by Holger Eitzenberger: create foo6 hash:ip hashsize 64 family inet6 add foo6 20a1:1234:5678::/64 add foo6 20a1:1234:5679::/64 you get: ipset v5.2: Error in line 1: Syntax error: plain IP address must be supplied: 20a1:1234:5678::/64 Should be line 2 though. The solution is to set the session lineno before parsing. --- diff --git a/include/libipset/session.h b/include/libipset/session.h index 02e8b36d..a06c79f2 100644 --- a/include/libipset/session.h +++ b/include/libipset/session.h @@ -24,6 +24,7 @@ struct ipset_handle; extern struct ipset_data * ipset_session_data(const struct ipset_session *session); extern struct ipset_handle * ipset_session_handle(const struct ipset_session *session); extern const struct ipset_type * ipset_saved_type(const struct ipset_session *session); +extern void ipset_session_lineno(struct ipset_session *session, uint32_t lineno); enum ipset_err_type { IPSET_ERROR, diff --git a/lib/session.c b/lib/session.c index 311e5df4..a1931431 100644 --- a/lib/session.c +++ b/lib/session.c @@ -98,6 +98,19 @@ ipset_saved_type(const struct ipset_session *session) return session->saved_type; } +/** + * ipset_session_lineno - set session lineno + * @session: session structure + * + * Set session lineno to report parser errors correctly. + */ +void +ipset_session_lineno(struct ipset_session *session, uint32_t lineno) +{ + assert(session); + session->lineno = lineno; +} + /* * Environment options */ diff --git a/src/ipset.c b/src/ipset.c index 89dbe8fa..d4cf7b86 100644 --- a/src/ipset.c +++ b/src/ipset.c @@ -439,6 +439,9 @@ parse_commandline(int argc, char *argv[]) "Cannot initialize ipset session, aborting."); } + /* Set session lineno to report parser errors correctly */ + ipset_session_lineno(session, restore_line); + /* Commandline parsing, somewhat similar to that of 'ip' */ /* First: parse core options */