Install scriptlets source root users .bashrc when pacman is run through sudo

Andrew Gregory andrew.gregory.8 at gmail.com
Sun Nov 14 22:27:18 UTC 2021


On 11/06/21 at 10:43pm, brainpower wrote:
> Am 06.11.21 um 21:34 schrieb Andrew Gregory:
> > On 11/06/21 at 09:08pm, brainpower wrote:
> > > Am 06.11.21 um 19:15 schrieb Andrew Gregory:
> > > > bash thinks it's being run remotely because we connect to the child over
> > > > sockets.
> > > 
> > > oh, right, that makes sense... I knew I was missing something rather obvious. :/
> > > (I shouldn't have just skimmed the manpage after all... I missed it b/c I
> > > was only looking for the word "interactive", which isn't in that
> > > paragraph)
> > > 
> > > 
> > > But what I'm still not quite getting is,
> > > what's the difference of pacman being run by sudo vs. directly?
> > > Shouldn't bash also think the sockets were remote if pacman is not run using sudo?
> > > 
> > > But it probably can detect somehow that it runs inside a interactive zsh when pacman is run directly,
> > > while there is no shell running between sudo and pacman when running it using sudo...
> > > or something like that.
> > > 
> > > Well mystery somewhat solved, thanks for pointing me in the right direction.
> > 
> > I'd guess it's because it also checks for $SHLVL < 2.
> > 
> 
> It does!
> I've checked by adding 'Defaults env_keep += "SHLVL"' to /etc/sudoers.
> 
> Would it make sense to export/set SHLVL=1 in _alpm_run_chroot() if SHLVL does
> not exist before executing the shell to make sure its non-interactive?
> 
> I've first thought of adding --norc, but I think that's a non standard option
> not all shells users may configure pacman to use support...  Exporting that
> variable if it does not exist should work with every shell and also should
> not hurt non-bash shells, I think?

The SHLVL check isn't documented anywhere that I can see, I just happened to
find it in bash's source, so it's not something we should rely on.  I'd reach
out to the bash developer first and see what they say.


More information about the pacman-dev mailing list