
if grep -qs ^allow-user-xsession "$OPTIONFILE"; then
  for STARTUPFILE in "$STARTUP" "$ALTSTARTUP"; do
    if [ -e "$STARTUPFILE" ]; then
      if [ -x "$STARTUPFILE" ]; then
        REALSTARTUP=$STARTUPFILE
      else
        REALSTARTUP="sh $STARTUPFILE"
      fi
      break
    fi
  done
fi

if [ -z "$REALSTARTUP" ]; then
  if [ -x /usr/bin/x-session-manager ]; then
    REALSTARTUP=x-session-manager
  elif [ -x /usr/bin/x-window-manager ]; then
    REALSTARTUP=x-window-manager
  elif [ -x /usr/bin/x-terminal-emulator ]; then
    REALSTARTUP=x-terminal-emulator
  fi
fi

if [ -z "$REALSTARTUP" ]; then
  # fatal error
  ERRMSG="Xsession: unable to start X session; "
  if grep -qs ^allow-user-xsession "$OPTIONFILE"; then
    ERRMSG="$ERRMSG no $STARTUP file, no $ALTSTARTUP file,"
  fi
  errormsg "$ERRMSG no session managers, no window managers, and no terminal" \
           "emulators found.  Aborting."
fi
