diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2004-07-21 23:56:31 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2004-07-21 23:56:31 +0000 |
commit | d591a432a3b3aabb7dd101dc80979cc37c996679 (patch) | |
tree | a2674ff005e0c3a1492522433caa6dc0998d3626 | |
parent | 0315f670527c2fc6b2f48d6f23031f85a0e5471d (diff) | |
download | busybox-w32-d591a432a3b3aabb7dd101dc80979cc37c996679.tar.gz busybox-w32-d591a432a3b3aabb7dd101dc80979cc37c996679.tar.bz2 busybox-w32-d591a432a3b3aabb7dd101dc80979cc37c996679.zip |
Patch from Mike Snitzer to fix return codes.
"I have a need to _really_ know if the interface was properly configured
via ifup so I made busybox's ifupdown pass the return codes through rather
than dropping them on the floor."
"All the functions in ifupdown.c return 1 on success and 0 on failure
(which happens to the opposite of standard practices but whatever).
So it is important for all these functions to not blindly return 1."
"The problem with blindly returning ret, even if it is != 1, is the
callers expect a 0 or 1 and accumulate the return codes. So a function that
makes 3 calls to execute will have a value of 3 accumulated. That value
of 1 (success) was almost always returned even if 1 of the commands in the
command sequence failed. The attached patch fixes the lack of checking
to verify thar result == expected_reult."
git-svn-id: svn://busybox.net/trunk/busybox@8995 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | networking/ifupdown.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 5d7442253..9daa0f513 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -27,6 +27,8 @@ | |||
27 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 27 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* TODO: standardise execute() return codes to return 0 for success and 1 for failure */ | ||
31 | |||
30 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
31 | #include <sys/utsname.h> | 33 | #include <sys/utsname.h> |
32 | #include <sys/wait.h> | 34 | #include <sys/wait.h> |
@@ -347,6 +349,9 @@ static int execute(char *command, struct interface_defn_t *ifd, execfn *exec) | |||
347 | ret = (*exec) (out); | 349 | ret = (*exec) (out); |
348 | 350 | ||
349 | free(out); | 351 | free(out); |
352 | if (ret != 1) { | ||
353 | return(0); | ||
354 | } | ||
350 | return(1); | 355 | return(1); |
351 | } | 356 | } |
352 | 357 | ||
@@ -390,7 +395,7 @@ static int loopback_up6(struct interface_defn_t *ifd, execfn *exec) | |||
390 | int result; | 395 | int result; |
391 | result =execute("ip addr add ::1 dev %iface%", ifd, exec); | 396 | result =execute("ip addr add ::1 dev %iface%", ifd, exec); |
392 | result += execute("ip link set %iface% up", ifd, exec); | 397 | result += execute("ip link set %iface% up", ifd, exec); |
393 | return( result); | 398 | return ((result == 2) ? 2 : 0); |
394 | #else | 399 | #else |
395 | return( execute("ifconfig %iface% add ::1", ifd, exec)); | 400 | return( execute("ifconfig %iface% add ::1", ifd, exec)); |
396 | #endif | 401 | #endif |
@@ -417,7 +422,7 @@ static int static_up6(struct interface_defn_t *ifd, execfn *exec) | |||
417 | result += execute("ifconfig %iface% add %address%/%netmask%", ifd, exec); | 422 | result += execute("ifconfig %iface% add %address%/%netmask%", ifd, exec); |
418 | result += execute("[[ route -A inet6 add ::/0 gw %gateway% ]]", ifd, exec); | 423 | result += execute("[[ route -A inet6 add ::/0 gw %gateway% ]]", ifd, exec); |
419 | #endif | 424 | #endif |
420 | return( result); | 425 | return ((result == 3) ? 3 : 0); |
421 | } | 426 | } |
422 | 427 | ||
423 | static int static_down6(struct interface_defn_t *ifd, execfn *exec) | 428 | static int static_down6(struct interface_defn_t *ifd, execfn *exec) |
@@ -438,7 +443,7 @@ static int v4tunnel_up(struct interface_defn_t *ifd, execfn *exec) | |||
438 | result += execute("ip link set %iface% up", ifd, exec); | 443 | result += execute("ip link set %iface% up", ifd, exec); |
439 | result += execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec); | 444 | result += execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec); |
440 | result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec); | 445 | result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec); |
441 | return( result); | 446 | return ((result == 4) ? 4 : 0); |
442 | } | 447 | } |
443 | 448 | ||
444 | static int v4tunnel_down(struct interface_defn_t * ifd, execfn * exec) | 449 | static int v4tunnel_down(struct interface_defn_t * ifd, execfn * exec) |
@@ -469,7 +474,7 @@ static int loopback_up(struct interface_defn_t *ifd, execfn *exec) | |||
469 | int result; | 474 | int result; |
470 | result = execute("ip addr add 127.0.0.1/8 dev %iface%", ifd, exec); | 475 | result = execute("ip addr add 127.0.0.1/8 dev %iface%", ifd, exec); |
471 | result += execute("ip link set %iface% up", ifd, exec); | 476 | result += execute("ip link set %iface% up", ifd, exec); |
472 | return(result); | 477 | return ((result == 2) ? 2 : 0); |
473 | #else | 478 | #else |
474 | return( execute("ifconfig %iface% 127.0.0.1 up", ifd, exec)); | 479 | return( execute("ifconfig %iface% 127.0.0.1 up", ifd, exec)); |
475 | #endif | 480 | #endif |
@@ -481,7 +486,7 @@ static int loopback_down(struct interface_defn_t *ifd, execfn *exec) | |||
481 | int result; | 486 | int result; |
482 | result = execute("ip addr flush dev %iface%", ifd, exec); | 487 | result = execute("ip addr flush dev %iface%", ifd, exec); |
483 | result += execute("ip link set %iface% down", ifd, exec); | 488 | result += execute("ip link set %iface% down", ifd, exec); |
484 | return(result); | 489 | return ((result == 2) ? 2 : 0); |
485 | #else | 490 | #else |
486 | return( execute("ifconfig %iface% 127.0.0.1 down", ifd, exec)); | 491 | return( execute("ifconfig %iface% 127.0.0.1 down", ifd, exec)); |
487 | #endif | 492 | #endif |
@@ -495,14 +500,15 @@ static int static_up(struct interface_defn_t *ifd, execfn *exec) | |||
495 | "dev %iface% [[peer %pointopoint%]] [[label %label%]]", ifd, exec); | 500 | "dev %iface% [[peer %pointopoint%]] [[label %label%]]", ifd, exec); |
496 | result += execute("ip link set [[mtu %mtu%]] [[address %hwaddress%]] %iface% up", ifd, exec); | 501 | result += execute("ip link set [[mtu %mtu%]] [[address %hwaddress%]] %iface% up", ifd, exec); |
497 | result += execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec); | 502 | result += execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec); |
503 | return ((result == 3) ? 3 : 0); | ||
498 | #else | 504 | #else |
499 | result = execute("ifconfig %iface% %address% netmask %netmask% " | 505 | result = execute("ifconfig %iface% %address% netmask %netmask% " |
500 | "[[broadcast %broadcast%]] [[pointopoint %pointopoint%]] " | 506 | "[[broadcast %broadcast%]] [[pointopoint %pointopoint%]] " |
501 | "[[media %media%]] [[mtu %mtu%]] [[hw %hwaddress%]] up", | 507 | "[[media %media%]] [[mtu %mtu%]] [[hw %hwaddress%]] up", |
502 | ifd, exec); | 508 | ifd, exec); |
503 | result += execute("[[ route add default gw %gateway% %iface% ]]", ifd, exec); | 509 | result += execute("[[ route add default gw %gateway% %iface% ]]", ifd, exec); |
510 | return ((result == 2) ? 2 : 0); | ||
504 | #endif | 511 | #endif |
505 | return(result); | ||
506 | } | 512 | } |
507 | 513 | ||
508 | static int static_down(struct interface_defn_t *ifd, execfn *exec) | 514 | static int static_down(struct interface_defn_t *ifd, execfn *exec) |
@@ -515,7 +521,7 @@ static int static_down(struct interface_defn_t *ifd, execfn *exec) | |||
515 | result = execute("[[ route del default gw %gateway% %iface% ]]", ifd, exec); | 521 | result = execute("[[ route del default gw %gateway% %iface% ]]", ifd, exec); |
516 | result += execute("ifconfig %iface% down", ifd, exec); | 522 | result += execute("ifconfig %iface% down", ifd, exec); |
517 | #endif | 523 | #endif |
518 | return(result); | 524 | return ((result == 2) ? 2 : 0); |
519 | } | 525 | } |
520 | 526 | ||
521 | static int execable(char *program) | 527 | static int execable(char *program) |
@@ -562,7 +568,7 @@ static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) | |||
562 | } else if (execable("/sbin/pump")) { | 568 | } else if (execable("/sbin/pump")) { |
563 | result = execute("pump -i %iface% -k", ifd, exec); | 569 | result = execute("pump -i %iface% -k", ifd, exec); |
564 | } else if (execable("/sbin/dhclient")) { | 570 | } else if (execable("/sbin/dhclient")) { |
565 | execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", ifd, exec); | 571 | result = execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", ifd, exec); |
566 | } else if (execable("/sbin/dhcpcd")) { | 572 | } else if (execable("/sbin/dhcpcd")) { |
567 | result = execute("dhcpcd -k %iface%", ifd, exec); | 573 | result = execute("dhcpcd -k %iface%", ifd, exec); |
568 | } | 574 | } |
@@ -1033,9 +1039,10 @@ static int execute_all(struct interface_defn_t *ifd, execfn *exec, const char *o | |||
1033 | } | 1039 | } |
1034 | 1040 | ||
1035 | bb_xasprintf(&buf, "run-parts /etc/network/if-%s.d", opt); | 1041 | bb_xasprintf(&buf, "run-parts /etc/network/if-%s.d", opt); |
1036 | (*exec)(buf); | 1042 | if ((*exec)(buf) != 1) { |
1037 | 1043 | return 0; | |
1038 | return (1); | 1044 | } |
1045 | return 1; | ||
1039 | } | 1046 | } |
1040 | 1047 | ||
1041 | static int check(char *str) { | 1048 | static int check(char *str) { |
@@ -1116,7 +1123,7 @@ static int popen2(FILE **in, FILE **out, char *command, ...) | |||
1116 | /* unreached */ | 1123 | /* unreached */ |
1117 | } | 1124 | } |
1118 | 1125 | ||
1119 | static char * run_mapping(char *physical, struct mapping_defn_t * map) | 1126 | static char *run_mapping(char *physical, struct mapping_defn_t * map) |
1120 | { | 1127 | { |
1121 | FILE *in, *out; | 1128 | FILE *in, *out; |
1122 | int i, status; | 1129 | int i, status; |
@@ -1198,6 +1205,7 @@ extern int ifupdown_main(int argc, char **argv) | |||
1198 | #endif | 1205 | #endif |
1199 | int do_all = 0; | 1206 | int do_all = 0; |
1200 | int force = 0; | 1207 | int force = 0; |
1208 | int any_failures = 0; | ||
1201 | int i; | 1209 | int i; |
1202 | 1210 | ||
1203 | if (bb_applet_name[2] == 'u') { | 1211 | if (bb_applet_name[2] == 'u') { |
@@ -1312,6 +1320,7 @@ extern int ifupdown_main(int argc, char **argv) | |||
1312 | char *liface; | 1320 | char *liface; |
1313 | char *pch; | 1321 | char *pch; |
1314 | int okay = 0; | 1322 | int okay = 0; |
1323 | int cmds_ret; | ||
1315 | 1324 | ||
1316 | iface = strdup(target_list->data); | 1325 | iface = strdup(target_list->data); |
1317 | target_list = target_list->link; | 1326 | target_list = target_list->link; |
@@ -1374,9 +1383,13 @@ extern int ifupdown_main(int argc, char **argv) | |||
1374 | debug_noise("\nConfiguring interface %s (%s)\n", liface, currif->address_family->name); | 1383 | debug_noise("\nConfiguring interface %s (%s)\n", liface, currif->address_family->name); |
1375 | 1384 | ||
1376 | /* Call the cmds function pointer, does either iface_up() or iface_down() */ | 1385 | /* Call the cmds function pointer, does either iface_up() or iface_down() */ |
1377 | if (cmds(currif) == -1) { | 1386 | cmds_ret = cmds(currif); |
1387 | if (cmds_ret == -1) { | ||
1378 | bb_error_msg("Don't seem to have all the variables for %s/%s.", | 1388 | bb_error_msg("Don't seem to have all the variables for %s/%s.", |
1379 | liface, currif->address_family->name); | 1389 | liface, currif->address_family->name); |
1390 | any_failures += 1; | ||
1391 | } else if (cmds_ret == 0) { | ||
1392 | any_failures += 1; | ||
1380 | } | 1393 | } |
1381 | 1394 | ||
1382 | currif->iface = oldiface; | 1395 | currif->iface = oldiface; |
@@ -1389,6 +1402,7 @@ extern int ifupdown_main(int argc, char **argv) | |||
1389 | 1402 | ||
1390 | if (!okay && !force) { | 1403 | if (!okay && !force) { |
1391 | bb_error_msg("Ignoring unknown interface %s", liface); | 1404 | bb_error_msg("Ignoring unknown interface %s", liface); |
1405 | any_failures += 1; | ||
1392 | } else { | 1406 | } else { |
1393 | llist_t *iface_state = find_iface_state(state_list, iface); | 1407 | llist_t *iface_state = find_iface_state(state_list, iface); |
1394 | 1408 | ||
@@ -1448,5 +1462,7 @@ extern int ifupdown_main(int argc, char **argv) | |||
1448 | state_fp = NULL; | 1462 | state_fp = NULL; |
1449 | } | 1463 | } |
1450 | 1464 | ||
1465 | if (any_failures) | ||
1466 | return 1; | ||
1451 | return 0; | 1467 | return 0; |
1452 | } | 1468 | } |