xtables-save: Use argv[0] as program name
Phil Sutter
reviewerPATCH 1/1 xtables-save: Use argv[0] as program name
Don't hard-code program names. This also fixes for bogus 'xtables-save' name which is no longer used.
--- iptables/xtables-save.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
iptables/xtables-save.c +11 -10
@@ -9,6 +9,7 @@#include "config.h" #include <getopt.h> #include <errno.h> +#include <libgen.h> #include <stdio.h> #include <fcntl.h> #include <stdlib.h>
@@ -80,8 +81,8 @@ __do_output(struct nft_handle *h, const char *tablename, bool counters)time_t now =time (NULL ); -printf ("# Generated by xtables-save v%s on %s" , -PACKAGE_VERSION ,ctime (&now)); +printf ("# Generated by %s v%s on %s" , prog_name, + prog_vers,ctime (&now));printf ("*%s\n" , tablename);/* Dump out chain names first,
@@ -122,7 +123,7 @@ do_output(struct nft_handle *h, const char *tablename, bool counters)* rule */ static int -xtables_save_main (int family,const char *progname,int argc,char *argv[]) +xtables_save_main (int family,int argc,char *argv[]) {const struct builtin_table *tables;const char *tablename =NULL ;
@@ -133,7 +134,7 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[])FILE *file =NULL ;int ret, c; - xtables_globals.program_name = progname; + xtables_globals.program_name =basename (*argv);; c =xtables_init_all (&xtables_globals, family);if (c <0 ) { fprintf(stderr, "%s/%s Failed to initialize xtables\n",
@@ -237,12 +238,12 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[])int xtables_ip4_save_main (int argc,char *argv[]) { -return xtables_save_main (NFPROTO_IPV4 ,"iptables-save" , argc, argv); +return xtables_save_main (NFPROTO_IPV4 , argc, argv); }int xtables_ip6_save_main (int argc,char *argv[]) { -return xtables_save_main (NFPROTO_IPV6 ,"ip6tables-save" , argc, argv); +return xtables_save_main (NFPROTO_IPV6 , argc, argv); }static int __ebt_save (struct nft_handle *h,const char *tablename,bool counters)
@@ -266,8 +267,8 @@ static int __ebt_save(struct nft_handle *h, const char *tablename, bool countersif (first) { now =time (NULL ); -printf ("# Generated by ebtables-save v%s on %s" , -PACKAGE_VERSION ,ctime (&now)); +printf ("# Generated by %s v%s on %s" , prog_name, + prog_vers,ctime (&now)); first = false; }printf ("*%s\n" , tablename);
@@ -307,7 +308,7 @@ int xtables_eb_save_main(int argc_, char *argv_[]) } } - xtables_globals.program_name ="ebtables-save" ; + xtables_globals.program_name =basename (*argv_); c =xtables_init_all (&xtables_globals, h.family);if (c <0 ) { fprintf(stderr, "%s/%s Failed to initialize xtables\n",
@@ -361,7 +362,7 @@ int xtables_arp_save_main(int argc, char **argv) };int c; - xtables_globals.program_name ="arptables-save" ; + xtables_globals.program_name =basename (*argv);; c =xtables_init_all (&xtables_globals, h.family);if (c <0 ) { fprintf(stderr, "%s/%s Failed to initialize xtables\n",
Signature · 1 line
2.22.0
Quoted 2 lines · Phil Sutter
Don't hard-code program names. This also fixes for bogus 'xtables-save' name which is no longer used.
Applied, thanks Phil.
BTW, it seems arptables-save doesn't print:
# Generated by ...
for some reason, probably good to get this consistent with other existing -save tools.
Thanks!
Phil Sutter
reviewerHi,
Quoted 9 lines · Pablo Neira Ayuso
Quoted 2 lines · Phil Sutter
Don't hard-code program names. This also fixes for bogus 'xtables-save' name which is no longer used.
Applied, thanks Phil.
BTW, it seems arptables-save doesn't print:
# Generated by ...
Also, ip{,6}tables-save prints that line once per table while ebtables-save does it once for all. And theres:
| # Completed on ...
which neither arp- nor ebtables-save print.
Quoted 2 lines
for some reason, probably good to get this consistent with other existing -save tools.
We can assume lines starting with '#' are ignored by any potential parser of any family's dump files, right?
Cheers, Phil
Pablo Neira Ayuso
maintainerQuoted 18 lines · Phil Sutter
Hi,
Quoted 9 lines · Pablo Neira Ayuso
Quoted 2 lines · Phil Sutter
Don't hard-code program names. This also fixes for bogus 'xtables-save' name which is no longer used.
Applied, thanks Phil.
BTW, it seems arptables-save doesn't print:
# Generated by ...
Also, ip{,6}tables-save prints that line once per table while ebtables-save does it once for all. And theres:
| # Completed on ...
Quoted 7 lines
which neither arp- nor ebtables-save print.
Quoted 2 lines
for some reason, probably good to get this consistent with other existing -save tools.
We can assume lines starting with '#' are ignored by any potential parser of any family's dump files, right?
Yes. It's just a comment. I just think it would be good to fix these small inconsistencies at some point.
Thanks!