summaryrefslogtreecommitdiff
path: root/networking/ifupdown.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /networking/ifupdown.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
Major coreutils update.
Diffstat (limited to 'networking/ifupdown.c')
-rw-r--r--networking/ifupdown.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 0511a5b95..9bbb90496 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -244,7 +244,7 @@ static char *parse(char *command, interface_defn_t *ifd)
244 varvalue = get_var(command, nextpercent - command, ifd); 244 varvalue = get_var(command, nextpercent - command, ifd);
245 245
246 if (varvalue) { 246 if (varvalue) {
247 addstr(&result, &len, &pos, varvalue, xstrlen(varvalue)); 247 addstr(&result, &len, &pos, varvalue, bb_strlen(varvalue));
248 } else { 248 } else {
249#ifdef CONFIG_FEATURE_IFUPDOWN_IP 249#ifdef CONFIG_FEATURE_IFUPDOWN_IP
250 /* Sigh... Add a special case for 'ip' to convert from 250 /* Sigh... Add a special case for 'ip' to convert from
@@ -255,7 +255,7 @@ static char *parse(char *command, interface_defn_t *ifd)
255 if (varvalue && (res=count_netmask_bits(varvalue)) > 0) { 255 if (varvalue && (res=count_netmask_bits(varvalue)) > 0) {
256 char argument[255]; 256 char argument[255];
257 sprintf(argument, "%d", res); 257 sprintf(argument, "%d", res);
258 addstr(&result, &len, &pos, argument, xstrlen(argument)); 258 addstr(&result, &len, &pos, argument, bb_strlen(argument));
259 command = nextpercent + 1; 259 command = nextpercent + 1;
260 break; 260 break;
261 } 261 }
@@ -734,9 +734,9 @@ static interfaces_file_t *read_interfaces(char *filename)
734 defn->mappings = NULL; 734 defn->mappings = NULL;
735 defn->ifaces = NULL; 735 defn->ifaces = NULL;
736 736
737 f = xfopen(filename, "r"); 737 f = bb_xfopen(filename, "r");
738 738
739 while ((buf = get_line_from_file(f)) != NULL) { 739 while ((buf = bb_get_line_from_file(f)) != NULL) {
740 char *buf_ptr = buf; 740 char *buf_ptr = buf;
741 741
742 /* Ignore comments */ 742 /* Ignore comments */
@@ -762,7 +762,7 @@ static interfaces_file_t *read_interfaces(char *filename)
762 currmap->match = xrealloc(currmap->match, sizeof(currmap->match) * currmap->max_matches); 762 currmap->match = xrealloc(currmap->match, sizeof(currmap->match) * currmap->max_matches);
763 } 763 }
764 764
765 currmap->match[currmap->n_matches++] = xstrdup(firstword); 765 currmap->match[currmap->n_matches++] = bb_xstrdup(firstword);
766 } 766 }
767 currmap->max_mappings = 0; 767 currmap->max_mappings = 0;
768 currmap->n_mappings = 0; 768 currmap->n_mappings = 0;
@@ -802,26 +802,26 @@ static interfaces_file_t *read_interfaces(char *filename)
802 method_name = next_word(&buf_ptr); 802 method_name = next_word(&buf_ptr);
803 803
804 if (buf_ptr == NULL) { 804 if (buf_ptr == NULL) {
805 error_msg("too few parameters for line \"%s\"", buf); 805 bb_error_msg("too few parameters for line \"%s\"", buf);
806 return NULL; 806 return NULL;
807 } 807 }
808 808
809 if (buf_ptr[0] != '\0') { 809 if (buf_ptr[0] != '\0') {
810 error_msg("too many parameters \"%s\"", buf); 810 bb_error_msg("too many parameters \"%s\"", buf);
811 return NULL; 811 return NULL;
812 } 812 }
813 813
814 currif->iface = xstrdup(iface_name); 814 currif->iface = bb_xstrdup(iface_name);
815 815
816 currif->address_family = get_address_family(addr_fams, address_family_name); 816 currif->address_family = get_address_family(addr_fams, address_family_name);
817 if (!currif->address_family) { 817 if (!currif->address_family) {
818 error_msg("unknown address type \"%s\"", buf); 818 bb_error_msg("unknown address type \"%s\"", buf);
819 return NULL; 819 return NULL;
820 } 820 }
821 821
822 currif->method = get_method(currif->address_family, method_name); 822 currif->method = get_method(currif->address_family, method_name);
823 if (!currif->method) { 823 if (!currif->method) {
824 error_msg("unknown method \"%s\"", buf); 824 bb_error_msg("unknown method \"%s\"", buf);
825 return NULL; 825 return NULL;
826 } 826 }
827 827
@@ -836,7 +836,7 @@ static interfaces_file_t *read_interfaces(char *filename)
836 836
837 while (*where != NULL) { 837 while (*where != NULL) {
838 if (duplicate_if(*where, currif)) { 838 if (duplicate_if(*where, currif)) {
839 error_msg("duplicate interface \"%s\"", buf); 839 bb_error_msg("duplicate interface \"%s\"", buf);
840 return NULL; 840 return NULL;
841 } 841 }
842 where = &(*where)->next; 842 where = &(*where)->next;
@@ -852,7 +852,7 @@ static interfaces_file_t *read_interfaces(char *filename)
852 852
853 /* Check the interface isnt already listed */ 853 /* Check the interface isnt already listed */
854 if (find_list_string(defn->autointerfaces, firstword)) { 854 if (find_list_string(defn->autointerfaces, firstword)) {
855 perror_msg_and_die("interface declared auto twice \"%s\"", buf); 855 bb_perror_msg_and_die("interface declared auto twice \"%s\"", buf);
856 } 856 }
857 857
858 /* Add the interface to the list */ 858 /* Add the interface to the list */
@@ -865,8 +865,8 @@ static interfaces_file_t *read_interfaces(char *filename)
865 { 865 {
866 int i; 866 int i;
867 867
868 if (xstrlen(buf_ptr) == 0) { 868 if (bb_strlen(buf_ptr) == 0) {
869 error_msg("option with empty value \"%s\"", buf); 869 bb_error_msg("option with empty value \"%s\"", buf);
870 return NULL; 870 return NULL;
871 } 871 }
872 872
@@ -876,7 +876,7 @@ static interfaces_file_t *read_interfaces(char *filename)
876 && strcmp(firstword, "post-down") != 0) { 876 && strcmp(firstword, "post-down") != 0) {
877 for (i = 0; i < currif->n_options; i++) { 877 for (i = 0; i < currif->n_options; i++) {
878 if (strcmp(currif->option[i].name, firstword) == 0) { 878 if (strcmp(currif->option[i].name, firstword) == 0) {
879 error_msg("duplicate option \"%s\"", buf); 879 bb_error_msg("duplicate option \"%s\"", buf);
880 return NULL; 880 return NULL;
881 } 881 }
882 } 882 }
@@ -889,8 +889,8 @@ static interfaces_file_t *read_interfaces(char *filename)
889 opt = xrealloc(currif->option, sizeof(*opt) * currif->max_options); 889 opt = xrealloc(currif->option, sizeof(*opt) * currif->max_options);
890 currif->option = opt; 890 currif->option = opt;
891 } 891 }
892 currif->option[currif->n_options].name = xstrdup(firstword); 892 currif->option[currif->n_options].name = bb_xstrdup(firstword);
893 currif->option[currif->n_options].value = xstrdup(next_word(&buf_ptr)); 893 currif->option[currif->n_options].value = bb_xstrdup(next_word(&buf_ptr));
894 if (!currif->option[currif->n_options].name) { 894 if (!currif->option[currif->n_options].name) {
895 perror(filename); 895 perror(filename);
896 return NULL; 896 return NULL;
@@ -905,34 +905,34 @@ static interfaces_file_t *read_interfaces(char *filename)
905#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING 905#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
906 if (strcmp(firstword, "script") == 0) { 906 if (strcmp(firstword, "script") == 0) {
907 if (currmap->script != NULL) { 907 if (currmap->script != NULL) {
908 error_msg("duplicate script in mapping \"%s\"", buf); 908 bb_error_msg("duplicate script in mapping \"%s\"", buf);
909 return NULL; 909 return NULL;
910 } else { 910 } else {
911 currmap->script = xstrdup(next_word(&buf_ptr)); 911 currmap->script = bb_xstrdup(next_word(&buf_ptr));
912 } 912 }
913 } else if (strcmp(firstword, "map") == 0) { 913 } else if (strcmp(firstword, "map") == 0) {
914 if (currmap->max_mappings == currmap->n_mappings) { 914 if (currmap->max_mappings == currmap->n_mappings) {
915 currmap->max_mappings = currmap->max_mappings * 2 + 1; 915 currmap->max_mappings = currmap->max_mappings * 2 + 1;
916 currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings); 916 currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings);
917 } 917 }
918 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&buf_ptr)); 918 currmap->mapping[currmap->n_mappings] = bb_xstrdup(next_word(&buf_ptr));
919 currmap->n_mappings++; 919 currmap->n_mappings++;
920 } else { 920 } else {
921 error_msg("misplaced option \"%s\"", buf); 921 bb_error_msg("misplaced option \"%s\"", buf);
922 return NULL; 922 return NULL;
923 } 923 }
924#endif 924#endif
925 break; 925 break;
926 case NONE: 926 case NONE:
927 default: 927 default:
928 error_msg("misplaced option \"%s\"", buf); 928 bb_error_msg("misplaced option \"%s\"", buf);
929 return NULL; 929 return NULL;
930 } 930 }
931 } 931 }
932 free(buf); 932 free(buf);
933 } 933 }
934 if (ferror(f) != 0) { 934 if (ferror(f) != 0) {
935 perror_msg_and_die("%s", filename); 935 bb_perror_msg_and_die("%s", filename);
936 } 936 }
937 fclose(f); 937 fclose(f);
938 938
@@ -945,7 +945,7 @@ static char *setlocalenv(char *format, char *name, char *value)
945 char *here; 945 char *here;
946 char *there; 946 char *there;
947 947
948 result = xmalloc(xstrlen(format) + xstrlen(name) + xstrlen(value) + 1); 948 result = xmalloc(bb_strlen(format) + bb_strlen(name) + bb_strlen(value) + 1);
949 949
950 sprintf(result, format, name, value); 950 sprintf(result, format, name, value);
951 951
@@ -960,7 +960,7 @@ static char *setlocalenv(char *format, char *name, char *value)
960 here++; 960 here++;
961 } 961 }
962 } 962 }
963 memmove(here, there, xstrlen(there) + 1); 963 memmove(here, there, bb_strlen(there) + 1);
964 964
965 return result; 965 return result;
966} 966}
@@ -1010,7 +1010,7 @@ static void set_environ(interface_defn_t *iface, char *mode)
1010static int doit(char *str) 1010static int doit(char *str)
1011{ 1011{
1012 if (verbose || no_act) { 1012 if (verbose || no_act) {
1013 error_msg("%s", str); 1013 bb_error_msg("%s", str);
1014 } 1014 }
1015 if (!no_act) { 1015 if (!no_act) {
1016 pid_t child; 1016 pid_t child;
@@ -1045,7 +1045,7 @@ static int execute_all(interface_defn_t *ifd, execfn *exec, const char *opt)
1045 } 1045 }
1046 } 1046 }
1047 1047
1048 buf = xmalloc(xstrlen(opt) + 19); 1048 buf = xmalloc(bb_strlen(opt) + 19);
1049 sprintf(buf, "/etc/network/if-%s.d", opt); 1049 sprintf(buf, "/etc/network/if-%s.d", opt);
1050 run_parts(&buf, 2); 1050 run_parts(&buf, 2);
1051 free(buf); 1051 free(buf);
@@ -1155,7 +1155,7 @@ static int run_mapping(char *physical, char *logical, int len, mapping_defn_t *
1155 waitpid(pid, &status, 0); 1155 waitpid(pid, &status, 0);
1156 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { 1156 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
1157 if (fgets(logical, len, out)) { 1157 if (fgets(logical, len, out)) {
1158 char *pch = logical + xstrlen(logical) - 1; 1158 char *pch = logical + bb_strlen(logical) - 1;
1159 1159
1160 while (pch >= logical && isspace(*pch)) 1160 while (pch >= logical && isspace(*pch))
1161 *(pch--) = '\0'; 1161 *(pch--) = '\0';
@@ -1169,7 +1169,7 @@ static int run_mapping(char *physical, char *logical, int len, mapping_defn_t *
1169 1169
1170static llist_t *find_iface_state(llist_t *state_list, const char *iface) 1170static llist_t *find_iface_state(llist_t *state_list, const char *iface)
1171{ 1171{
1172 unsigned short iface_len = xstrlen(iface); 1172 unsigned short iface_len = bb_strlen(iface);
1173 llist_t *search = state_list; 1173 llist_t *search = state_list;
1174 1174
1175 while (search) { 1175 while (search) {
@@ -1199,7 +1199,7 @@ extern int ifupdown_main(int argc, char **argv)
1199 int force = 0; 1199 int force = 0;
1200 int i; 1200 int i;
1201 1201
1202 if (applet_name[2] == 'u') { 1202 if (bb_applet_name[2] == 'u') {
1203 /* ifup command */ 1203 /* ifup command */
1204 cmds = iface_up; 1204 cmds = iface_up;
1205 } else { 1205 } else {
@@ -1214,7 +1214,7 @@ extern int ifupdown_main(int argc, char **argv)
1214#endif 1214#endif
1215 switch (i) { 1215 switch (i) {
1216 case 'i': /* interfaces */ 1216 case 'i': /* interfaces */
1217 interfaces = xstrdup(optarg); 1217 interfaces = bb_xstrdup(optarg);
1218 break; 1218 break;
1219 case 'v': /* verbose */ 1219 case 'v': /* verbose */
1220 verbose = 1; 1220 verbose = 1;
@@ -1234,18 +1234,18 @@ extern int ifupdown_main(int argc, char **argv)
1234 force = 1; 1234 force = 1;
1235 break; 1235 break;
1236 default: 1236 default:
1237 show_usage(); 1237 bb_show_usage();
1238 break; 1238 break;
1239 } 1239 }
1240 } 1240 }
1241 1241
1242 if (argc - optind > 0) { 1242 if (argc - optind > 0) {
1243 if (do_all) { 1243 if (do_all) {
1244 show_usage(); 1244 bb_show_usage();
1245 } 1245 }
1246 } else { 1246 } else {
1247 if (!do_all) { 1247 if (!do_all) {
1248 show_usage(); 1248 bb_show_usage();
1249 } 1249 }
1250 } 1250 }
1251 1251
@@ -1297,13 +1297,13 @@ extern int ifupdown_main(int argc, char **argv)
1297 if (cmds == iface_up) { 1297 if (cmds == iface_up) {
1298 /* ifup */ 1298 /* ifup */
1299 if (iface_state) { 1299 if (iface_state) {
1300 error_msg("interface %s already configured", iface); 1300 bb_error_msg("interface %s already configured", iface);
1301 continue; 1301 continue;
1302 } 1302 }
1303 } else { 1303 } else {
1304 /* ifdown */ 1304 /* ifdown */
1305 if (iface_state) { 1305 if (iface_state) {
1306 error_msg("interface %s not configured", iface); 1306 bb_error_msg("interface %s not configured", iface);
1307 continue; 1307 continue;
1308 } 1308 }
1309 } 1309 }
@@ -1319,7 +1319,7 @@ extern int ifupdown_main(int argc, char **argv)
1319 if (fnmatch(currmap->match[i], liface, 0) != 0) 1319 if (fnmatch(currmap->match[i], liface, 0) != 0)
1320 continue; 1320 continue;
1321 if (verbose) { 1321 if (verbose) {
1322 error_msg("Running mapping script %s on %s", currmap->script, liface); 1322 bb_error_msg("Running mapping script %s on %s", currmap->script, liface);
1323 } 1323 }
1324 run_mapping(iface, liface, sizeof(liface), currmap); 1324 run_mapping(iface, liface, sizeof(liface), currmap);
1325 break; 1325 break;
@@ -1336,7 +1336,7 @@ extern int ifupdown_main(int argc, char **argv)
1336 currif->iface = iface; 1336 currif->iface = iface;
1337 1337
1338 if (verbose) { 1338 if (verbose) {
1339 error_msg("Configuring interface %s=%s (%s)", iface, liface, currif->address_family->name); 1339 bb_error_msg("Configuring interface %s=%s (%s)", iface, liface, currif->address_family->name);
1340 } 1340 }
1341 1341
1342 /* Call the cmds function pointer, does either iface_up() or iface_down() */ 1342 /* Call the cmds function pointer, does either iface_up() or iface_down() */
@@ -1351,12 +1351,12 @@ extern int ifupdown_main(int argc, char **argv)
1351 } 1351 }
1352 1352
1353 if (!okay && !force) { 1353 if (!okay && !force) {
1354 error_msg("Ignoring unknown interface %s=%s.", iface, liface); 1354 bb_error_msg("Ignoring unknown interface %s=%s.", iface, liface);
1355 } else { 1355 } else {
1356 llist_t *iface_state = find_iface_state(state_list, iface); 1356 llist_t *iface_state = find_iface_state(state_list, iface);
1357 1357
1358 if (cmds == iface_up) { 1358 if (cmds == iface_up) {
1359 char *newiface = xmalloc(xstrlen(iface) + 1 + xstrlen(liface) + 1); 1359 char *newiface = xmalloc(bb_strlen(iface) + 1 + bb_strlen(liface) + 1);
1360 sprintf(newiface, "%s=%s", iface, liface); 1360 sprintf(newiface, "%s=%s", iface, liface);
1361 if (iface_state == NULL) { 1361 if (iface_state == NULL) {
1362 state_list = llist_add_to(state_list, newiface); 1362 state_list = llist_add_to(state_list, newiface);
@@ -1387,10 +1387,10 @@ extern int ifupdown_main(int argc, char **argv)
1387 1387
1388 if (state_fp) 1388 if (state_fp)
1389 fclose(state_fp); 1389 fclose(state_fp);
1390 state_fp = xfopen(statefile, "a+"); 1390 state_fp = bb_xfopen(statefile, "a+");
1391 1391
1392 if (ftruncate(fileno(state_fp), 0) < 0) { 1392 if (ftruncate(fileno(state_fp), 0) < 0) {
1393 error_msg_and_die("failed to truncate statefile %s: %s", statefile, strerror(errno)); 1393 bb_error_msg_and_die("failed to truncate statefile %s: %s", statefile, strerror(errno));
1394 } 1394 }
1395 1395
1396 rewind(state_fp); 1396 rewind(state_fp);