summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorEric Andersen2003-06-20 10:02:29 +0000
committerEric Andersen2003-06-20 10:02:29 +0000
commit3c8bca364d640976f0d8829c0b1bb2a414778acc (patch)
treeb49fe8d105fe24be957bd016ca8abfdad7faac08 /networking
parent25ea42de9bb947193ac759e7bef6067ddf9c77ad (diff)
downloadbusybox-3c8bca364d640976f0d8829c0b1bb2a414778acc.zip
busybox-3c8bca364d640976f0d8829c0b1bb2a414778acc.tar.gz
Fixup whitespace handing, fixing some annoying behavior and
a couple of segfaults
Diffstat (limited to 'networking')
-rw-r--r--networking/ifupdown.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 5b37c3a..8170e80 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -467,7 +467,7 @@ static int loopback_up(struct interface_defn_t *ifd, execfn *exec)
{
#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_up(struct interface_defn_t *ifd, execfn *exec)
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 @@ static char *next_word(char **buf)
}
/* 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 @@ static struct interfaces_file_t *read_interfaces(char *filename)
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 @@ static struct interfaces_file_t *read_interfaces(char *filename)
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;
@@ -1229,6 +1236,10 @@ extern int ifupdown_main(int argc, char **argv)
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");
}