summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-02 02:34:19 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-02 02:34:19 +0200
commit54e0843e7dabc4f6d79781f8b07094dadacd4cd5 (patch)
treefb25b2bdb58f309872c4c13ec24376f89ebcf684 /shell
parent48a29defcaeb3e3bbf32ae6ed3f77de2101e083a (diff)
downloadbusybox-w32-54e0843e7dabc4f6d79781f8b07094dadacd4cd5.tar.gz
busybox-w32-54e0843e7dabc4f6d79781f8b07094dadacd4cd5.tar.bz2
busybox-w32-54e0843e7dabc4f6d79781f8b07094dadacd4cd5.zip
hush: make . cmd search $PATH
function old new delta builtin_source 128 249 +121 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 692076cf4..cbec2dd71 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -6142,7 +6142,6 @@ int hush_main(int argc, char **argv)
6142 /* If we are login shell... */ 6142 /* If we are login shell... */
6143 if (argv[0] && argv[0][0] == '-') { 6143 if (argv[0] && argv[0][0] == '-') {
6144 FILE *input; 6144 FILE *input;
6145 /* TODO: what should argv be while sourcing /etc/profile? */
6146 debug_printf("sourcing /etc/profile\n"); 6145 debug_printf("sourcing /etc/profile\n");
6147 input = fopen_for_read("/etc/profile"); 6146 input = fopen_for_read("/etc/profile");
6148 if (input != NULL) { 6147 if (input != NULL) {
@@ -6875,6 +6874,7 @@ static int builtin_shift(char **argv)
6875 6874
6876static int builtin_source(char **argv) 6875static int builtin_source(char **argv)
6877{ 6876{
6877 const char *PATH;
6878 FILE *input; 6878 FILE *input;
6879 save_arg_t sv; 6879 save_arg_t sv;
6880#if ENABLE_HUSH_FUNCTIONS 6880#if ENABLE_HUSH_FUNCTIONS
@@ -6884,12 +6884,36 @@ static int builtin_source(char **argv)
6884 if (*++argv == NULL) 6884 if (*++argv == NULL)
6885 return EXIT_FAILURE; 6885 return EXIT_FAILURE;
6886 6886
6887// TODO: search through $PATH is missing 6887 if (strchr(*argv, '/') == NULL
6888 && (PATH = get_local_var_value("PATH")) != NULL
6889 ) {
6890 /* Search through $PATH */
6891 while (1) {
6892 const char *end = strchrnul(PATH, ':');
6893 int sz = end - PATH; /* must be int! */
6894
6895 if (sz != 0) {
6896 char *tmp = xasprintf("%.*s/%s", sz, PATH, *argv);
6897 input = fopen_for_read(tmp);
6898 free(tmp);
6899 } else {
6900 /* We have xxx::yyyy in $PATH,
6901 * it means "use current dir" */
6902 input = fopen_for_read(*argv);
6903 }
6904 if (input)
6905 goto opened_ok;
6906 if (*end == '\0')
6907 break;
6908 PATH = end + 1;
6909 }
6910 }
6888 input = fopen_or_warn(*argv, "r"); 6911 input = fopen_or_warn(*argv, "r");
6889 if (!input) { 6912 if (!input) {
6890 /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ 6913 /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */
6891 return EXIT_FAILURE; 6914 return EXIT_FAILURE;
6892 } 6915 }
6916 opened_ok:
6893 close_on_exec_on(fileno(input)); 6917 close_on_exec_on(fileno(input));
6894 6918
6895#if ENABLE_HUSH_FUNCTIONS 6919#if ENABLE_HUSH_FUNCTIONS