This thread has inspired me to move my desktop setup under s6 this weekend. 
Here's what I got:

General flow: boot to tty1 -> login -> bash starts bashrc -> bashrc sets 
DISPLAY and TTY env vars then exec into s6-svscan -> s6-svscan starts xserver, 
window manager, and other desktop services.

Reading Samuel's reply, I find the easiest way to get around the controlling 
terminal issue is to give Xorg capability: `setcap cap_sys_tty_config=+eip 
/usr/lib/Xorg`. (Considering Chromium has cap_sys_admin, letting Xorg control 
ttys doesn't seem that bad). Setting the owner of tty doesn't quite work in my 
case because of the login shell is attached to tty1 already.

In my bashrc, I have some logic to check whether X should be started. 
Eventually, it runs this code:

exec execlineb /dev/stdin << EOF
s6-setsid -q
piperw 4 3
background {
  fdclose 3 fdmove 0 4
  foreground { redirfd -w 1 /dev/null cat }
  foreground { s6-rc-init -l "$S6/live" -c "$S6/compiled" "$S6/service" }
  s6-rc -l "$S6/live" -up change "$1"
}

fdclose 4
s6-svscan -d 3 "$S6/service"
EOF

And I have $HOME/.service/xserver-srv/run that replaces startx/sx:

#!/usr/bin/execlineb -P
fdmove -c 2 1

importas DISPLAY DISPLAY
importas TTY TTY

if { test -r /dev/dri/card0 }
if { test -n "${DISPLAY}" }

backtick -E cookie { xxd -l 16 -ps /dev/urandom }
foreground { xauth add "${DISPLAY}" MIT-MAGIC-COOKIE-1 "${cookie}" }

Xorg "${DISPLAY}" -displayfd 3 "vt${TTY}"

With a finish file:

#!/usr/bin/execlineb -P
if { test -n "$DISPLAY" }
xauth remove "$DISPLAY"

The window manager, pulseaudio server, and a few other services are started 
together as well, using s6-rc to depend on xserver.

This is what I ended up with:

s6-supervise agetty-tty1
 \_ login -- rio
     \_ s6-svscan -d 3 /tmp/rio/s6/1/service
         \_ s6-supervise xss-lock
         |   \_ xss-lock -- s6-svc -1 /run/service/locker
         \_ s6-supervise xserver-srv
         |   \_ /usr/lib/Xorg :1 -displayfd 3 vt1
         \_ s6-supervise xserver-log
         |   \_ s6-log -- n4 T /tmp/rio/s6/1/log/xserver
         \_ s6-supervise xbanish
         |   \_ xbanish -i mod1 -i mod4 -i control
         \_ s6-supervise syndaemon
         |   \_ syndaemon -tki 0.2
         \_ s6-supervise pulseaudio-srv
         |   \_ pulseaudio --exit-idle-time=-1 --daemonize=no
         |       \_ /usr/lib/pulse/gsettings-helper
         \_ s6-supervise pulseaudio-log
         |   \_ s6-log -- -system_bus_socket T /tmp/rio/s6/1/log/pulseaudio
         \_ s6-supervise gcin
         |   \_ gcin
         \_ s6-supervise awesome
         |   \_ awesome --no-argb
         \_ s6-supervise s6rc-fdholder
         |   \_ s6-fdholderd -1 -i data/rules
         \_ s6-supervise s6rc-oneshot-runner

Now there are probably issues here and there, as I just got it running. 
Suggestions welcome.

Rio

Reply via email to