aboutsummaryrefslogtreecommitdiff
path: root/debianutils
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 /debianutils
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>
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/which.c68
1 files changed, 14 insertions, 54 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}