aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-11 22:16:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-11 22:16:56 +0000
commitf6f43df60bbd69ae5ea83b9012beb953a2baf116 (patch)
tree80c51cd39201fcffaa9537c5abd1b10da3811ad0
parent8de82bf84f7311bd74b08d9f4b4d4a6fef4649b9 (diff)
downloadbusybox-w32-f6f43df60bbd69ae5ea83b9012beb953a2baf116.tar.gz
busybox-w32-f6f43df60bbd69ae5ea83b9012beb953a2baf116.tar.bz2
busybox-w32-f6f43df60bbd69ae5ea83b9012beb953a2baf116.zip
ifupdown: stop emitting annoying/misleading error messages.
Patch by Gabriel Somlo <somlo at cmu.edu>
-rw-r--r--debianutils/which.c68
-rw-r--r--include/libbb.h4
-rw-r--r--libbb/Kbuild2
-rw-r--r--networking/ifupdown.c88
4 files changed, 74 insertions, 88 deletions
diff --git a/debianutils/which.c b/debianutils/which.c
index 583d94613..e83c752a1 100644
--- a/debianutils/which.c
+++ b/debianutils/which.c
@@ -3,6 +3,7 @@
3 * Which implementation for busybox 3 * Which implementation for busybox
4 * 4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
6 * 7 *
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
8 * 9 *
@@ -10,74 +11,33 @@
10 */ 11 */
11 12
12#include "busybox.h" 13#include "busybox.h"
13#include <string.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <unistd.h>
17#include <sys/stat.h>
18
19
20static int is_executable_file(char *a, struct stat *b)
21{
22 return (!access(a,X_OK) && !stat(a, b) && S_ISREG(b->st_mode));
23}
24 14
25int which_main(int argc, char **argv) 15int which_main(int argc, char **argv)
26{ 16{
27 int status; 17 int status = EXIT_SUCCESS;
28 size_t i, count; 18 char *p;
29 char *path_list, *p;
30 19
31 if (argc <= 1 || argv[1][0] == '-') { 20 if (argc <= 1 || argv[1][0] == '-') {
32 bb_show_usage(); 21 bb_show_usage();
33 } 22 }
34 argc--;
35
36 path_list = getenv("PATH");
37 if (path_list != NULL) {
38 count = 1;
39 p = path_list;
40 while ((p = strchr(p, ':')) != NULL) {
41 *p++ = 0;
42 count++;
43 }
44 } else {
45 path_list = "/bin\0/sbin\0/usr/bin\0/usr/sbin\0/usr/local/bin";
46 count = 5;
47 }
48
49 status = EXIT_SUCCESS;
50 while (argc-- > 0) {
51 struct stat stat_b;
52 char *buf;
53 23
24 while (--argc > 0) {
54 argv++; 25 argv++;
55 buf = argv[0]; 26 if (strchr(*argv, '/')) {
56 27 if (execable_file(*argv)) {
57 /* If filename is either absolute or contains slashes, 28 puts(*argv);
58 * stat it */ 29 continue;
59 if (strchr(buf, '/')) {
60 if (is_executable_file(buf, &stat_b)) {
61 puts(buf);
62 goto next;
63 } 30 }
64 } else { 31 } else {
65 /* File doesn't contain slashes */ 32 p = find_execable(*argv);
66 p = path_list; 33 if (p) {
67 for (i = 0; i < count; i++) { 34 puts(p);
68 /* Empty component in PATH is treated as . */ 35 free(p);
69 buf = concat_path_file(p[0] ? p : ".", argv[0]); 36 continue;
70 if (is_executable_file(buf, &stat_b)) {
71 puts(buf);
72 free(buf);
73 goto next;
74 }
75 free(buf);
76 p += strlen(p) + 1;
77 } 37 }
78 } 38 }
79 status = EXIT_FAILURE; 39 status = EXIT_FAILURE;
80 next: /* nothing */;
81 } 40 }
41
82 bb_fflush_stdout_and_exit(status); 42 bb_fflush_stdout_and_exit(status);
83} 43}
diff --git a/include/libbb.h b/include/libbb.h
index 1d26b0367..ac48411c0 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -430,6 +430,10 @@ char *last_char_is(const char *s, int c);
430 430
431char *fgets_str(FILE *file, const char *terminating_string); 431char *fgets_str(FILE *file, const char *terminating_string);
432 432
433int execable_file(const char *name);
434char *find_execable(const char *filename);
435int exists_execable(const char *filename);
436
433extern USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out); 437extern USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
434extern int inflate(int in, int out); 438extern int inflate(int in, int out);
435 439
diff --git a/libbb/Kbuild b/libbb/Kbuild
index 4e992ef5b..27ed68c2c 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -28,7 +28,7 @@ lib-y:= \
28 getopt32.o default_error_retval.o wfopen_input.o speed_table.o \ 28 getopt32.o default_error_retval.o wfopen_input.o speed_table.o \
29 perror_nomsg_and_die.o perror_nomsg.o skip_whitespace.o bb_askpass.o \ 29 perror_nomsg_and_die.o perror_nomsg.o skip_whitespace.o bb_askpass.o \
30 warn_ignoring_args.o concat_subpath_file.o vfork_daemon_rexec.o \ 30 warn_ignoring_args.o concat_subpath_file.o vfork_daemon_rexec.o \
31 bb_do_delay.o uuencode.o info_msg.o vinfo_msg.o 31 bb_do_delay.o uuencode.o info_msg.o vinfo_msg.o execable.o
32 32
33# conditionally compiled objects: 33# conditionally compiled objects:
34lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o 34lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index f572b487d..c1dc1d35d 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -133,7 +133,7 @@ static int count_netmask_bits(char *dotted_quad)
133} 133}
134#endif 134#endif
135 135
136static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_length) 136static void addstr(char **buf, size_t *len, size_t *pos, const char *str, size_t str_length)
137{ 137{
138 if (*pos + str_length >= *len) { 138 if (*pos + str_length >= *len) {
139 char *newbuf; 139 char *newbuf;
@@ -150,7 +150,7 @@ static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_l
150 (*buf)[*pos] = '\0'; 150 (*buf)[*pos] = '\0';
151} 151}
152 152
153static int strncmpz(char *l, char *r, size_t llen) 153static int strncmpz(const char *l, const char *r, size_t llen)
154{ 154{
155 int i = strncmp(l, r, llen); 155 int i = strncmp(l, r, llen);
156 156
@@ -161,7 +161,7 @@ static int strncmpz(char *l, char *r, size_t llen)
161 } 161 }
162} 162}
163 163
164static char *get_var(char *id, size_t idlen, struct interface_defn_t *ifd) 164static char *get_var(const char *id, size_t idlen, struct interface_defn_t *ifd)
165{ 165{
166 int i; 166 int i;
167 167
@@ -188,7 +188,7 @@ static char *get_var(char *id, size_t idlen, struct interface_defn_t *ifd)
188 return NULL; 188 return NULL;
189} 189}
190 190
191static char *parse(char *command, struct interface_defn_t *ifd) 191static char *parse(const char *command, struct interface_defn_t *ifd)
192{ 192{
193 193
194 char *result = NULL; 194 char *result = NULL;
@@ -294,7 +294,7 @@ static char *parse(char *command, struct interface_defn_t *ifd)
294} 294}
295 295
296/* execute() returns 1 for success and 0 for failure */ 296/* execute() returns 1 for success and 0 for failure */
297static int execute(char *command, struct interface_defn_t *ifd, execfn *exec) 297static int execute(const char *command, struct interface_defn_t *ifd, execfn *exec)
298{ 298{
299 char *out; 299 char *out;
300 int ret; 300 int ret;
@@ -449,43 +449,65 @@ static int static_down(struct interface_defn_t *ifd, execfn *exec)
449 return ((result == 2) ? 2 : 0); 449 return ((result == 2) ? 2 : 0);
450} 450}
451 451
452static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) 452#ifndef CONFIG_APP_UDHCPC
453struct dhcp_client_t
453{ 454{
454 if (execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface% " 455 const char *name;
455 "[[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]", ifd, exec)) 456 const char *startcmd;
456 return 1; 457 const char *stopcmd;
457 458};
458 /* 2006-09-30: The following are deprecated, and should eventually be
459 * removed. For non-busybox (i.e., other than udhcpc) clients, use
460 * 'iface foo inet manual' in /etc/network/interfaces, and supply
461 * start/stop commands explicitly via up/down. */
462 459
463 if (execute("pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]", 460static const struct dhcp_client_t ext_dhcp_clients[] = {
464 ifd, exec)) return 1; 461 { "udhcpc",
465 if (execute("dhclient -pf /var/run/dhclient.%iface%.pid %iface%", 462 "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]",
466 ifd, exec)) return 1; 463 "kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
467 if (execute("dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] " 464 },
468 "[[-l %leasetime%]] %iface%", ifd, exec)) return 1; 465 { "pump",
466 "pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]",
467 "pump -i %iface% -k",
468 },
469 { "dhclient",
470 "dhclient -pf /var/run/dhclient.%iface%.pid %iface%",
471 "kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null",
472 },
473 { "dhcpcd",
474 "dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] [[-l %leasetime%]] %iface%",
475 "dhcpcd -k %iface%",
476 },
477};
478#endif
469 479
480static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
481{
482#ifdef CONFIG_APP_UDHCPC
483 return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
484 "-i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]",
485 ifd, exec);
486#else
487 int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
488 for (i = 0; i < nclients; i++) {
489 if (exists_execable(ext_dhcp_clients[i].name))
490 return execute(ext_dhcp_clients[i].startcmd, ifd, exec);
491 }
492 bb_error_msg("no dhcp clients found");
470 return 0; 493 return 0;
494#endif
471} 495}
472 496
473static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) 497static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
474{ 498{
475 if (execute("kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", 499#ifdef CONFIG_APP_UDHCPC
476 ifd, exec)) return 1; 500 return execute("kill -TERM "
477 501 "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
478 /* 2006-09-30: The following are deprecated, and should eventually be 502#else
479 * removed. For non-busybox (i.e., other than udhcpc) clients, use 503 int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
480 * 'iface foo inet manual' in /etc/network/interfaces, and supply 504 for (i = 0; i < nclients; i++) {
481 * start/stop commands explicitly via up/down. */ 505 if (exists_execable(ext_dhcp_clients[i].name))
482 506 return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
483 if (execute("pump -i %iface% -k", ifd, exec)) return 1; 507 }
484 if (execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", 508 bb_error_msg("no dhcp clients found, using static interface shutdown");
485 ifd, exec)) return 1;
486 if (execute("dhcpcd -k %iface%", ifd, exec)) return 1;
487
488 return static_down(ifd, exec); 509 return static_down(ifd, exec);
510#endif
489} 511}
490 512
491static int manual_up_down(struct interface_defn_t *ifd, execfn *exec) 513static int manual_up_down(struct interface_defn_t *ifd, execfn *exec)