[Main]
Type = classic
Version = 0.1.6
Description = "lightdm daemon (no Depends on boot stub)"
User = ( root )
Depends = ( dbus devmanager logind x11-common mount-rw )
# Wait for live-config (autologin conf) when live-config-66 is present, and
# for seatd when installed. Without live-config here, lightdm can start before
# autologin-user is written even if the mount tree runs first.
# Note: 66 may fold OptsDepends into hard Depends — purging live-config-66
# can drop this service from the graph; that trade-off is required for live.
OptsDepends = ( live-config seatd )
Options = ( log )

[Start]
Execute = (
	# Do not use "exec -c" or "fdmove -c": that yields a restart loop
	# and the host shows "Display output is not active". LightDM's own
	# log (paths in lightdm.conf / /var/log/lightdm/) is enough; the s6
	# pipeline still captures stdout without merging stderr via fdmove -c.
	# Pause when another display manager is selected (OpenRC/runit pattern).

	ifelse {
		ifelse { test ! -s /etc/X11/default-display-manager } { true }
		redirfd -r 0 /etc/X11/default-display-manager
		grep -qx /usr/sbin/lightdm
	} {
		# logind Notify can race; wait until the bus name answers (dbus-send,
		# same probe as elogind's data/check — busctl is unreliable here).
		foreground {
			loopwhilex
			ifelse {
				redirfd -w 1 /dev/null
				redirfd -w 2 /dev/null
				dbus-send --system --dest=org.freedesktop.login1 --print-reply
					/org/freedesktop/login1 org.freedesktop.DBus.Peer.Ping
			}
			{ exit 1 }
			sleep 0.25
		}
		foreground { mkdir -p /var/lib/lightdm/data }
		foreground { chown lightdm:lightdm /var/lib/lightdm /var/lib/lightdm/data }
		exec /usr/sbin/lightdm
	}
	s6-pause
)

[Logger]
RunAs = s6log
Backup = 3
MaxSize = 2000000
Timestamp = tai
Destination = /var/log/lightdm
