Blame SOURCES/net-tools-correct-exit-code.patch

648959
diff --git a/arp.c b/arp.c
648959
index 5db71a7..30dd56d 100644
648959
--- a/arp.c
648959
+++ b/arp.c
648959
@@ -93,7 +93,7 @@ struct hwtype *hw;		/* current hardware type        */
648959
 int sockfd = 0;			/* active socket descriptor     */
648959
 int hw_set = 0;			/* flag if hw-type was set (-H) */
648959
 char device[16] = "";		/* current device               */
648959
-static void usage(void);
648959
+static void usage(int rc);
648959
 
648959
 /* Delete an entry from the ARP cache. */
648959
 static int arp_del(char **args)
648959
@@ -169,14 +169,14 @@ static int arp_del(char **args)
648959
 	}
648959
 	if (!strcmp(*args, "dev")) {
648959
 	    if (*++args == NULL)
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 	    safe_strncpy(device, *args, sizeof(device));
648959
 	    args++;
648959
 	    continue;
648959
 	}
648959
 	if (!strcmp(*args, "netmask")) {
648959
 	    if (*++args == NULL)
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 	    if (strcmp(*args, "255.255.255.255") != 0) {
648959
 		safe_strncpy(host, *args, (sizeof host));
648959
 		if (ap->input(0, host, &ss) < 0) {
648959
@@ -190,7 +190,7 @@ static int arp_del(char **args)
648959
 	    args++;
648959
 	    continue;
648959
 	}
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
     }
648959
 
648959
     // if neighter priv nor pub is given, work on both
648959
@@ -346,14 +346,14 @@ static int arp_set(char **args)
648959
 	}
648959
 	if (!strcmp(*args, "dev")) {
648959
 	    if (*++args == NULL)
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 	    safe_strncpy(device, *args, sizeof(device));
648959
 	    args++;
648959
 	    continue;
648959
 	}
648959
 	if (!strcmp(*args, "netmask")) {
648959
 	    if (*++args == NULL)
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 	    if (strcmp(*args, "255.255.255.255") != 0) {
648959
 		safe_strncpy(host, *args, (sizeof host));
648959
 		if (ap->input(0, host, &ss) < 0) {
648959
@@ -367,7 +367,7 @@ static int arp_set(char **args)
648959
 	    args++;
648959
 	    continue;
648959
 	}
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
     }
648959
 
648959
     /* Fill in the remainder of the request. */
648959
@@ -621,7 +621,7 @@ static void version(void)
648959
     exit(E_VERSION);
648959
 }
648959
 
648959
-static void usage(void)
648959
+static void usage(int rc)
648959
 {
648959
     fprintf(stderr, _("Usage:\n  arp [-vn]  [<HW>] [-i <if>] [-a] [<hostname>]             <-Display ARP cache\n"));
648959
     fprintf(stderr, _("  arp [-v]          [-i <if>] -d  <host> [pub]               <-Delete ARP entry\n"));
648959
@@ -643,7 +643,7 @@ static void usage(void)
648959
     fprintf(stderr, _("  <HW>=Use '-H <hw>' to specify hardware address type. Default: %s\n"), DFLT_HW);
648959
     fprintf(stderr, _("  List of possible hardware types (which support ARP):\n"));
648959
     print_hwlist(1); /* 1 = ARPable */
648959
-    exit(E_USAGE);
648959
+    exit(rc);
648959
 }
648959
 
648959
 int main(int argc, char **argv)
648959
@@ -745,10 +745,11 @@ int main(int argc, char **argv)
648959
 
648959
 	case 'V':
648959
 	    version();
648959
-	case '?':
648959
 	case 'h':
648959
+	    usage(E_USAGE);
648959
+	case '?':
648959
 	default:
648959
-	    usage();
648959
+	    usage(E_OPTERR);
648959
 	}
648959
 
648959
     if (ap->af != AF_INET) {
648959
@@ -797,7 +798,7 @@ int main(int argc, char **argv)
648959
 	break;
648959
 
648959
     default:
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
     }
648959
 
