[BusyBox-cvs] busybox/networking ifupdown.c,1.24,1.25

Erik Andersen andersen at busybox.net
Fri Jun 20 10:02:33 UTC 2003


Update of /var/cvs/busybox/networking
In directory winder:/tmp/cvs-serv16300/networking

Modified Files:
	ifupdown.c 
Log Message:
Fixup whitespace handing, fixing some annoying behavior and
a couple of segfaults


Index: ifupdown.c
===================================================================
RCS file: /var/cvs/busybox/networking/ifupdown.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- ifupdown.c	5 Jun 2003 19:37:01 -0000	1.24
+++ ifupdown.c	20 Jun 2003 10:02:29 -0000	1.25
@@ -467,7 +467,7 @@
 {
 #ifdef CONFIG_FEATURE_IFUPDOWN_IP
 	int result;
-	result += execute("ip link set %iface% up", ifd, exec);
+	result = execute("ip link set %iface% up", ifd, exec);
 	result += execute("ip addr add 127.0.0.1/8 dev %iface% label %label%", ifd, exec);
 	return(result);
 #else
@@ -547,15 +547,13 @@
 
 static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 {
-	int result;
+	int result = 0;
 	if (execable("/sbin/udhcpc")) {
 		execute("kill -9 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
-		result = 0; 
 	} else if (execable("/sbin/pump")) {
 		result = execute("pump -i %iface% -k", ifd, exec);
 	} else if (execable("/sbin/dhclient")) {
 		execute("kill -9 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
-		result = 0; 
 	} else if (execable("/sbin/dhcpcd")) {
 		result = execute("dhcpcd -k %iface%", ifd, exec);
 	}
@@ -625,7 +623,15 @@
 	}
 
 	/* Skip over leading whitespace */
-	word = *buf + strspn(*buf, " \t\n");
+	word = *buf;
+	while (isspace(*word)) {
+		++word;
+	}
+
+	/* Skip over comments */
+	if (*word == '#') {
+		return(NULL);
+	}
 
 	/* Find the length of this word */
 	length = strcspn(word, " \t\n");
@@ -711,13 +717,9 @@
 	while ((buf = bb_get_chomped_line_from_file(f)) != NULL) {
 		char *buf_ptr = buf;
 
-		/* Ignore comments */
-		if (buf[0] == '#') {
-			continue;
-		}
-
 		firstword = next_word(&buf_ptr);
 		if (firstword == NULL) {
+			free(buf);
 			continue;	/* blank line */
 		}
 
@@ -779,6 +781,11 @@
 					return NULL;
 				}
 
+				/* ship any trailing whitespace */
+				while (isspace(*buf_ptr)) {
+					++buf_ptr;
+				}
+
 				if (buf_ptr[0] != '\0') {
 					bb_error_msg("too many parameters \"%s\"", buf);
 					return NULL;
@@ -1228,6 +1235,10 @@
 	debug_noise("reading %s file:\n", interfaces);
 	defn = read_interfaces(interfaces);
 	debug_noise("\ndone reading %s\n\n", interfaces);
+
+	if (!defn) {
+		exit(EXIT_FAILURE);
+	}
 
 	if (no_act) {
 		state_fp = fopen(statefile, "r");



More information about the busybox-cvs mailing list