Sunday, July 2, 2017

Killing (zapping) X

Killing (or zapping) the X server used to be easy, by simply pressing the "magic" key combination of Ctrl+Alt+Backspace. But that doesn't seem work anymore in my Solaris 11 GNOME Desktop. In fact, strictly speaking, the X default is like this. Killing the X server with such key combination is not supposed to be globally active by default. But traditionally it's been always possible to ("easily") override this and that's a convenient setting, excepting it would affect all users.

After being frustrated for a while, looking for a bunch legacy X information on how to re-enable the option for killing X via the Ctrl+Alt+Backspace key sequence I finally found how, but accidentaly, though! It's "hidden", as to say, in the GNOME Desktop keyboard settings, more precisely at System | Preferences | Keyboard dialog shown below:


By clicking at Options a secondary dialog pops-up and then it is just a matter of finding and marking the appropriate option checkbox as shown below:


This setup is much easier than the more traditional X environment hard way, but unfortunately it's not well documented, not even at the all mighty Destop Adminstrator's Guide. This cost me much time finding it my own way. Appart from that, the good news are that it will handle the operation on a per-user basis, which is certainly much better than traditional system-wide setting.

That's it!



As complementary information and discussion, I'll just add that the guidance offered at the Destop Adminstrator's Guide, that is, linking from 90-zap.conf in /etc/X11/xorg.conf.avail/ to /etc/X11/xorg.conf.d/ does not solve the issue as expected, probably because this solution not suited to a GNOME Desktop scenario as it probably is to a "plain" X scenario. This somewhat puzzeled me at first because I though for a moment that my xorg.conf file in /etc/X11/, which was automatically generated by nvidia-settings, could have some conflicting setting. I also thought about some possible conflict with Compiz but I quickly discarded it by testing without it on a separate virtual machine.

I have to say that by looking at the X legacy information I've got to the setxkbmap command which provided a partially successful, imperfect, solution as its effect wasn't surviving across reboots. By opening a terminal and issuing the following sequence, for that session only, I was able to kill X:

$ setxkbmap -option "terminate:ctrl_alt_bksp"
$ setxkbmap -query
rules:      base
model:      dellusbmm
layout:     br,br,us
variant:    nodeadkeys,,
options:    terminate:ctrl_alt_bksp,grp:shifts_toggle

 
The above partial solution opened up perspectives on enabling this setting on a per-user basis, a much more convenient approach. So I started thinking on somehow hooking this statement to one of the usual start-up scripts, such as .profile or .bashrc. I quickly realized that the setxkbmap command only worked under an already established X session, which existence I immediately associated to the DISPLAY environment variable being set to scripts, but that's so only to .bashrc which is the interactive and implies a parent session. So I've tried adjust things as follows:

$ tail .bashrc
...
 
if ! [[ ${DISPLAY-NO_X} = NO_X ]] ;
then
  if [[ -z $(setxkbmap -query |grep ctrl_alt_bksp) ]] ; 
  then
    # Just need to be set by the first interactive shell
    setxkbmap -option "terminate:ctrl_alt_bksp" 
  fi
fi
...

 
But unfortunately that's not a solution either because .bashrc isn't automatically run upon login. That was a dead-end: i) .profile ran at login but had no DISPLAY set; ii) .bashrc had DISPLAY set but didn't run a login! Perfect! :-( Finally I understood that the problem was sitting between these two contexts was the gnome-session, which is the one that connects to X and sets DISPLAY, and which is invoked by login. Of course, all later regular GNOME Desktop terminal sessions are children of gnome-session and that explains my initial perception of problem and shows that there's no solution independent of GNOME as well. That's where the GNOME startup files get in the scene: if a script has to be run upon a gnome-session launch they must be invoked as GNOME Startup Applications, which adheres to the Desktop Application Startup Specification.

If the options above aren't satisfactory the only alternatives that seem to work safely and relatively close to them are:
  1. Perform: # svcadm restart gdm
    (essentially a # kill -TERM `cat /var/run/gdm.pid`)
       
    or
     
  2. Try manually killing X from outside a gnome-session:
    If possible, preferably switch to a virtual console (vtn).
    (press a Ctrl+Alt+Fn keys combination, where 2 ≤ n ≤ 6)
    As root, execute: # pkill X
    Wait of try forcing switch back to the graphics mode.
    (press Ctrl+Alt+F7 keys combination)
NOTE
These work-arounds are not as convenient as the zap key combination because they require even more interactions.

By the way, under VirtualBox the virtual console keys combination seems to be Hostkey+Fn. But curiously you may have to "shake it" one time or so, that is, press Hostkey+F2, Hostkey+F7 and Hostkey+F2, until you see the vt2 virtual console prompt.