648959
     exit(what);
648959
diff --git a/ipmaddr.c b/ipmaddr.c
648959
index e4ed41d..c45b62a 100644
648959
--- a/ipmaddr.c
648959
+++ b/ipmaddr.c
648959
@@ -53,14 +53,14 @@ static void version(void)
648959
 	exit(E_VERSION);
648959
 }
648959
 
648959
-static void usage(void) __attribute__((noreturn));
648959
+static void usage(int rc) __attribute__((noreturn));
648959
 
648959
-static void usage(void)
648959
+static void usage(int rc)
648959
 {
648959
 	fprintf(stderr, _("Usage: ipmaddr [ add | del ] MULTIADDR dev STRING\n"));
648959
 	fprintf(stderr, _("       ipmaddr show [ dev STRING ] [ ipv4 | ipv6 | link | all ]\n"));
648959
 	fprintf(stderr, _("       ipmaddr -V | -version\n"));
648959
-	exit(E_USAGE);
648959
+	exit(rc);
648959
 }
648959
 
648959
 static void print_lla(FILE *fp, int len, unsigned char *addr)
648959
@@ -294,7 +294,7 @@ static int multiaddr_list(int argc, char **argv)
648959
 			NEXT_ARG();
648959
 			l = strlen(*argv);
648959
 			if (l <= 0 || l >= sizeof(filter_dev))
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 			strncpy(filter_dev, *argv, sizeof (filter_dev));
648959
 		} else if (strcmp(*argv, "all") == 0) {
648959
 			filter_family = AF_UNSPEC;
648959
@@ -307,7 +307,7 @@ static int multiaddr_list(int argc, char **argv)
648959
 		} else {
648959
 			l = strlen(*argv);
648959
 			if (l <= 0 || l >= sizeof(filter_dev))
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 			strncpy(filter_dev, *argv, sizeof (filter_dev));
648959
 		}
648959
 		argv++; argc--;
648959
@@ -339,18 +339,18 @@ int multiaddr_modify(int cmd, int argc, char **argv)
648959
 		if (strcmp(*argv, "dev") == 0) {
648959
 			NEXT_ARG();
648959
 			if (ifr.ifr_name[0])
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 			strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
648959
 		} else {
648959
 			if (ifr.ifr_hwaddr.sa_data[0])
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 			if (parse_lla(*argv, ifr.ifr_hwaddr.sa_data) < 0)
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 		}
648959
 		argc--; argv++;
648959
 	}
648959
 	if (ifr.ifr_name[0] == 0)
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 
648959
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
648959
 	if (fd < 0) {
648959
@@ -378,7 +378,7 @@ int do_multiaddr(int argc, char **argv)
648959
 	if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0
648959
 	    || matches(*argv, "lst") == 0)
648959
 		return multiaddr_list(argc-1, argv+1);
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
 }
648959
 
648959
 int preferred_family = AF_UNSPEC;
648959
@@ -408,13 +408,13 @@ int main(int argc, char **argv)
648959
 			argc--;
648959
 			argv++;
648959
 			if (argc <= 1)
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 			if (strcmp(argv[1], "inet") == 0)
648959
 				preferred_family = AF_INET;
648959
 			else if (strcmp(argv[1], "inet6") == 0)
648959
 				preferred_family = AF_INET6;
648959
 			else
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 		} else if (matches(argv[1], "-stats") == 0 ||
648959
 			   matches(argv[1], "-statistics") == 0) {
648959
 			++show_stats;
648959
@@ -423,7 +423,7 @@ int main(int argc, char **argv)
648959
 		} else if ((matches(argv[1], "-V") == 0) || matches(argv[1], "--version") == 0) {
648959
 			version();
648959
 		} else
648959
-			usage();
648959
+			usage(E_OPTERR);
648959
 		argc--;	argv++;
648959
 	}
648959
 
648959
diff --git a/include/util-ank.h b/include/util-ank.h
648959
index c8fcd08..c78604a 100644
648959
--- a/include/util-ank.h
648959
+++ b/include/util-ank.h
648959
@@ -23,7 +23,7 @@ extern int resolve_hosts;
648959
 #define NEXT_ARG() \
