Re: proposed BASH_SOURCE_PATH

2024-05-13 Thread Matheus Afonso Martins Moreira
Completely agree with your suggestions. I've proposed suggestion 3 as well in previous emails but consensus was not reached. -- Matheus

proposed BASH_SOURCE_PATH

2024-05-13 Thread Martin D Kealey
I wholeheartedly support the introduction of BASH_SOURCE_PATH, but I would like to suggest three tweaks to its semantics. A common pattern is to unpack a script with its associated library & config files into a new directory, which then leaves a problem locating the library files whose paths are o

Re: Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions

2024-05-13 Thread Matheus Afonso Martins Moreira
> The patches touch the interface of many functions I added one external function: find_in_path_var. The other changes are all static and local. > It seems essentially equivalent to just calling > find_in_path (list->word->word, path_value ("BASH_SOURCE_PATH", 1), > FS_READABLE); It is. I'm

Re: Re: [PATCH v2 6/8] builtins/source: use source path in isolated mode

2024-05-13 Thread Matheus Afonso Martins Moreira
> I think we should restrict the search in > BASH_SOURCE_PATH and shouldn't fall back to local files. I concur but thought it'd be wise to discuss it first so I left it in. Users might expect it to respect the configuration option. I also saw that many of the PATH-like variable defaults had the cu

Re: [PATCH v2 1/8] findcmd: parameterize path variable in functions

2024-05-13 Thread Koichi Murase
2024年5月13日(月) 19:38 Matheus Afonso Martins Moreira : > The PATH variable is hard coded in the user command finder function. > Transforming it into an argument allows reusing the file finding logic > with variables other than PATH, making the code more flexible. I think what was suggested by Chet i

Re: [PATCH v2 3/8] builtins/source: extract file executor function

2024-05-13 Thread Koichi Murase
2024年5月13日(月) 19:39 Matheus Afonso Martins Moreira : > Extract into a dedicated helper function the code which loads > the contents of a file and executes it in the current shell. > This separates this useful functionality from the path resolution > mechanism used by the source builtin. To other r

Re: [PATCH v2 6/8] builtins/source: use source path in isolated mode

2024-05-13 Thread Koichi Murase
2024年5月13日(月) 19:40 Matheus Afonso Martins Moreira : > diff --git a/builtins/source.def b/builtins/source.def > index 26040e70..7f870bfe 100644 > --- a/builtins/source.def > +++ b/builtins/source.def > @@ -177,6 +178,27 @@ search_for_file (WORD_LIST *list) > [...] > +static char * > +isolated_searc

Re: bug in bash

2024-05-13 Thread Oğuz
On Monday, May 13, 2024, Chet Ramey wrote: > performs the setpgid in the process forked > to run the process substitution). > Yes, this sounds like the easy way. I don't know how else to prevent the race in OP. Close stdin/stdout? Direct it from /dev/null? -- Oğuz

Re: bug in bash

2024-05-13 Thread Chet Ramey
On 5/12/24 10:00 AM, Oğuz wrote: On Sun, May 12, 2024 at 4:33 PM Andreas Schwab wrote: Since the redirection fails and the cat command is never started, bash doesn't switch the terminal process group It does on my computer: 554 ioctl(255, TIOCSPGRP, [554]) = 0 553 execve("/usr/bin/w

Changed behaviour of ${PARAMETER/#PATTERN/STRING} and ${PARAMETER/%PATTERN/STRING}

2024-05-13 Thread Andreas Schwab
In 5.3-alpha, it is no longer possible to quote the special % and # characters in a pattern replacement expansion. $ a=1/%2/%3 $ echo "${a/\%/##}" 1/%2/%3## $ echo "${a/\/%/##}" 1##2/%3 The second example shows that quoting still works as expected for ${PARAMETER//PATTERN/STRING}. -- Andreas Sc

[PATCH v2 7/8] variables: define default BASH_SOURCE_PATH

2024-05-13 Thread Matheus Afonso Martins Moreira
Define a build time configurable default value for the new BASH_SOURCE_PATH variable. Look for libraries in the user's home directory as well as the system wide directories. Signed-off-by: Matheus Afonso Martins Moreira --- config-top.h | 7 +++ variables.c | 1 + 2 files changed, 8 inserti

[PATCH v2 6/8] builtins/source: use source path in isolated mode

2024-05-13 Thread Matheus Afonso Martins Moreira
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 --- builtins/source.def | 27 ++- 1 file changed, 26 insertions(+), 1 delet

[PATCH v2 8/8] shell: restrict BASH_SOURCE_PATH when appropriate

2024-05-13 Thread Matheus Afonso Martins Moreira
Make the BASH_SOURCE_PATH variable read-only and unsettable when the shell is operating in restricted mode. This variable should be restricted for the same reasons why PATH is restricted. Signed-off-by: Matheus Afonso Martins Moreira --- shell.c | 1 + 1 file changed, 1 insertion(+) diff --git

[PATCH v2 4/8] builtins/source: refactor file searching function

2024-05-13 Thread Matheus Afonso Martins Moreira
Extract the file searching algorithm of the source builtin into a static helper function. Makes the code easier to understand and separates the searching from the error handling logic. Signed-off-by: Matheus Afonso Martins Moreira --- builtins/source.def | 59 +++-

[PATCH v2 5/8] builtins/source: parse the -i option

2024-05-13 Thread Matheus Afonso Martins Moreira
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

[PATCH v2 2/8] findcmd: define find_in_path_var function

2024-05-13 Thread Matheus Afonso Martins Moreira
It works just like the find_in_path function but takes a PATH-like variable name instead. This allows defining and using more PATH-like variables much more easily. Signed-off-by: Matheus Afonso Martins Moreira --- findcmd.c | 7 +++ findcmd.h | 1 + 2 files changed, 8 insertions(+) diff --g

[PATCH v2 3/8] builtins/source: extract file executor function

2024-05-13 Thread Matheus Afonso Martins Moreira
Extract into a dedicated helper function the code which loads the contents of a file and executes it in the current shell. This separates this useful functionality from the path resolution mechanism used by the source builtin. Signed-off-by: Matheus Afonso Martins Moreira --- builtins/source.def

[PATCH v2 1/8] findcmd: parameterize path variable in functions

2024-05-13 Thread Matheus Afonso Martins Moreira
The PATH variable is hard coded in the user command finder function. Transforming it into an argument allows reusing the file finding logic with variables other than PATH, making the code more flexible. Signed-off-by: Matheus Afonso Martins Moreira --- findcmd.c | 25 + 1

[PATCH v2 0/8] Add isolated mode to source builtin

2024-05-13 Thread Matheus Afonso Martins Moreira
Bash scripts can be tricky to get right so reusing proven solutions as shell script libraries is of immense value. However, the existing shell script sourcing mechanisms are suboptimal for this task. The source builtin uses the PATH variable for resolving file names which means they would have to