jasonwryan.com

Miscellaneous ephemera…

Logging Straight Into X

image

I have been using CDM to log into X on my Arch machines and, if I were to continue to require the ability to access different window managers with any frequency, I would use this approach. However, on my EeePC, I really only ever login to a dwm session or the console, so having a login manager seemed like an unnecessary step.

Consequently, over the weekend, with the help of the Start X at Boot article on the Arch Wiki, I removed CDM and arrived at a secure, flexible approach to logging into X (or the console).

My /etc/inittab already boots me into runlevel 5:

1
2
# Boot to X11
id:5:initdefault:

So it was just a case of putting a couple of lines in the correct invocation file. I chose $HOME/.bash_profile because I only use Bash; if you use another shell you should probably go with $HOME/.profile. The recommended lines from the Arch Wiki are:

1
2
3
4
5
if [[ -z $DISPLAY && $(tty) = /dev/tty1 ]]; then
  exec startx
  # Could use xinit instead of startx
  #exec xinit -- /usr/bin/X -nolisten tcp vt7
fi

…and this works as advertised. If you are in TTY1 and you login, X is started. The disadvantage for me, though, was that when you shutdown, you must manually change to TTY7 (if that is your last agetty) to see the shutdown messages.

After rummaging around through various man and web pages, I finally alighted on this helpful option: -novtswitch. So, my entry to start X now looked like:

1
2
3
4
5
# startx if on tty1
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
    exec xinit -- :0 -novtswitch &>/dev/null &
    logout
fi

Now, on shutdown and reboot, I see all of the shutdown messages. All that remained was to add an option to log into a tmux session if I didn’t want to use X. The final code looks like this:

~/.profile
1
2
3
4
5
6
7
# startx if on tty1 and tmux on tty2
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
    exec xinit -- :0 -novtswitch &>/dev/null &
    logout
elif [[ $(tty) = /dev/tty2 ]]; then
    tmux -f $HOME/.tmux/conf new -s secured
fi

Logging in from TTY1 takes me into my dwm session, if I switch to TTY2 I am logged into a tmux session with keychain running. To start consolekit with dwm, I have this in my $HOME/.xinitrc:

1
exec ck-launch-session $HOME/Scripts/dwm-start.

You can see my full $HOME/.bash_profile in my mercurial repo.

Updated 4/2/12

For various reasons, I moved my environment variables from $HOME/.bashrc into $HOME/.profile; this meant that these variables were only inherited in interactive shells if xinit was called with exec.

I have also ditched consolekit - for all of the processes it was spawning, it actually wasn’t performing any critical functions; or indeed any functions that I really needed at all…

Comments