Don't hard-code program names. This also fixes for bogus 'xtables-save' name which is no longer used. Signed-off-by: Phil Sutter <phil@xxxxxx> --- iptables/xtables-save.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/iptables/xtables-save.c b/iptables/xtables-save.c index 3f389e8fdc234..491122f39bbb0 100644 --- a/iptables/xtables-save.c +++ b/iptables/xtables-save.c @@ -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 counters if (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); @@ -308,7 +309,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", @@ -362,7 +363,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", -- 2.22.0