On Sat, Jun 8, 2024 at 9:38 PM Martin D Kealey <mar...@kurahaupo.gen.nz> wrote:
>
>
> On Wed, 10 Apr 2024 at 03:58, Carl Edquist <edqu...@cs.wisc.edu> wrote:
>>
>> Note the coproc shell only does this with pipes; it leaves other user
>> managed fds like files or directories alone.
>>
>> I have no idea why that's the case, and i wonder whether it's intentional
>> or an oversight.
>
>
> Simply closing all pipes is definitely a bug.
>
> This is starting to feel like we really need explicit ways to control 
> attributes on filedescriptors.
>
> It should be possible to arrange so that any new subshell will keep 
> "emphemal" filedescriptors until just before invoking a command.
>
> One mechanism would be to add two new per-fd attributes: inherited-by-fork, 
> and ephemeral.
>
> The inherited-by-fork attribute would be set on any fd that's carried through 
> a fork (especially the implicit fork to create a pipeline) and reset on any 
> fd that's the result of a redirection.
>
> The emphemal attribute is set on any coproc fd (or at least, any that's a 
> pipe to the stdin of a coproc).
>
> Then when both attributes are set on an fd, it would be closed just before 
> launching any inner command, after any redirections have been done.That way 
> we could simply turn off the close-after-fork attribute on a coproc fd if 
> that's desired, but otherwise avoid deadlocks in the simple cases.

I think this sort of mirrors or extends my nosub builtin idea[1],
which didn't make it into Chet's folder of ideas[2].

Has an example loadable command[3] ever graduated to being a bash
builtin? 'asort' and 'csv' sound very helpful, but building a loadable
builtin is going to be a hurdle for a lot of people, and not all
systems support dynamic loading.

For 'fdflags' to become a builtin, some things that bash does behind
the scenes would have to change.[4] I assume the coproc fd behavior of
being closed after most forks is not handled through a system fd flag,
though if there is a system fd flag that would cause an fd to
automatically be closed in any forked child process, that would
simplify also closing coproc fds in process substitutions. Heck, bash
could use its own internal fork() function that calls the system
fork() function and then also closes all coproc fds if it finds itself
in the child process. And then just call that from anywhere that calls
the system fork() now.

Point being, maybe the solution would be an extended fdflags builtin
that takes additional arguments not corresponding to system fd flags
but used to toggle bash's behavior with respect to fds.

[1]: https://lists.gnu.org/archive/html/bug-bash/2024-04/msg00087.html
[2]: https://lists.gnu.org/archive/html/bug-bash/2024-05/msg00371.html
[3]: https://git.savannah.gnu.org/cgit/bash.git/tree/examples/loadables
[4]: https://lists.gnu.org/archive/html/bug-bash/2024-02/msg00194.html

            • ... Zachary Santer
            • ... Chet Ramey
            • ... Carl Edquist via Bug reports for the GNU Bourne Again SHell
            • ... Chet Ramey
            • ... Carl Edquist
            • ... Chet Ramey
            • ... Carl Edquist
            • ... Chet Ramey
            • ... Robert Elz
            • ... Martin D Kealey
            • ... Zachary Santer
            • ... Robert Elz
            • ... Zachary Santer
      • Re: E... Chet Ramey
        • R... Carl Edquist via Bug reports for the GNU Bourne Again SHell
          • ... Chet Ramey
            • ... Carl Edquist
            • ... Chet Ramey
  • Re: Examples o... Chet Ramey

Reply via email to