diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-23 12:49:01 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-23 12:49:01 +0000 |
| commit | 7f1f5b001f5a0dee058024f7bee04dced38877df (patch) | |
| tree | 762b9940c5be349a4f9d10f67b131c1ce6b43eb5 | |
| parent | a65a17700af53300b90a4dbfaeab972c1771e2ba (diff) | |
| download | busybox-w32-7f1f5b001f5a0dee058024f7bee04dced38877df.tar.gz busybox-w32-7f1f5b001f5a0dee058024f7bee04dced38877df.tar.bz2 busybox-w32-7f1f5b001f5a0dee058024f7bee04dced38877df.zip | |
ifupdown: getopt_ulflags'ification.
| -rw-r--r-- | networking/ifupdown.c | 88 |
1 files changed, 29 insertions, 59 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index fa5bfe1e9..88bdc521f 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
| @@ -91,8 +91,21 @@ struct interfaces_file_t | |||
| 91 | struct mapping_defn_t *mappings; | 91 | struct mapping_defn_t *mappings; |
| 92 | }; | 92 | }; |
| 93 | 93 | ||
| 94 | static char no_act = 0; | 94 | static unsigned option_mask; |
| 95 | static char verbose = 0; | 95 | #define OPTION_STR "anvf" USE_FEATURE_IFUPDOWN_MAPPING("m") "i:" |
| 96 | enum { | ||
| 97 | OPT_do_all = 0x1, | ||
| 98 | OPT_no_act = 0x2, | ||
| 99 | OPT_verbose = 0x4, | ||
| 100 | OPT_force = 0x8, | ||
| 101 | OPT_no_mappings = 0x10, | ||
| 102 | }; | ||
| 103 | #define DO_ALL (option_mask & OPT_do_all) | ||
| 104 | #define NO_ACT (option_mask & OPT_no_act) | ||
| 105 | #define VERBOSE (option_mask & OPT_verbose) | ||
| 106 | #define FORCE (option_mask & OPT_force) | ||
| 107 | #define NO_MAPPINGS (option_mask & OPT_no_mappings) | ||
| 108 | |||
| 96 | static char **__myenviron = NULL; | 109 | static char **__myenviron = NULL; |
| 97 | 110 | ||
| 98 | #if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6 | 111 | #if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6 |
| @@ -875,10 +888,10 @@ static void set_environ(struct interface_defn_t *iface, const char *mode) | |||
| 875 | 888 | ||
| 876 | static int doit(char *str) | 889 | static int doit(char *str) |
| 877 | { | 890 | { |
| 878 | if (verbose || no_act) { | 891 | if (option_mask & (OPT_no_act|OPT_verbose)) { |
| 879 | printf("%s\n", str); | 892 | printf("%s\n", str); |
| 880 | } | 893 | } |
| 881 | if (!no_act) { | 894 | if (!(option_mask & OPT_no_act)) { |
| 882 | pid_t child; | 895 | pid_t child; |
| 883 | int status; | 896 | int status; |
| 884 | 897 | ||
| @@ -895,7 +908,7 @@ static int doit(char *str) | |||
| 895 | return 0; | 908 | return 0; |
| 896 | } | 909 | } |
| 897 | } | 910 | } |
| 898 | return (1); | 911 | return 1; |
| 899 | } | 912 | } |
| 900 | 913 | ||
| 901 | static int execute_all(struct interface_defn_t *ifd, const char *opt) | 914 | static int execute_all(struct interface_defn_t *ifd, const char *opt) |
| @@ -1070,12 +1083,6 @@ int ifupdown_main(int argc, char **argv) | |||
| 1070 | llist_t *target_list = NULL; | 1083 | llist_t *target_list = NULL; |
| 1071 | const char *interfaces = "/etc/network/interfaces"; | 1084 | const char *interfaces = "/etc/network/interfaces"; |
| 1072 | const char *statefile = "/var/run/ifstate"; | 1085 | const char *statefile = "/var/run/ifstate"; |
| 1073 | |||
| 1074 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING | ||
| 1075 | int run_mappings = 1; | ||
| 1076 | #endif | ||
| 1077 | int do_all = 0; | ||
| 1078 | int force = 0; | ||
| 1079 | int any_failures = 0; | 1086 | int any_failures = 0; |
| 1080 | int i; | 1087 | int i; |
| 1081 | 1088 | ||
| @@ -1087,48 +1094,11 @@ int ifupdown_main(int argc, char **argv) | |||
| 1087 | cmds = iface_down; | 1094 | cmds = iface_down; |
| 1088 | } | 1095 | } |
| 1089 | 1096 | ||
| 1090 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING | 1097 | option_mask = bb_getopt_ulflags(argc, argv, OPTION_STR, &interfaces); |
| 1091 | while ((i = getopt(argc, argv, "i:hvnamf")) != -1) | ||
| 1092 | #else | ||
| 1093 | while ((i = getopt(argc, argv, "i:hvnaf")) != -1) | ||
| 1094 | #endif | ||
| 1095 | { | ||
| 1096 | switch (i) { | ||
| 1097 | case 'i': /* interfaces */ | ||
| 1098 | interfaces = optarg; | ||
| 1099 | break; | ||
| 1100 | case 'v': /* verbose */ | ||
| 1101 | verbose = 1; | ||
| 1102 | break; | ||
| 1103 | case 'a': /* all */ | ||
| 1104 | do_all = 1; | ||
| 1105 | break; | ||
| 1106 | case 'n': /* no-act */ | ||
| 1107 | no_act = 1; | ||
| 1108 | break; | ||
| 1109 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING | ||
| 1110 | case 'm': /* no-mappings */ | ||
| 1111 | run_mappings = 0; | ||
| 1112 | break; | ||
| 1113 | #endif | ||
| 1114 | case 'f': /* force */ | ||
| 1115 | force = 1; | ||
| 1116 | break; | ||
| 1117 | default: | ||
| 1118 | bb_show_usage(); | ||
| 1119 | break; | ||
| 1120 | } | ||
| 1121 | } | ||
| 1122 | |||
| 1123 | if (argc - optind > 0) { | 1098 | if (argc - optind > 0) { |
| 1124 | if (do_all) { | 1099 | if (DO_ALL) bb_show_usage(); |
| 1125 | bb_show_usage(); | 1100 | } else |
| 1126 | } | 1101 | if (!DO_ALL) bb_show_usage(); |
| 1127 | } else { | ||
| 1128 | if (!do_all) { | ||
| 1129 | bb_show_usage(); | ||
| 1130 | } | ||
| 1131 | } | ||
| 1132 | 1102 | ||
| 1133 | debug_noise("reading %s file:\n", interfaces); | 1103 | debug_noise("reading %s file:\n", interfaces); |
| 1134 | defn = read_interfaces(interfaces); | 1104 | defn = read_interfaces(interfaces); |
| @@ -1139,7 +1109,7 @@ int ifupdown_main(int argc, char **argv) | |||
| 1139 | } | 1109 | } |
| 1140 | 1110 | ||
| 1141 | /* Create a list of interfaces to work on */ | 1111 | /* Create a list of interfaces to work on */ |
| 1142 | if (do_all) { | 1112 | if (DO_ALL) { |
| 1143 | if (cmds == iface_up) { | 1113 | if (cmds == iface_up) { |
| 1144 | target_list = defn->autointerfaces; | 1114 | target_list = defn->autointerfaces; |
| 1145 | } else { | 1115 | } else { |
| @@ -1177,7 +1147,7 @@ int ifupdown_main(int argc, char **argv) | |||
| 1177 | liface = xstrdup(iface); | 1147 | liface = xstrdup(iface); |
| 1178 | } | 1148 | } |
| 1179 | 1149 | ||
| 1180 | if (!force) { | 1150 | if (!FORCE) { |
| 1181 | const llist_t *iface_state = find_iface_state(state_list, iface); | 1151 | const llist_t *iface_state = find_iface_state(state_list, iface); |
| 1182 | 1152 | ||
| 1183 | if (cmds == iface_up) { | 1153 | if (cmds == iface_up) { |
| @@ -1196,7 +1166,7 @@ int ifupdown_main(int argc, char **argv) | |||
| 1196 | } | 1166 | } |
| 1197 | 1167 | ||
| 1198 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING | 1168 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING |
| 1199 | if ((cmds == iface_up) && run_mappings) { | 1169 | if ((cmds == iface_up) && !NO_MAPPINGS) { |
| 1200 | struct mapping_defn_t *currmap; | 1170 | struct mapping_defn_t *currmap; |
| 1201 | 1171 | ||
| 1202 | for (currmap = defn->mappings; currmap; currmap = currmap->next) { | 1172 | for (currmap = defn->mappings; currmap; currmap = currmap->next) { |
| @@ -1204,7 +1174,7 @@ int ifupdown_main(int argc, char **argv) | |||
| 1204 | for (i = 0; i < currmap->n_matches; i++) { | 1174 | for (i = 0; i < currmap->n_matches; i++) { |
| 1205 | if (fnmatch(currmap->match[i], liface, 0) != 0) | 1175 | if (fnmatch(currmap->match[i], liface, 0) != 0) |
| 1206 | continue; | 1176 | continue; |
| 1207 | if (verbose) { | 1177 | if (VERBOSE) { |
| 1208 | printf("Running mapping script %s on %s\n", currmap->script, liface); | 1178 | printf("Running mapping script %s on %s\n", currmap->script, liface); |
| 1209 | } | 1179 | } |
| 1210 | liface = run_mapping(iface, currmap); | 1180 | liface = run_mapping(iface, currmap); |
| @@ -1240,11 +1210,11 @@ int ifupdown_main(int argc, char **argv) | |||
| 1240 | } | 1210 | } |
| 1241 | iface_list = iface_list->link; | 1211 | iface_list = iface_list->link; |
| 1242 | } | 1212 | } |
| 1243 | if (verbose) { | 1213 | if (VERBOSE) { |
| 1244 | printf("\n"); | 1214 | printf("\n"); |
| 1245 | } | 1215 | } |
| 1246 | 1216 | ||
| 1247 | if (!okay && !force) { | 1217 | if (!okay && !FORCE) { |
| 1248 | bb_error_msg("Ignoring unknown interface %s", liface); | 1218 | bb_error_msg("Ignoring unknown interface %s", liface); |
| 1249 | any_failures += 1; | 1219 | any_failures += 1; |
| 1250 | } else { | 1220 | } else { |
| @@ -1266,7 +1236,7 @@ int ifupdown_main(int argc, char **argv) | |||
| 1266 | } | 1236 | } |
| 1267 | 1237 | ||
| 1268 | /* Actually write the new state */ | 1238 | /* Actually write the new state */ |
| 1269 | if (!no_act) { | 1239 | if (!NO_ACT) { |
| 1270 | FILE *state_fp = NULL; | 1240 | FILE *state_fp = NULL; |
| 1271 | 1241 | ||
| 1272 | state_fp = xfopen(statefile, "w"); | 1242 | state_fp = xfopen(statefile, "w"); |
