#!/bin/sh # Start weston with Xwayland for X11 clients: on the browser's GL transport # (the glr backend, Weston's GL renderer drawing through WebGL2) when the host # grants it, otherwise on the KMS device with pixman. Exits 0 once the # compositor's socket is up and leaves it running; otherwise prints why, in one # line, and exits 1. brintos-session-start runs it. WESTON_SOCKET=wayland-0 WESTON_LOG=/var/log/weston.log WESTON_ARGS= WESTON_BACKEND=auto WAYLAND_TIMEOUT=180 [ -r /etc/default/brintos-session ] && . /etc/default/brintos-session [ -n "$BRINTOS_SESSION_CONF" ] && . "$BRINTOS_SESSION_CONF" # /var/log points into /var/volatile, as for the X session. if [ ! -d "${WESTON_LOG%/*}/" ]; then mount -t tmpfs -o mode=0755,nodev,nosuid tmpfs /var/volatile 2>/dev/null && mkdir -p /var/volatile/log /var/volatile/tmp [ -d "${WESTON_LOG%/*}/" ] || WESTON_LOG=/tmp/${WESTON_LOG##*/} fi uid=$(id -u) if [ -z "$XDG_RUNTIME_DIR" ]; then XDG_RUNTIME_DIR=/run/user/$uid mkdir -p "$XDG_RUNTIME_DIR" 2>/dev/null || XDG_RUNTIME_DIR=/tmp/runtime-$uid fi mkdir -p "$XDG_RUNTIME_DIR" && chmod 0700 "$XDG_RUNTIME_DIR" || { echo "cannot create XDG_RUNTIME_DIR $XDG_RUNTIME_DIR"; exit 1; } export XDG_RUNTIME_DIR # The kernel starts init with HOME=/ in /, and the session inherits both. The # clients weston starts want the user's: they inherit its working directory as # well as HOME, and a file manager started with no argument opens the former. pw=$(awk -F: -v u="$uid" '$3 == u { print $1 ":" $6; exit }' /etc/passwd) if [ -n "$pw" ]; then export USER="${pw%%:*}" LOGNAME="${pw%%:*}" if [ -z "$HOME" ] || [ "$HOME" = / ]; then h=${pw#*:} [ -n "$h" ] && [ -d "$h" ] && export HOME="$h" fi fi cd "${HOME:-/}" 2>/dev/null || cd / [ -S "$XDG_RUNTIME_DIR/$WESTON_SOCKET" ] && { echo "$XDG_RUNTIME_DIR/$WESTON_SOCKET already exists: a compositor is running"; exit 1; } mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix # GTK programs the session starts skip the accessibility bridge, as in the X # session: the bridge asks D-Bus to start at-spi-bus-launcher, which aborts. # BRINTOS-WORKAROUND: brintos/hardwarejs#62 remove -- a dynamically linked program is refused every thread, so the accessibility bus launcher cannot run export NO_AT_BRIDGE=1 # GTK programs the session starts (pcmanfm, l3afpad) and those started from its # terminals draw through Xwayland: a GTK3 client on Wayland can freeze the # guest. A program that asks for GDK_BACKEND=wayland itself still gets it. # BRINTOS-WORKAROUND: brintos/glibc#25 revisit -- GLib threads in a GTK3 Wayland client park in a raw FUTEX_WAIT and every guest-side writer stops export GDK_BACKEND=x11 # weston reads one file: the sessions is the base file plus every packages # fragment in weston.ini.d, in name order. set -- /etc/xdg/weston/weston.ini.d/*.ini if [ -e "$1" ]; then for f in /etc/xdg/weston/weston.ini "$@"; do cat "$f"; echo; done >"$XDG_RUNTIME_DIR/weston.ini" && WESTON_ARGS="--config=$XDG_RUNTIME_DIR/weston.ini $WESTON_ARGS" fi why() { l=$(grep -h -i -E 'fatal|fail|error|cannot|couldn' "$WESTON_LOG" "$WESTON_LOG.out" 2>/dev/null | grep -v '^[[:space:]]*$' | tail -n 1) [ -n "$l" ] || l=$(cat "$WESTON_LOG" "$WESTON_LOG.out" 2>/dev/null | grep -v '^[[:space:]]*$' | tail -n 1) printf '%s' "$l" | tr -d '\r' | cut -c 1-200 } # start BACKEND RENDERER: start weston and wait for its socket. 0 once it is # up; 1, with the reason on stdout, when weston exits or the time runs out. start() { # The status file, not kill -0: an exited child stays a zombie until # waited for, and kill -0 succeeds on a zombie. st=$XDG_RUNTIME_DIR/.weston-exit.$$ rm -f "$st" ( LIBSEAT_BACKEND=builtin weston --backend="$1" --renderer="$2" --shell=desktop \ --xwayland --socket="$WESTON_SOCKET" --idle-time=0 --log="$WESTON_LOG" \ $WESTON_ARGS "$WESTON_LOG.out" 2>&1 echo $? > "$st" ) /dev/null 2>&1 & read -r t0 _ < /proc/uptime t0=${t0%.*} while :; do [ -S "$XDG_RUNTIME_DIR/$WESTON_SOCKET" ] && return 0 if [ -s "$st" ]; then echo "weston ($1) exited with status $(cat "$st"): $(why); log: $WESTON_LOG" rm -f "$st" return 1 fi read -r t _ < /proc/uptime if [ $(( ${t%.*} - t0 )) -ge "$WAYLAND_TIMEOUT" ]; then echo "no compositor socket after ${WAYLAND_TIMEOUT}s ($1): $(why); log: $WESTON_LOG" return 1 fi sleep 1 done } # The GL transport exists only when the host grants it; the glr backend # refuses to start when its GL renderer cannot (eglInitialize fails), and the # DRM backend with pixman takes over. glr_why= case $WESTON_BACKEND in auto|glr) if [ -c /dev/hwjs-transport ]; then if out=$(start glr gl); then echo "weston on the GL transport (glr backend, GL renderer)" exit 0 fi glr_why="glr: $out; " mv -f "$WESTON_LOG" "$WESTON_LOG.glr" 2>/dev/null mv -f "$WESTON_LOG.out" "$WESTON_LOG.glr.out" 2>/dev/null else glr_why="no GL transport: /dev/hwjs-transport is absent; " fi [ "$WESTON_BACKEND" = glr ] && { echo "$glr_why" | sed 's/; $//'; exit 1; } ;; esac [ -c /dev/dri/card0 ] || { echo "${glr_why}no KMS device: /dev/dri/card0 is absent"; exit 1; } if out=$(start drm pixman); then echo "weston on the KMS device (drm backend, pixman)${glr_why:+; $glr_why}" | sed 's/; $//' exit 0 fi echo "${glr_why}$out" exit 1