648959
 argv++; \
648959
 if (--argc <= 0) \
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
 
648959
 typedef struct
648959
 {
648959
diff --git a/iptunnel.c b/iptunnel.c
648959
index 2215d68..42b2a9e 100644
648959
--- a/iptunnel.c
648959
+++ b/iptunnel.c
648959
@@ -76,9 +76,9 @@ static void version(void)
648959
 	exit(E_VERSION);
648959
 }
648959
 
648959
-static void usage(void) __attribute__((noreturn));
648959
+static void usage(int rc) __attribute__((noreturn));
648959
 
648959
-static void usage(void)
648959
+static void usage(int rc)
648959
 {
648959
 	fprintf(stderr, _("Usage: iptunnel { add | change | del | show } [ NAME ]\n"));
648959
 	fprintf(stderr, _("          [ mode { ipip | gre | sit } ] [ remote ADDR ] [ local ADDR ]\n"));
648959
@@ -90,7 +90,7 @@ static void usage(void)
648959
 	fprintf(stderr, _("       TOS  := { NUMBER | inherit }\n"));
648959
 	fprintf(stderr, _("       TTL  := { 1..255 | inherit }\n"));
648959
 	fprintf(stderr, _("       KEY  := { DOTTED_QUAD | NUMBER }\n"));
648959
-	exit(E_USAGE);
648959
+	exit(rc);
648959
 }
648959
 
648959
 static int do_ioctl_get_ifindex(char *dev)
648959
@@ -217,18 +217,18 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
648959
 			NEXT_ARG();
648959
 			if (strcmp(*argv, "ipip") == 0) {
648959
 				if (p->iph.protocol)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->iph.protocol = IPPROTO_IPIP;
648959
 			} else if (strcmp(*argv, "gre") == 0) {
648959
 				if (p->iph.protocol)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->iph.protocol = IPPROTO_GRE;
648959
 			} else if (strcmp(*argv, "sit") == 0) {
648959
 				if (p->iph.protocol)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->iph.protocol = IPPROTO_IPV6;
648959
 			} else
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 		} else if (strcmp(*argv, "key") == 0) {
648959
 			unsigned uval;
648959
 			NEXT_ARG();
648959
@@ -238,7 +238,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
648959
 				p->i_key = p->o_key = get_addr32(*argv);
648959
 			else {
648959
 				if (scan_number(*argv, &uval)<0)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->i_key = p->o_key = htonl(uval);
648959
 			}
648959
 		} else if (strcmp(*argv, "ikey") == 0) {
648959
@@ -249,7 +249,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
648959
 				p->o_key = get_addr32(*argv);
648959
 			else {
648959
 				if (scan_number(*argv, &uval)<0)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->i_key = htonl(uval);
648959
 			}
648959
 		} else if (strcmp(*argv, "okey") == 0) {
648959
@@ -260,7 +260,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
648959
 				p->o_key = get_addr32(*argv);
648959
 			else {
648959
 				if (scan_number(*argv, &uval)<0)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->o_key = htonl(uval);
648959
 			}
648959
 		} else if (strcmp(*argv, "seq") == 0) {
648959
@@ -295,9 +295,9 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
648959
 			NEXT_ARG();
648959
 			if (strcmp(*argv, "inherit") != 0) {
648959
 				if (scan_number(*argv, &uval)<0)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				if (uval > 255)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->iph.ttl = uval;
648959
 			}
648959
 		} else if (strcmp(*argv, "tos") == 0) {
648959
@@ -305,15 +305,15 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
648959
 			NEXT_ARG();
648959
 			if (strcmp(*argv, "inherit") != 0) {
648959
 				if (scan_number(*argv, &uval)<0)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				if (uval > 255)
648959
-					usage();
648959
+					usage(E_OPTERR);
648959
 				p->iph.tos = uval;
648959
 			} else
648959
 				p->iph.tos = 1;
648959
 		} else {
648959
 			if (p->name[0])
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 			safe_strncpy(p->name, *argv, IFNAMSIZ);
648959
 		}
