diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-20 17:01:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-20 17:01:14 +0000 |
commit | b32502da83ff7e7241a4584c88f3a35859dfeeda (patch) | |
tree | 7dcdaf2b3940b86ca74f185cdb5dedfdc385c8d2 /networking | |
parent | 568d8c9a5cb05a595b4201198fd3c780920586dc (diff) | |
download | busybox-w32-1_5_1.tar.gz busybox-w32-1_5_1.tar.bz2 busybox-w32-1_5_1.zip |
applied post-1.5.0 fixes1_5_1
Diffstat (limited to 'networking')
-rw-r--r-- | networking/ifupdown.c | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 887c2eea5..74646c6f5 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -1083,15 +1083,32 @@ static llist_t *find_iface_state(llist_t *state_list, const char *iface) | |||
1083 | return NULL; | 1083 | return NULL; |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | /* read the previous state from the state file */ | ||
1087 | static llist_t *read_iface_state(void) { | ||
1088 | llist_t *state_list = NULL; | ||
1089 | FILE *state_fp; | ||
1090 | state_fp = fopen("/var/run/ifstate", "r"); | ||
1091 | if (state_fp) { | ||
1092 | char *start, *end_ptr; | ||
1093 | while ((start = xmalloc_fgets(state_fp)) != NULL) { | ||
1094 | /* We should only need to check for a single character */ | ||
1095 | end_ptr = start + strcspn(start, " \t\n"); | ||
1096 | *end_ptr = '\0'; | ||
1097 | llist_add_to(&state_list, start); | ||
1098 | } | ||
1099 | fclose(state_fp); | ||
1100 | } | ||
1101 | return state_list; | ||
1102 | } | ||
1103 | |||
1104 | |||
1086 | int ifupdown_main(int argc, char **argv); | 1105 | int ifupdown_main(int argc, char **argv); |
1087 | int ifupdown_main(int argc, char **argv) | 1106 | int ifupdown_main(int argc, char **argv) |
1088 | { | 1107 | { |
1089 | int (*cmds)(struct interface_defn_t *) = NULL; | 1108 | int (*cmds)(struct interface_defn_t *) = NULL; |
1090 | struct interfaces_file_t *defn; | 1109 | struct interfaces_file_t *defn; |
1091 | llist_t *state_list = NULL; | ||
1092 | llist_t *target_list = NULL; | 1110 | llist_t *target_list = NULL; |
1093 | const char *interfaces = "/etc/network/interfaces"; | 1111 | const char *interfaces = "/etc/network/interfaces"; |
1094 | FILE *state_fp; | ||
1095 | bool any_failures = 0; | 1112 | bool any_failures = 0; |
1096 | 1113 | ||
1097 | cmds = iface_down; | 1114 | cmds = iface_down; |
@@ -1118,32 +1135,9 @@ int ifupdown_main(int argc, char **argv) | |||
1118 | startup_PATH = getenv("PATH"); | 1135 | startup_PATH = getenv("PATH"); |
1119 | if (!startup_PATH) startup_PATH = ""; | 1136 | if (!startup_PATH) startup_PATH = ""; |
1120 | 1137 | ||
1121 | /* Read the previous state from the state file */ | ||
1122 | state_fp = fopen("/var/run/ifstate", "r"); | ||
1123 | if (state_fp) { | ||
1124 | char *start, *end_ptr; | ||
1125 | while ((start = xmalloc_fgets(state_fp)) != NULL) { | ||
1126 | /* We should only need to check for a single character */ | ||
1127 | end_ptr = start + strcspn(start, " \t\n"); | ||
1128 | *end_ptr = '\0'; | ||
1129 | llist_add_to(&state_list, start); | ||
1130 | } | ||
1131 | fclose(state_fp); | ||
1132 | } | ||
1133 | |||
1134 | /* Create a list of interfaces to work on */ | 1138 | /* Create a list of interfaces to work on */ |
1135 | if (DO_ALL) { | 1139 | if (DO_ALL) { |
1136 | if (cmds == iface_up) { | 1140 | target_list = defn->autointerfaces; |
1137 | target_list = defn->autointerfaces; | ||
1138 | } else { | ||
1139 | /* iface_down */ | ||
1140 | const llist_t *list = state_list; | ||
1141 | while (list) { | ||
1142 | llist_add_to_end(&target_list, xstrdup(list->data)); | ||
1143 | list = list->link; | ||
1144 | } | ||
1145 | target_list = defn->autointerfaces; | ||
1146 | } | ||
1147 | } else { | 1141 | } else { |
1148 | llist_add_to_end(&target_list, argv[optind]); | 1142 | llist_add_to_end(&target_list, argv[optind]); |
1149 | } | 1143 | } |
@@ -1170,6 +1164,7 @@ int ifupdown_main(int argc, char **argv) | |||
1170 | } | 1164 | } |
1171 | 1165 | ||
1172 | if (!FORCE) { | 1166 | if (!FORCE) { |
1167 | llist_t *state_list = read_iface_state(); | ||
1173 | const llist_t *iface_state = find_iface_state(state_list, iface); | 1168 | const llist_t *iface_state = find_iface_state(state_list, iface); |
1174 | 1169 | ||
1175 | if (cmds == iface_up) { | 1170 | if (cmds == iface_up) { |
@@ -1185,6 +1180,7 @@ int ifupdown_main(int argc, char **argv) | |||
1185 | continue; | 1180 | continue; |
1186 | } | 1181 | } |
1187 | } | 1182 | } |
1183 | llist_free(state_list, free); | ||
1188 | } | 1184 | } |
1189 | 1185 | ||
1190 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING | 1186 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING |
@@ -1239,6 +1235,8 @@ int ifupdown_main(int argc, char **argv) | |||
1239 | bb_error_msg("ignoring unknown interface %s", liface); | 1235 | bb_error_msg("ignoring unknown interface %s", liface); |
1240 | any_failures = 1; | 1236 | any_failures = 1; |
1241 | } else { | 1237 | } else { |
1238 | /* update the state file */ | ||
1239 | llist_t *state_list = read_iface_state(); | ||
1242 | llist_t *iface_state = find_iface_state(state_list, iface); | 1240 | llist_t *iface_state = find_iface_state(state_list, iface); |
1243 | 1241 | ||
1244 | if (cmds == iface_up) { | 1242 | if (cmds == iface_up) { |
@@ -1254,19 +1252,21 @@ int ifupdown_main(int argc, char **argv) | |||
1254 | llist_unlink(&state_list, iface_state); | 1252 | llist_unlink(&state_list, iface_state); |
1255 | free(llist_pop(&iface_state)); | 1253 | free(llist_pop(&iface_state)); |
1256 | } | 1254 | } |
1257 | } | ||
1258 | } | ||
1259 | 1255 | ||
1260 | /* Actually write the new state */ | 1256 | /* Actually write the new state */ |
1261 | if (!NO_ACT) { | 1257 | if (!NO_ACT) { |
1262 | state_fp = xfopen("/var/run/ifstate", "w"); | 1258 | FILE *state_fp = xfopen("/var/run/ifstate", "w"); |
1263 | while (state_list) { | 1259 | llist_t *state = state_list; |
1264 | if (state_list->data) { | 1260 | while (state) { |
1265 | fprintf(state_fp, "%s\n", state_list->data); | 1261 | if (state->data) { |
1262 | fprintf(state_fp, "%s\n", state->data); | ||
1263 | } | ||
1264 | state = state->link; | ||
1265 | } | ||
1266 | fclose(state_fp); | ||
1266 | } | 1267 | } |
1267 | state_list = state_list->link; | 1268 | llist_free(state_list, free); |
1268 | } | 1269 | } |
1269 | fclose(state_fp); | ||
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | return any_failures; | 1272 | return any_failures; |