diff options
Diffstat (limited to 'networking/ifupdown.c')
-rw-r--r-- | networking/ifupdown.c | 69 |
1 files changed, 8 insertions, 61 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 038bb13bc..6a200bb26 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -629,10 +629,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
629 | 629 | ||
630 | enum { NONE, IFACE, MAPPING } currently_processing = NONE; | 630 | enum { NONE, IFACE, MAPPING } currently_processing = NONE; |
631 | 631 | ||
632 | defn = xmalloc(sizeof(struct interfaces_file_t)); | 632 | defn = xzalloc(sizeof(struct interfaces_file_t)); |
633 | defn->autointerfaces = NULL; | ||
634 | defn->mappings = NULL; | ||
635 | defn->ifaces = NULL; | ||
636 | 633 | ||
637 | f = bb_xfopen(filename, "r"); | 634 | f = bb_xfopen(filename, "r"); |
638 | 635 | ||
@@ -647,10 +644,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
647 | 644 | ||
648 | if (strcmp(firstword, "mapping") == 0) { | 645 | if (strcmp(firstword, "mapping") == 0) { |
649 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING | 646 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING |
650 | currmap = xmalloc(sizeof(struct mapping_defn_t)); | 647 | currmap = xzalloc(sizeof(struct mapping_defn_t)); |
651 | currmap->max_matches = 0; | ||
652 | currmap->n_matches = 0; | ||
653 | currmap->match = NULL; | ||
654 | 648 | ||
655 | while ((firstword = next_word(&buf_ptr)) != NULL) { | 649 | while ((firstword = next_word(&buf_ptr)) != NULL) { |
656 | if (currmap->max_matches == currmap->n_matches) { | 650 | if (currmap->max_matches == currmap->n_matches) { |
@@ -690,7 +684,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
690 | NULL | 684 | NULL |
691 | }; | 685 | }; |
692 | 686 | ||
693 | currif = xmalloc(sizeof(struct interface_defn_t)); | 687 | currif = xzalloc(sizeof(struct interface_defn_t)); |
694 | iface_name = next_word(&buf_ptr); | 688 | iface_name = next_word(&buf_ptr); |
695 | address_family_name = next_word(&buf_ptr); | 689 | address_family_name = next_word(&buf_ptr); |
696 | method_name = next_word(&buf_ptr); | 690 | method_name = next_word(&buf_ptr); |
@@ -724,9 +718,6 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
724 | return NULL; | 718 | return NULL; |
725 | } | 719 | } |
726 | 720 | ||
727 | currif->max_options = 0; | ||
728 | currif->n_options = 0; | ||
729 | currif->option = NULL; | ||
730 | 721 | ||
731 | { | 722 | { |
732 | llist_t *iface_list; | 723 | llist_t *iface_list; |
@@ -845,9 +836,7 @@ static char *setlocalenv(char *format, const char *name, const char *value) | |||
845 | char *here; | 836 | char *here; |
846 | char *there; | 837 | char *there; |
847 | 838 | ||
848 | result = xmalloc(strlen(format) + strlen(name) + strlen(value) + 1); | 839 | result = bb_xasprintf(format, name, value); |
849 | |||
850 | sprintf(result, format, name, value); | ||
851 | 840 | ||
852 | for (here = there = result; *there != '=' && *there; there++) { | 841 | for (here = there = result; *there != '=' && *there; there++) { |
853 | if (*there == '-') | 842 | if (*there == '-') |
@@ -878,11 +867,9 @@ static void set_environ(struct interface_defn_t *iface, const char *mode) | |||
878 | *ppch = NULL; | 867 | *ppch = NULL; |
879 | } | 868 | } |
880 | free(__myenviron); | 869 | free(__myenviron); |
881 | __myenviron = NULL; | ||
882 | } | 870 | } |
883 | __myenviron = xmalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ )); | 871 | __myenviron = xzalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ )); |
884 | environend = __myenviron; | 872 | environend = __myenviron; |
885 | *environend = NULL; | ||
886 | 873 | ||
887 | for (i = 0; i < iface->n_options; i++) { | 874 | for (i = 0; i < iface->n_options; i++) { |
888 | if (strcmp(iface->option[i].name, "up") == 0 | 875 | if (strcmp(iface->option[i].name, "up") == 0 |
@@ -892,19 +879,13 @@ static void set_environ(struct interface_defn_t *iface, const char *mode) | |||
892 | continue; | 879 | continue; |
893 | } | 880 | } |
894 | *(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); | 881 | *(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); |
895 | *environend = NULL; | ||
896 | } | 882 | } |
897 | 883 | ||
898 | *(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface); | 884 | *(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface); |
899 | *environend = NULL; | ||
900 | *(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name); | 885 | *(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name); |
901 | *environend = NULL; | ||
902 | *(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name); | 886 | *(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name); |
903 | *environend = NULL; | ||
904 | *(environend++) = setlocalenv("%s=%s", "MODE", mode); | 887 | *(environend++) = setlocalenv("%s=%s", "MODE", mode); |
905 | *environend = NULL; | ||
906 | *(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"); | 888 | *(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"); |
907 | *environend = NULL; | ||
908 | } | 889 | } |
909 | 890 | ||
910 | static int doit(char *str) | 891 | static int doit(char *str) |
@@ -1069,7 +1050,7 @@ static char *run_mapping(char *physical, struct mapping_defn_t * map) | |||
1069 | free(logical); | 1050 | free(logical); |
1070 | logical = new_logical; | 1051 | logical = new_logical; |
1071 | } else { | 1052 | } else { |
1072 | /* If we are UNABLE to read a line of output, discard are | 1053 | /* If we are UNABLE to read a line of output, discard our |
1073 | * freshly allocated memory. */ | 1054 | * freshly allocated memory. */ |
1074 | free(new_logical); | 1055 | free(new_logical); |
1075 | } | 1056 | } |
@@ -1177,28 +1158,6 @@ int ifupdown_main(int argc, char **argv) | |||
1177 | if (cmds == iface_up) { | 1158 | if (cmds == iface_up) { |
1178 | target_list = defn->autointerfaces; | 1159 | target_list = defn->autointerfaces; |
1179 | } else { | 1160 | } else { |
1180 | #if 0 | ||
1181 | /* iface_down */ | ||
1182 | llist_t *new_item; | ||
1183 | const llist_t *list = state_list; | ||
1184 | while (list) { | ||
1185 | new_item = xmalloc(sizeof(llist_t)); | ||
1186 | new_item->data = bb_xstrdup(list->data); | ||
1187 | new_item->link = NULL; | ||
1188 | list = target_list; | ||
1189 | if (list == NULL) | ||
1190 | target_list = new_item; | ||
1191 | else { | ||
1192 | while (list->link) { | ||
1193 | list = list->link; | ||
1194 | } | ||
1195 | list = new_item; | ||
1196 | } | ||
1197 | list = list->link; | ||
1198 | } | ||
1199 | target_list = defn->autointerfaces; | ||
1200 | #else | ||
1201 | |||
1202 | /* iface_down */ | 1161 | /* iface_down */ |
1203 | const llist_t *list = state_list; | 1162 | const llist_t *list = state_list; |
1204 | while (list) { | 1163 | while (list) { |
@@ -1206,7 +1165,6 @@ int ifupdown_main(int argc, char **argv) | |||
1206 | list = list->link; | 1165 | list = list->link; |
1207 | } | 1166 | } |
1208 | target_list = defn->autointerfaces; | 1167 | target_list = defn->autointerfaces; |
1209 | #endif | ||
1210 | } | 1168 | } |
1211 | } else { | 1169 | } else { |
1212 | llist_add_to_end(&target_list, argv[optind]); | 1170 | llist_add_to_end(&target_list, argv[optind]); |
@@ -1308,8 +1266,7 @@ int ifupdown_main(int argc, char **argv) | |||
1308 | llist_t *iface_state = find_iface_state(state_list, iface); | 1266 | llist_t *iface_state = find_iface_state(state_list, iface); |
1309 | 1267 | ||
1310 | if (cmds == iface_up) { | 1268 | if (cmds == iface_up) { |
1311 | char *newiface = xmalloc(strlen(iface) + 1 + strlen(liface) + 1); | 1269 | char *newiface = bb_xasprintf("%s=%s", iface, liface); |
1312 | sprintf(newiface, "%s=%s", iface, liface); | ||
1313 | if (iface_state == NULL) { | 1270 | if (iface_state == NULL) { |
1314 | llist_add_to_end(&state_list, newiface); | 1271 | llist_add_to_end(&state_list, newiface); |
1315 | } else { | 1272 | } else { |
@@ -1318,17 +1275,7 @@ int ifupdown_main(int argc, char **argv) | |||
1318 | } | 1275 | } |
1319 | } else { | 1276 | } else { |
1320 | /* Remove an interface from the linked list */ | 1277 | /* Remove an interface from the linked list */ |
1321 | if (iface_state) { | 1278 | free(llist_pop(&iface_state)); |
1322 | llist_t *l = iface_state->link; | ||
1323 | free(iface_state->data); | ||
1324 | iface_state->data = NULL; | ||
1325 | iface_state->link = NULL; | ||
1326 | if (l) { | ||
1327 | iface_state->data = l->data; | ||
1328 | iface_state->link = l->link; | ||
1329 | } | ||
1330 | free(l); | ||
1331 | } | ||
1332 | } | 1279 | } |
1333 | } | 1280 | } |
1334 | } | 1281 | } |