648959
 		argc--; argv++;
648959
@@ -574,7 +574,7 @@ int do_iptunnel(int argc, char **argv)
648959
 	} else
648959
 		return do_show(0, NULL);
648959
 
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
 }
648959
 
648959
 
648959
@@ -605,13 +605,13 @@ int main(int argc, char **argv)
648959
 			argc--;
648959
 			argv++;
648959
 			if (argc <= 1)
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 			if (strcmp(argv[1], "inet") == 0)
648959
 				preferred_family = AF_INET;
648959
 			else if (strcmp(argv[1], "inet6") == 0)
648959
 				preferred_family = AF_INET6;
648959
 			else
648959
-				usage();
648959
+				usage(E_OPTERR);
648959
 		} else if (matches(argv[1], "-stats") == 0 ||
648959
 			   matches(argv[1], "-statistics") == 0) {
648959
 			++show_stats;
648959
@@ -620,7 +620,7 @@ int main(int argc, char **argv)
648959
 		} else if ((matches(argv[1], "-V") == 0) || (matches(argv[1], "--version") == 0)) {
648959
 			version();
648959
 		} else
648959
-			usage();
648959
+			usage(E_OPTERR);
648959
 		argc--;	argv++;
648959
 	}
648959
 
648959
diff --git a/nameif.c b/nameif.c
648959
index b280e59..13e3033 100644
648959
--- a/nameif.c
648959
+++ b/nameif.c
648959
@@ -192,10 +192,10 @@ struct option lopt[] = {
648959
 	{NULL},
648959
 };
648959
 
648959
-void usage(void)
648959
+void usage(int rc)
648959
 {
648959
 	fprintf(stderr, _("usage: nameif [-c configurationfile] [-s] {ifname macaddress}\n"));
648959
-	exit(E_USAGE);
648959
+	exit(rc);
648959
 }
648959
 
648959
 int main(int ac, char **av)
648959
@@ -214,7 +214,7 @@ int main(int ac, char **av)
648959
 		switch (c) {
648959
 		default:
648959
 		case '?':
648959
-			usage();
648959
+			usage(E_OPTERR);
648959
 		case 'c':
648959
 			fname = optarg;
648959
 			break;
648959
@@ -232,7 +232,7 @@ int main(int ac, char **av)
648959
 		char pos[30];
648959
 
648959
 		if ((ac-optind) & 1)
648959
-			usage();
648959
+			usage(E_OPTERR);
648959
 		if (strlen(av[optind])+1>IFNAMSIZ)
648959
 			complain(_("interface name `%s' too long"), av[optind]);
648959
 		safe_strncpy(ch->ifname, av[optind], sizeof(ch->ifname));
648959
diff --git a/plipconfig.c b/plipconfig.c
648959
index 86fa890..1caeed3 100644
648959
--- a/plipconfig.c
648959
+++ b/plipconfig.c
648959
@@ -57,12 +57,12 @@ static void version(void)
648959
     exit(E_VERSION);
648959
 }
648959
 
648959
-void usage(void)
648959
+void usage(int rc)
648959
 {
648959
     fprintf(stderr, _("Usage: plipconfig interface [nibble NN] [trigger NN]\n"));
648959
     fprintf(stderr, _("       plipconfig -V | --version\n"));
648959
     fprintf(stderr, _("       plipconfig -h | --help\n"));
648959
-    exit(E_USAGE);
648959
+    exit(rc);
648959
 }
648959
 
648959
 void print_plip(void)
648959
@@ -89,16 +89,18 @@ int main(int argc, char **argv)
648959
     argc--;
648959
     argv++;
648959
     while (argv[0] && *argv[0] == '-') {
648959
-	if (!strcmp(*argv, "-V") || !strcmp(*argv, "--version"))
648959
+	if ((!strcmp(*argv, "-V") || !strcmp(*argv, "--version")) && argc==1)
648959
 	    version();
648959
+	if ((!strcmp(*argv, "-h") || !strcmp(*argv, "--help")) && argc==1)
648959
+	    usage(E_USAGE);
648959
 	else
648959
-            usage();
648959
+            usage(E_OPTERR);
648959
 	argv++;
648959
 	argc--;
648959
     }
