SHLVL=2 in outermost shell in unity terminals (REGRESSION)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
unity (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
The bash variable SHLVL is 2, rather than 1, in the outermost shell process in terminal emulators (gnome-terminal, xterm, etc. -- it doesn't matter). This makes SHLVL useless, and breaks many scripts (run from .bashrc etc.) which look for SHLVL=1 to save/restore state of some kind.
This is a painful REGRESSION since 16.04.
SHLVL=1 in pty terminals (Ctrl-Alt-F1 etc.) so the problem is not in bash.
The parent of the "outer most" shell (which has SHLVL=2) is not another bash instance,
but the terminal emulator (gnome-
Since the problem exists with various terminal emulators, the bug must be in generic gui initialization or gui-app startup code (not in gnome-terminal or xterm).
=> Speculation: Somewhere in the initial GUI startup code there is a script executed by bash which starts long-running processes (systemd?) and then exits. SHLVL=1 is inherited in the environment by the child, and so any shell the child later spawns set SHLVL=2. If that's the case, then it might suffice to "unset SHLVL" before starting the child(ren). Again, this is just speculation.
ProblemType: Bug
DistroRelease: Ubuntu 17.04
Package: unity 7.5.0+17.
ProcVersionSign
Uname: Linux 4.10.0-28-generic x86_64
NonfreeKernelMo
.proc.driver.
.proc.driver.
.proc.driver.
NVRM version: NVIDIA UNIX x86_64 Kernel Module 375.66 Mon May 1 15:29:16 PDT 2017
GCC version: gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2)
.proc.driver.
Your system is not currently configured to drive a VGA console
on the primary VGA device. The NVIDIA Linux graphics driver
requires the use of a text-mode VGA console. Use of other console
drivers including, but not limited to, vesafb, may result in
corruption and stability problems, and is not supported.
.tmp.unity_
ApportVersion: 2.20.4-0ubuntu4.5
Architecture: amd64
BootLog: WDStockRoot: clean, 408304/4890624 files, 6257387/19531008 blocks
CompizPlugins: No value set for `/apps/
CompositorRunning: compiz
CompositorUnred
CompositorUnred
CurrentDesktop: Unity:Unity7
Date: Tue Aug 1 10:07:13 2017
DistUpgraded: 2017-07-26 09:01:41,817 DEBUG Running PostInstallScript: './xorg_
DistroCodename: zesty
DistroVariant: ubuntu
DkmsStatus:
bbswitch, 0.8, 4.10.0-28-generic, x86_64: installed
bbswitch, 0.8, 4.4.0-87-generic, x86_64: installed
nvidia-375, 375.66, 4.10.0-28-generic, x86_64: installed
DpkgLog:
GconfCompiz:
/apps/
/apps/
/apps/
/apps/
top_
GraphicsCard:
NVIDIA Corporation GK208 [GeForce GT 630 Rev. 2] [10de:1284] (rev a1) (prog-if 00 [VGA controller])
Subsystem: ZOTAC International (MCO) Ltd. GK208 [GeForce GT 630 Rev. 2] [19da:1308]
InstallationDate: Installed on 2017-01-19 (194 days ago)
InstallationMedia: Ubuntu 16.04.1 LTS "Xenial Xerus" - Release amd64 (20160719)
MachineType: System manufacturer System Product Name
ProcKernelCmdLine: BOOT_IMAGE=
SourcePackage: unity
UpgradeStatus: Upgraded to zesty on 2017-07-26 (6 days ago)
dmi.bios.date: 09/21/2010
dmi.bios.vendor: American Megatrends Inc.
dmi.bios.version: 1408
dmi.board.
dmi.board.name: P6T
dmi.board.vendor: ASUSTeK Computer INC.
dmi.board.version: Rev 1.xx
dmi.chassis.
dmi.chassis.type: 3
dmi.chassis.vendor: Chassis Manufacture
dmi.chassis.
dmi.modalias: dmi:bvnAmerican
dmi.product.name: System Product Name
dmi.product.
dmi.sys.vendor: System manufacturer
version.compiz: compiz 1:0.9.13.
version.ia32-libs: ia32-libs N/A
version.libdrm2: libdrm2 2.4.76-1
version.
version.
version.
version.
version.
version.
version.
version.
version.
xserver.bootTime: Tue Aug 1 09:56:34 2017
xserver.configfile: default
xserver.devices:
input Power Button KEYBOARD, id 6
input Power Button KEYBOARD, id 7
input Heng Yu Technology Deck 87 Francium Pro KEYBOARD, id 8
input Heng Yu Technology Deck 87 Francium Pro KEYBOARD, id 9
input ImPS/2 Generic Wheel Mouse MOUSE, id 10
xserver.errors:
xserver.logfile: /var/log/Xorg.0.log
xserver.outputs:
xserver.version: 2:1.19.3-1ubuntu1.1
I hope this bug will be fixed before the next release. But meanwhile, here is a nasty workaround which can be used in bash startup scripts:
i_am_toplevel() { server| ^xterm) ' /proc/$PPID/cmdline ; then
case "$SHLVL" in
1) return 0 ;;
3) return 1 ;; # (optimize this case)
2) # HACK FOR Ubuntu 16.10, 17.04 ... where SHLVL=2 at top
if egrep -s '(terminal-
return 0
fi
;;
esac
return 1
}
Then say "if i_am_toplevel ; then ... "
instead of "if [ $SHLVL -eq 1 ] ..."