[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 6/8] builtins/source: use source path in isolated mode
From: |
Matheus Afonso Martins Moreira |
Subject: |
[PATCH v2 6/8] builtins/source: use source path in isolated mode |
Date: |
Mon, 13 May 2024 07:37:24 -0300 |
Behave normally when executed without any options.
Search only BASH_SOURCE_PATH for scripts to source
when isolated mode is enabled via the -i option.
Signed-off-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
---
builtins/source.def | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/builtins/source.def b/builtins/source.def
index 26040e70..7f870bfe 100644
--- a/builtins/source.def
+++ b/builtins/source.def
@@ -83,6 +83,7 @@ extern int errno;
static void uw_maybe_pop_dollar_vars (void *);
static int execute_file_contents (WORD_LIST *, char *, char *);
static char *search_for_file (WORD_LIST *);
+static char *isolated_search_for_file (WORD_LIST *);
/* If non-zero, `.' uses $PATH to look up the script to be sourced. */
int source_uses_path = 1;
@@ -177,6 +178,27 @@ search_for_file (WORD_LIST *list)
return (filename);
}
+static char *
+isolated_search_for_file (WORD_LIST *list)
+{
+ char *filename = NULL;
+
+ if (absolute_pathname (list->word->word))
+ filename = savestring (list->word->word);
+ else
+ filename = find_in_path_var (list->word->word, "BASH_SOURCE_PATH",
FS_READABLE);
+
+ if (filename == 0)
+ {
+ if (source_searches_cwd == 0)
+ return (NULL);
+ else
+ filename = savestring (list->word->word);
+ }
+
+ return (filename);
+}
+
/* Read and execute commands from the file passed as argument. */
int
source_builtin (WORD_LIST *list)
@@ -226,7 +248,10 @@ source_builtin (WORD_LIST *list)
}
#endif
- filename = search_for_file (list);
+ if (!isolated_mode)
+ filename = search_for_file (list);
+ else
+ filename = isolated_search_for_file (list);
if (filename == 0)
{
--
2.44.0
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, (continued)
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Chet Ramey, 2024/05/17
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Robert Elz, 2024/05/17
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Chet Ramey, 2024/05/20
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Matheus Afonso Martins Moreira, 2024/05/20
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Andreas Kähäri, 2024/05/20
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Matheus Afonso Martins Moreira, 2024/05/20
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Greg Wooledge, 2024/05/20
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Andreas Kähäri, 2024/05/20
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Chet Ramey, 2024/05/20
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Chet Ramey, 2024/05/20
[PATCH v2 6/8] builtins/source: use source path in isolated mode,
Matheus Afonso Martins Moreira <=
Re: [PATCH v2 6/8] builtins/source: use source path in isolated mode, Chet Ramey, 2024/05/14
Re: [PATCH v2 6/8] builtins/source: use source path in isolated mode, Koichi Murase, 2024/05/14
Re: [PATCH v2 6/8] builtins/source: use source path in isolated mode, Chet Ramey, 2024/05/15
Re: [PATCH v2 6/8] builtins/source: use source path in isolated mode, Koichi Murase, 2024/05/15
[PATCH v2 7/8] variables: define default BASH_SOURCE_PATH, Matheus Afonso Martins Moreira, 2024/05/13