help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Avoid sourcing bashrc when connected to sockets


From: Andrew Gregory
Subject: Re: Avoid sourcing bashrc when connected to sockets
Date: Mon, 21 Feb 2022 10:31:21 -0800

On 02/14/22 at 11:11am, Chet Ramey wrote:
> On 2/13/22 2:55 PM, Andrew Gregory wrote:
> > The pacman package manager runs install scripts by forking and invoking a
> > compile-time configured shell by calling "<shell> -c '. <path-to-script>;
> > <operation> <args>'", e.g. "bash -c '. /tmp/.INSTALL; pre_install pacman'". 
> >  A
> > while back we switched from using pipes to sockets to communicate with the 
> > fork
> > in order to avoid SIGPIPE problems.  Unfortunately, this makes bash think 
> > it's
> > being run under rsh/ssh and it now reads ~/.bashrc, which can break scripts.
> > Can the rsh/ssh check be modified to ignore this case?
> 
> How do you tell "this case" from others?
 
No idea, but I'm only passingly familiar with the original intent of this
behavior.

> You could start bash with the SHLVL environment variable set to something
> greater than 2. That will inhibit sourcing bashrc even if bash thinks it
> was run by ssh or stdin is a socket. Make sure to unset BASH_ENV as well.

I had considered this, but wasn't sure how reliable manipulating SHLVL would
be.  If that's going to be reliable behavior going forward though, that's
probably the easiest option.

> You might also want to tell your vendor about this, since they built bash
> with the non-standard option that enables this behavior.

Can you explain this?  Looking at the package build script[1] and the bash
source, nothing stands out to me as specifically enabling this behavior.

[1]: 
https://github.com/archlinux/svntogit-packages/blob/packages/bash/trunk/PKGBUILD

Thanks,
apg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]