#!/bin/sh # Start the X session once per boot, through poky's xserver-nodm chain: # /etc/xserver-nodm/Xserver -> xinit -> /etc/X11/Xsession -> x-session-manager. # Run from /etc/inittab under busybox init, or from /.bashrc when bash is PID 1. # The opt-out xserver-nodm's own init script honours. for x in $(cat /proc/cmdline); do [ "$x" = "x11=false" ] && exit 0 done # Once per boot. /tmp is a tmpfs, so the stamp goes with a reboot; set -C makes # the create atomic, so two callers cannot both start a server. (set -C; : > /tmp/.brintos-x11-started) 2>/dev/null || exit 0 # Xorg will not start without its log file, and /var/log points into # /var/volatile, which nothing on this image mounts yet (BRINTOS-2993 owns the # volatiles). Once something does, this block does nothing. if [ ! -d /var/log/ ]; then mount -t tmpfs -o mode=0755,nodev,nosuid tmpfs /var/volatile && mkdir -p /var/volatile/log /var/volatile/tmp fi LOG=/var/log/xserver-nodm.log [ -d /var/log/ ] || LOG=/tmp/xserver-nodm.log # The server's own log, named as Xorg names it for the display. An older one is # moved aside, as Xorg itself does, so a log found afterwards is this server's. d=$(for f in /etc/default/xserver-nodm /etc/X11/xserver-common; do [ -r $f ] && . $f; done; echo "${DISPLAY:-:0}") d=${d#*:} XLOG=/var/log/Xorg.${d%%.*}.log [ -e "$XLOG" ] && mv -f "$XLOG" "$XLOG.old" /etc/xserver-nodm/Xserver >"$LOG" 2>&1 rc=$? # Nothing in the chain writes to the console, so a failed server leaves only a # black screen. Say it there, in one line. xinit names how the server ended; # a server killed by a signal leaves no line in its own log. end=$(tr -d '\r' < "$LOG" | sed -n -E 's/^.*xinit: X server ((killed by signal|exited with status) .*)$/\1/p' | tail -n 1) [ "$rc" -ne 0 ] || [ -n "$end" ] || exit 0 if [ -s "$XLOG" ]; then xorg="last line of $XLOG: $(grep -v '^[[:space:]]*$' "$XLOG" | tail -n 1 | tr -d '\r' | cut -c 1-200)" else xorg="$XLOG not written" fi echo "brintos-x11-start: X server failed: xinit exit status $rc${end:+, server $end}; $xorg; xinit's log: $LOG" >&2 exit "$rc"