summaryrefslogtreecommitdiff
path: root/networking/ifupdown.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-20 10:02:29 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-20 10:02:29 +0000
commit3c8bca364d640976f0d8829c0b1bb2a414778acc (patch)
treeb49fe8d105fe24be957bd016ca8abfdad7faac08 /networking/ifupdown.c
parent25ea42de9bb947193ac759e7bef6067ddf9c77ad (diff)
downloadbusybox-w32-3c8bca364d640976f0d8829c0b1bb2a414778acc.tar.gz
busybox-w32-3c8bca364d640976f0d8829c0b1bb2a414778acc.tar.bz2
busybox-w32-3c8bca364d640976f0d8829c0b1bb2a414778acc.zip
Fixup whitespace handing, fixing some annoying behavior and
a couple of segfaults
Diffstat (limited to 'networking/ifupdown.c')
-rw-r--r--networking/ifupdown.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 5b37c3ab7..8170e80b3 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -467,7 +467,7 @@ static int loopback_up(struct interface_defn_t *ifd, execfn *exec)
467{ 467{
468#ifdef CONFIG_FEATURE_IFUPDOWN_IP 468#ifdef CONFIG_FEATURE_IFUPDOWN_IP
469 int result; 469 int result;
470 result += execute("ip link set %iface% up", ifd, exec); 470 result = execute("ip link set %iface% up", ifd, exec);
471 result += execute("ip addr add 127.0.0.1/8 dev %iface% label %label%", ifd, exec); 471 result += execute("ip addr add 127.0.0.1/8 dev %iface% label %label%", ifd, exec);
472 return(result); 472 return(result);
473#else 473#else
@@ -547,15 +547,13 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
547 547
548static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) 548static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
549{ 549{
550 int result; 550 int result = 0;
551 if (execable("/sbin/udhcpc")) { 551 if (execable("/sbin/udhcpc")) {
552 execute("kill -9 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); 552 execute("kill -9 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
553 result = 0;
554 } else if (execable("/sbin/pump")) { 553 } else if (execable("/sbin/pump")) {
555 result = execute("pump -i %iface% -k", ifd, exec); 554 result = execute("pump -i %iface% -k", ifd, exec);
556 } else if (execable("/sbin/dhclient")) { 555 } else if (execable("/sbin/dhclient")) {
557 execute("kill -9 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); 556 execute("kill -9 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
558 result = 0;
559 } else if (execable("/sbin/dhcpcd")) { 557 } else if (execable("/sbin/dhcpcd")) {
560 result = execute("dhcpcd -k %iface%", ifd, exec); 558 result = execute("dhcpcd -k %iface%", ifd, exec);
561 } 559 }
@@ -625,7 +623,15 @@ static char *next_word(char **buf)
625 } 623 }
626 624
627 /* Skip over leading whitespace */ 625 /* Skip over leading whitespace */
628 word = *buf + strspn(*buf, " \t\n"); 626 word = *buf;
627 while (isspace(*word)) {
628 ++word;
629 }
630
631 /* Skip over comments */
632 if (*word == '#') {
633 return(NULL);
634 }
629 635
630 /* Find the length of this word */ 636 /* Find the length of this word */
631 length = strcspn(word, " \t\n"); 637 length = strcspn(word, " \t\n");
@@ -711,13 +717,9 @@ static struct interfaces_file_t *read_interfaces(char *filename)
711 while ((buf = bb_get_chomped_line_from_file(f)) != NULL) { 717 while ((buf = bb_get_chomped_line_from_file(f)) != NULL) {
712 char *buf_ptr = buf; 718 char *buf_ptr = buf;
713 719
714 /* Ignore comments */
715 if (buf[0] == '#') {
716 continue;
717 }
718
719 firstword = next_word(&buf_ptr); 720 firstword = next_word(&buf_ptr);
720 if (firstword == NULL) { 721 if (firstword == NULL) {
722 free(buf);
721 continue; /* blank line */ 723 continue; /* blank line */
722 } 724 }
723 725
@@ -779,6 +781,11 @@ static struct interfaces_file_t *read_interfaces(char *filename)
779 return NULL; 781 return NULL;
780 } 782 }
781 783
784 /* ship any trailing whitespace */
785 while (isspace(*buf_ptr)) {
786 ++buf_ptr;
787 }
788
782 if (buf_ptr[0] != '\0') { 789 if (buf_ptr[0] != '\0') {
783 bb_error_msg("too many parameters \"%s\"", buf); 790 bb_error_msg("too many parameters \"%s\"", buf);
784 return NULL; 791 return NULL;
@@ -1229,6 +1236,10 @@ extern int ifupdown_main(int argc, char **argv)
1229 defn = read_interfaces(interfaces); 1236 defn = read_interfaces(interfaces);
1230 debug_noise("\ndone reading %s\n\n", interfaces); 1237 debug_noise("\ndone reading %s\n\n", interfaces);
1231 1238
1239 if (!defn) {
1240 exit(EXIT_FAILURE);
1241 }
1242
1232 if (no_act) { 1243 if (no_act) {
1233 state_fp = fopen(statefile, "r"); 1244 state_fp = fopen(statefile, "r");
1234 } 1245 }