]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: Add exit_error cb to xtables_globals
authorJamal Hadi Salim <hadi@cyberus.ca>
Wed, 11 Feb 2009 12:02:21 +0000 (13:02 +0100)
committerPatrick McHardy <kaber@trash.net>
Wed, 11 Feb 2009 12:02:21 +0000 (13:02 +0100)
Introduce exit_error() as part of xtables_globals structure.
When an application registers its xtables_globals definition
and does not specify its exit_error() it gets assigned a
basic version

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: Patrick McHardy <kaber@trash.net>
include/xtables.h.in
xtables.c

index 1d333942b34c1756de42873ef79516f0853b9690..3a16651074bcbeae8ae3fd4c77b86ae3be137f18 100644 (file)
 
 struct in_addr;
 
-struct xtables_globals
-{
-       unsigned int option_offset;
-       char *program_version;
-       char *program_name;
-       struct option *opts;
-};
-
 /* Include file for additions: new matches and targets. */
 struct xtables_match
 {
@@ -191,6 +183,15 @@ enum xtables_exittype {
        XTF_ONE_ACTION,
 };
 
+struct xtables_globals
+{
+       unsigned int option_offset;
+       char *program_version;
+       char *program_name;
+       struct option *opts;
+       void (*exit_error)(enum xtables_exittype status, const char *msg, ...);
+};
+
 extern const char *xtables_program_name;
 extern const char *xtables_modprobe_program;
 extern struct xtables_match *xtables_matches;
index 95be5f8eaac91c6ca9bb4c0c8affb09e2e099e66..d0fc478af656457c99c2b64dc40def0f0fbcdb8d 100644 (file)
--- a/xtables.c
+++ b/xtables.c
 #define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
 #endif
 
-struct xtables_globals *xt_params;
+struct xtables_globals *xt_params = NULL;
+
+void basic_exit_error(enum xtables_exittype status, const char *msg, ...)
+{
+       va_list args;
+
+       va_start(args, msg);
+       fprintf(stderr, "%s v%s: ", xt_params->program_name, xt_params->program_version);
+       vfprintf(stderr, msg, args);
+       va_end(args);
+       fprintf(stderr, "\n");
+       exit(status);
+}
+
 /**
  * xtables_set_params - set the global parameters used by xtables
  * @xtp:       input xtables_globals structure
@@ -65,6 +78,10 @@ int xtables_set_params(struct xtables_globals *xtp)
        }
 
        xt_params = xtp;
+
+       if (!xt_params->exit_error)
+               xt_params->exit_error = basic_exit_error;
+
        return 0;
 }