0

I use the terminal to do the majority of my day-to-day computing, so I have the default runlevel set to 3 in /etc/inittab and I only start the X server when I need to. I currently have the following in my xorg.conf in order to make quickly switching to the terminal easier:

Section "ServerFlags"
    Option            "DontZap"    "false"
EndSection

Section "InputClass"
    Identifier        "Keyboard Defaults"
    MatchIsKeyboard   "yes"
    Option            "XkbOptions" "terminate:ctrl_alt_bksp"
EndSection

I know this is messy and fraught with security problems, which is why these settings were removed from the default install in the first place. However, it's fast. How can I get this kind of functionality in a safer way using a shell script or something similar that can be attached to an event such as a key combination or to closing the screen of a laptop?

What I am after is an immediate killing of the X server process with no output to tty (currently, Ctrl + Alt + Bksp fills the terminal with the output from the dying X server, which I have to exit with Ctrl + C).

  • 1
    What about invoking it from a screen/tmux session and doing the killing there? – slm May 24 '14 at 14:39
  • Or background it with &. Wouldn't that accomplish the same thing? – Jonathan Landrum May 27 '14 at 12:59
0

Solution That I Have Settled With

This issue still plagues me somewhat, but I have mashed together a multi-pronged solution that gets very close to what the original question was seeking, to the point that I am marking this issue "resolved".

1.) Remove the xorg.conf changes

These changes to xorg.conf from the OP can be removed, as the functionality will be replicated in another way:

Section "ServerFlags"
    Option            "DontZap"    "false"
EndSection

Section "InputClass"
    Identifier        "Keyboard Defaults"
    MatchIsKeyboard   "yes"
    Option            "XkbOptions" "terminate:ctrl_alt_bksp"
EndSection

2.) Edit .xinitrc

Most guides to using .xinitrc suggest adding a line such as this one to start your desktop of choice when Xorg starts:

exec cinnamon-session;

However, in an .xinitrc file, anything after an exec statement gets ignored. So alter it to just call the desktop without the exec:

cinnamon-session;

Then add a clear on the line below it, so that when the desktop session ends, it clears the screen:

cinnamon-session;
clear;

Because of the time taken to end the session, there may still be a couple of lines remaining from ending the session (and this is what I mean when I say this issue still plagues me somewhat; I haven't figured out how to solve this part completely).

3.) Create a shell script to end the session

I mentioned in step 1 that the Xorg zapping functionality will be replicated in another way, and that happens here. This particular example is unique to Cinnamon, but there may be a similar command for your desktop. Make a shell script with the following two lines:

#!/usr/bin/env bash
cinnamon-session-quit --logout --force --no-prompt;

Make the script executable with chmod +x quit-x.sh (or whatever you've named it.) The reason I had to make a tiny shell script to pull this off is because I had issues mapping a key combination to a command with options, but mapping it to a script was a snap (see step 4).

4.) Map the script to a key combination

This is also highly desktop specific. The settings for this in Cinnamon are located in the System Settings application, under Keyboard > Shortcuts > Custom Shortcuts. Click "Add custom shortcut", give it a name ("Quit X", for example), give it a shortcut (I chose Alt-T), and point it at your custom script. Now dropping to a terminal is a snap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.