648959
 
648959
     if (argc == 0)
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
 
648959
     spp = argv;
648959
     safe_strncpy(ifr.ifr_name, *spp++, IFNAMSIZ);
648959
@@ -117,19 +119,19 @@ int main(int argc, char **argv)
648959
     while (*spp != (char *) NULL) {
648959
 	if (!strcmp(*spp, "nibble")) {
648959
 	    if (*++spp == NULL)
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 	    plip->nibble = atoi(*spp);
648959
 	    spp++;
648959
 	    continue;
648959
 	}
648959
 	if (!strcmp(*spp, "trigger")) {
648959
 	    if (*++spp == NULL)
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 	    plip->trigger = atoi(*spp);
648959
 	    spp++;
648959
 	    continue;
648959
 	}
648959
-	usage();
648959
+	usage(E_OPTERR);
648959
     }
648959
 
648959
     plip->pcmd = PLIP_SET_TIMEOUT;
648959
diff --git a/slattach.c b/slattach.c
648959
index 5c81584..dbb2658 100644
648959
--- a/slattach.c
648959
+++ b/slattach.c
648959
@@ -581,7 +581,7 @@ sig_catch(int sig)
648959
 
648959
 
648959
 static void
648959
-usage(void)
648959
+usage(int rc)
648959
 {
648959
   char *usage_msg = "Usage: slattach [-ehlLmnqv] "
648959
 #ifdef SIOCSKEEPALIVE
648959
@@ -594,7 +594,7 @@ usage(void)
648959
 	  "       slattach -V | --version\n";
648959
 
648959
   fputs(usage_msg, stderr);
648959
-  exit(E_USAGE);
648959
+  exit(rc);
648959
 }
648959
 
648959
 
648959
@@ -691,7 +691,7 @@ main(int argc, char *argv[])
648959
 		/*NOTREACHED*/
648959
 
648959
 	default:
648959
-		usage();
648959
+		usage(E_OPTERR);
648959
 		/*NOTREACHED*/
648959
   }
648959
 
648959
@@ -707,7 +707,7 @@ main(int argc, char *argv[])
648959
        opt_m++;
648959
 
648959
   /* Is a terminal given? */
648959
-  if (optind != (argc - 1)) usage();
648959
+  if (optind != (argc - 1)) usage(E_OPTERR);
648959
   safe_strncpy(path_buf, argv[optind], sizeof(path_buf));
648959
   if (!strcmp(path_buf, "-")) {
648959
 	opt_e = 1;
648959
diff --git a/netstat.c.old b/netstat.c
648959
index dbcba2b..d04f0ff 100644
648959
--- a/netstat.c.old
648959
+++ b/netstat.c
648959
@@ -2286,7 +2286,7 @@ int main
648959
 
648959
     if(argc == optind + 1) {
648959
     	if((reptimer = atoi(argv[optind])) <= 0)
648959
-    		usage(E_USAGE);
648959
+    		usage(E_OPTERR);
648959
         flag_cnt++;
648959
     }
648959
 
648959
diff --git a/route.c.old b/route.c
648959
index f86bb8e..b0a885e 100644
648959
--- a/route.c.old
648959
+++ b/route.c
648959
@@ -186,6 +186,7 @@ int main(int argc, char **argv)
648959
 	case 'V':
648959
 	    version();
648959
 	case 'h':
648959
+	    usage(E_USAGE);
648959
 	case '?':
648959
 	    opt_h++;
648959
 	    break;
648959
@@ -198,7 +199,7 @@ int main(int argc, char **argv)
648959
 
648959
     if (opt_h) {
648959
 	if (!afname[0])
648959
-	    usage(E_USAGE);
648959
+	    usage(E_OPTERR);
648959
 	else
648959
 	    what = RTACTION_HELP;
648959
     } else {