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