From f1e8e9da00ccf91c924cd3edad0fc01d1b2dc820 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 29 May 2016 22:09:51 +0200 Subject: try to detect sudo spawned root-shell in prefixing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is a try as the we need to inspect SUDO_COMMAND which could be anything – apt, apt-get, in /usr/bin, in a $DPKG_ROOT "chroot", build from source, aliases, … The best we can do is look if the SHELL variable is equal to the SUDO_COMMAND which would mean a shell was invoked. That isn't fail-safe if different shells are involved as sub-shells have the tendency of not overriding the SHELL so a bash started from within zsh can happily pretend to be still zsh, so we could have a look at /etc/shells for a list, but oh well, we have to stop somewhere I guess. This sudo-prefixing feature is a gimmick after all. Closes: 825742 --- apt-private/private-install.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 7bd9a6034..63e7b734d 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -521,8 +521,13 @@ bool DoAutomaticRemove(CacheFile &Cache) ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n", "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount); std::string autocmd = "apt autoremove"; - if (getenv("SUDO_USER") != NULL) - autocmd = "sudo " + autocmd; + if (getenv("SUDO_USER") != nullptr) + { + auto const envsudocmd = getenv("SUDO_COMMAND"); + auto const envshell = getenv("SHELL"); + if (envsudocmd == nullptr || envshell == nullptr || strcmp(envsudocmd, envshell) != 0) + autocmd = "sudo " + autocmd; + } ioprintf(c1out, P_("Use '%s' to remove it.", "Use '%s' to remove them.", autoRemoveCount), autocmd.c_str()); c1out << std::endl; } -- cgit v1.2.3