Re: s6 xinit replacement?

From: Samuel Holland <samuel_at_sholland.org>
Date: Sat, 14 May 2022 21:44:43 -0500

On 5/13/22 10:47 PM, Guillermo wrote:
> Hello,
>
> El mié, 11 may 2022 a las 0:43, dallinjdahl escribió:
>>
>> I tried to run X under s6 with the following run file:
>>
>> ~~~
>> #!/usr/bin/execlineb
>> [...]
>> X :${screen} vt${screen}
>> ~~~
>> [...]
>> (WW) xf86OpenConsole: VT_ACTIVATE failed: Operation not permitted
>> (EE)
>> Fatal server error:
>> (EE) xf86OpenConsole: Switching VT failed
>> [...]
>> Does anybody know anything about how s6-svscan and s6-supervise might
>> change the environment so as to complicate running X?
>
> If the Xorg process does not run as root, the tty specified in the vt
> argument must be its controlling terminal.

Yes, this is effectively the requirement. You can override it with a capability,
but doing so is not necessary (see below). Here is the relevant kernel source
for reference:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/tty/vt/vt_ioctl.c?h=v5.17#n744

> It works if you run X from
> an interactive shell (perhaps indirectly through 'startx'), because it
> inherits the shell's controlling terminal. It doesn't when run by
> s6-supervise, because s6-supervise executes the 'run' file in a new
> session, so there is no controlling terminal.

It also works if X has permission to open the tty device read/write. Opening a
tty as a session leader without a controlling terminal will set the controlling
terminal to that tty. Relevant kernel code:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/tty/tty_jobctrl.c?h=v5.17#n129

And X will try to do that at startup (after failing to play with process groups
because it is already group leader):

https://gitlab.freedesktop.org/xorg/xserver/-/blob/master/hw/xfree86/os-support/linux/lnx_init.c#L207

I use a udev rule to set the tty owner:

$ cat /etc/udev/rules.d/99-tty.rules
SUBSYSTEM=="tty", KERNEL=="tty1", OWNER="samuel", GROUP="samuel", MODE="0600"

And everything Just Works.

I am fine with hard coding the tty number because my systems are single-user. X
is started at boot from my user supervision tree[1], which is started by the
user-* services in my system supervision tree[2].

[1]: https://github.com/smaeul/rc-user
[2]: https://github.com/smaeul/rc

You could also set the tty permissions at login. Another option is to avoid the
privileged IOCTLs by using the "-novtswitch" or "-sharevts" option. These set
flags which affect the logic in the other file:

https://gitlab.freedesktop.org/xorg/xserver/-/blob/master/hw/xfree86/common/xf86Init.c#L1168

Hope that helps,
Samuel
Received on Sun May 15 2022 - 04:44:43 CEST

This archive was generated by hypermail 2.4.0 : Sun May 15 2022 - 04:45:17 CEST