[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/8] builtins/source: parse the -i option
From: |
Matheus Afonso Martins Moreira |
Subject: |
[PATCH v2 5/8] builtins/source: parse the -i option |
Date: |
Mon, 13 May 2024 07:37:23 -0300 |
Passing the -i option to the source builtin
enables isolated sourcing mode which restricts
its search path to the directories defined by
the BASH_SOURCE_PATH variable. This also has
the added benefit of not touching PATH at all.
To maximize compatibility, the option will only
be recognized outside POSIXly correct mode.
Signed-off-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
---
builtins/source.def | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/builtins/source.def b/builtins/source.def
index ba5e1596..26040e70 100644
--- a/builtins/source.def
+++ b/builtins/source.def
@@ -182,10 +182,34 @@ int
source_builtin (WORD_LIST *list)
{
char *filename, *x;
+ int opt, isolated_mode = 0;
- if (no_options (list))
- return (EX_USAGE);
- list = loptend;
+ if (posixly_correct)
+ {
+ /* Don't parse options in POSIX mode */
+ if (no_options (list))
+ return (EX_USAGE);
+ }
+ else
+ {
+ reset_internal_getopt ();
+
+ while ((opt = internal_getopt (list, "i")) != -1)
+ {
+ switch (opt)
+ {
+ case 'i':
+ isolated_mode = 1;
+ break;
+ CASE_HELPOPT;
+ default:
+ builtin_usage ();
+ return (EX_USAGE);
+ }
+ }
+
+ list = loptend;
+ }
if (list == 0)
{
--
2.44.0
- Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions, (continued)
- Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions, Chet Ramey, 2024/05/15
- Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions, Chet Ramey, 2024/05/14
- Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions, Chet Ramey, 2024/05/14
- Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions, Matheus Afonso Martins Moreira, 2024/05/14
- Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions, Matheus Afonso Martins Moreira, 2024/05/14
- Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions, Chet Ramey, 2024/05/15
[PATCH v2 2/8] findcmd: define find_in_path_var function, Matheus Afonso Martins Moreira, 2024/05/13
[PATCH v2 3/8] builtins/source: extract file executor function, Matheus Afonso Martins Moreira, 2024/05/13
[PATCH v2 4/8] builtins/source: refactor file searching function, Matheus Afonso Martins Moreira, 2024/05/13
[PATCH v2 5/8] builtins/source: parse the -i option,
Matheus Afonso Martins Moreira <=
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Chet Ramey, 2024/05/14
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Greg Wooledge, 2024/05/14
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Lawrence Velázquez, 2024/05/14
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Koichi Murase, 2024/05/14
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Koichi Murase, 2024/05/14
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Chet Ramey, 2024/05/15
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Koichi Murase, 2024/05/15
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Chet Ramey, 2024/05/16
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Greg Wooledge, 2024/05/16
- Re: [PATCH v2 5/8] builtins/source: parse the -i option, Koichi Murase, 2024/05/20