Xserver revision 1018
0N/A#!/bin/ksh93
0N/A#
0N/A#
0N/A# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
407N/A#
0N/A# Permission is hereby granted, free of charge, to any person obtaining a
0N/A# copy of this software and associated documentation files (the "Software"),
0N/A# to deal in the Software without restriction, including without limitation
0N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
0N/A# and/or sell copies of the Software, and to permit persons to whom the
0N/A# Software is furnished to do so, subject to the following conditions:
0N/A#
0N/A# The above copyright notice and this permission notice (including the next
0N/A# paragraph) shall be included in all copies or substantial portions of the
0N/A# Software.
0N/A#
0N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
816N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0N/A# DEALINGS IN THE SOFTWARE.
0N/A#
0N/A
392N/AUSAGE="Usage: $0 [-c <class>] :<display> [<X server arguments>]"
392N/A
392N/APATH=/usr/bin:/usr/sbin
392N/A
392N/Aprogname=$0
392N/Afunction fatal_error
392N/A{
392N/A print -u2 "${progname}: $*"
392N/A exit 1
392N/A}
459N/A
392N/A#########
392N/A#
392N/A# Default values
459N/A#
392N/A# Users must not modify this script to change them - change via SMF properties
392N/A#
392N/A
804N/ADISPLAY="0"
0N/ADEFDEPTH=""
0N/ACLASSES=""
0N/ATCP_LISTEN=""
0N/ASERVERARGS=""
0N/AXSERVER="/usr/bin/Xorg"
0N/ACONSOLE=""
804N/ACONFIG_FILE=""
0N/A
0N/A
804N/Awhile getopts :c: opt; do
804N/A case $opt in
0N/A c) CLASSES+=" :${OPTARG}" ;;
0N/A ?) print -u2 $USAGE ; exit 2;;
0N/A esac
804N/Adone
554N/A
554N/Ashift $((OPTIND - 1))
554N/A
554N/Aif (( $# > 1 )) ; then
202N/A case $1 in
804N/A :*)
804N/A # Strip leading ":" from $1 to get display number
804N/A DISPLAY="${1#:}"
0N/A shift
804N/A ;;
554N/A esac
889N/Afi
889N/A
889N/AREMOTE="false"
889N/Afor a in $SERVERARGS "$*" ; do
889N/A case $a in
889N/A -query|-broadcast|-multicast|-indirect)
889N/A REMOTE="true"
889N/A ;;
889N/A *)
889N/A # Do nothing
889N/A ;;
459N/A esac
816N/Adone
459N/A
889N/Aif [[ "${REMOTE}" == "true" ]] ; then
889N/A CLASSES+=" :remote"
459N/Aelse
459N/A CLASSES+=" :local"
0N/Afi
0N/A
459N/A# Arguments:
804N/A# 1) name of SMF property to find in one of the service instances
804N/A# 2) name of variable to store the value of the property in, if found
804N/A# Also sets variable with name of $2_INSTANCE to the service instance the
804N/A# property was found in, for use in later messages.
804N/Afunction getprop {
804N/A # Make ${propval} be a reference to the variable named as the second arg
804N/A nameref propval=$2
804N/A nameref propinst="${2}_INSTANCE"
804N/A
804N/A # The "" instance is to get the properties from the base service without
804N/A # any instance specifier
804N/A for instance in ":display${DISPLAY}" ${CLASSES} "" ; do
804N/A propinst="svc:/application/x11/x11-server${instance}"
804N/A if svcprop -q -p $1 "${propinst}" ; then
804N/A propval="$(svcprop -p $1 "${propinst}")"
392N/A if [[ "${propval}" == "\"\"" ]] ; then
804N/A propval=""
804N/A fi
804N/A return 0
804N/A fi
804N/A done
804N/A return 1
804N/A}
804N/A
804N/Agetprop options/default_depth DEFDEPTH
804N/Agetprop options/server XSERVER
804N/Agetprop options/server_args SERVERARGS
804N/Agetprop options/tcp_listen TCP_LISTEN
804N/Agetprop options/display_0_on_console CONSOLE
804N/Agetprop options/config_file CONFIG_FILE
804N/A
804N/AORIGINAL_XSERVER="${XSERVER}"
804N/A
804N/Aif [[ -f ${XSERVER} ]] ; then
804N/A # Canonicalize path, so that we don't break people who specified path
804N/A # via the /usr/X -> openwin or X11 link
804N/A builtin -f libcmd.so.1 readlink && \
804N/A XSERVER=$(readlink -f ${XSERVER})
804N/Aelse
804N/A # Automatically select replacements for removed X servers
804N/A case ${XSERVER} in
804N/A */Xsun)
804N/A newserver="/usr/bin/Xorg"
804N/A ;;
804N/A */Xvfb)
804N/A newserver="/usr/bin/Xvfb"
804N/A ;;
804N/A *)
804N/A fatal_error "${XSERVER} is not an executable"
804N/A ;;
804N/A esac
804N/A cat 1>&2 <<#EOF
804N/A Specified server ${XSERVER} not found, using ${newserver} instead.
804N/A To correct this warning, change the server property with
804N/A /usr/sbin/svccfg -s ${XSERVER_INSTANCE} \\
804N/A setprop options/server == ${newserver}
804N/A EOF
804N/A XSERVER="${newserver}"
804N/Afi
804N/A
0N/A
0N/A# Make sure ${XSERVER} is a known X server binary
0N/Afunction is_known_xserver {
804N/A case "$1" in
804N/A /usr/bin/Xorg) return 0 ;;
804N/A /usr/bin/amd64/Xorg) return 0 ;;
804N/A /usr/bin/i86/Xorg) return 0 ;;
0N/A /usr/bin/Xvfb) return 0 ;;
804N/A /usr/bin/amd64/Xvfb) return 0 ;;
0N/A /usr/bin/i86/Xvfb) return 0 ;;
804N/A /usr/bin/Xvnc) return 0 ;;
392N/A /usr/openwin/bin/Xsun) return 0 ;;
392N/A /usr/openwin/bin/Xvfb) return 0 ;;
804N/A /opt/SUNWut/lib/Xnewt) return 0 ;;
804N/A esac
804N/A return 1
804N/A}
804N/A
804N/Aif ! is_known_xserver "${ORIGINAL_XSERVER}" ; then
804N/A if ! is_known_xserver "${XSERVER}" ; then
0N/A fatal_error "${XSERVER} is not a valid X server"
804N/A fi
554N/Afi
0N/A
804N/Acase ${XSERVER} in
804N/A # Xsun based
804N/A /usr/openwin/bin/*)
804N/A DEPTHARG="-defdepth ${DEFDEPTH:-24}"
804N/A ;;
0N/A # Xorg based
804N/A /usr/bin/*)
0N/A if [[ "${DEFDEPTH}" != "" ]] ; then
0N/A DEPTHARG="-depth ${DEFDEPTH}"
0N/A fi
0N/A ;;
554N/Aesac
0N/A
804N/A# Should not happen, but just in case
804N/Aif [[ "${TCP_LISTEN}" == "" ]] ; then
804N/A if [[ "${REMOTE}" == "true" ]] ; then
0N/A TCP_LISTEN="true"
804N/A else
811N/A TCP_LISTEN="false"
804N/A fi
804N/Afi
804N/A
804N/Aif [[ "${TCP_LISTEN}" == "false" ]] ; then
804N/A LISTENARG="-nolisten tcp"
804N/Aelse
804N/A LISTENARG=""
804N/Afi
804N/A
804N/Aif [[ ("${CONSOLE}" == "true") && ("${DISPLAY}" == "0") ]] ; then
804N/A CONSOLE="-C"
804N/Aelse
804N/A CONSOLE=""
804N/Afi
804N/A
804N/A# Currently only Xorg accepts a command line flag for choosing config files.
804N/A# If other X servers add such flags in the future, they should be added here.
804N/A# Only filenames without directory paths are allowed (similar to when a
804N/A# non-root user runs Xorg -config) to avoid security issues.
804N/ACONFIGARG=""
804N/Aif [[ ! -z "${CONFIG_FILE}" ]] ; then
804N/A case ${CONFIG_FILE} in
804N/A */*) fatal_error "Illegal value for config_file property" ;;
804N/A esac
804N/A case ${XSERVER} in
804N/A *Xorg) CONFIGARG="-config ${CONFIG_FILE}" ;;
804N/A esac
804N/Afi
804N/A
804N/AALLARGS="${DEPTHARG} ${LISTENARG} ${SERVERARGS} ${CONSOLE} ${CONFIGARG} $*"
804N/A
804N/Aexec ${XSERVER} :${DISPLAY} ${ALLARGS}
804N/A