4 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
26 USAGE="Usage: $0 [-c <class>] :<display> [<X server arguments>]"
28 PATH=/usr/bin:/usr/sbin
33 print -u2 "${progname}: $*"
41 # Users must not modify this script to change them - change via SMF properties
49 XSERVER="/usr/bin/Xorg"
53 while getopts :c: opt; do
55 c) CLASSES+=" :${OPTARG}" ;;
56 ?) print -u2 $USAGE ; exit 2;;
62 if (( $# > 1 )) ; then
65 # Strip leading ":" from $1 to get display number
73 for a in $SERVERARGS "$*" ; do
75 -query|-broadcast|-multicast|-indirect)
84 if [[ "${REMOTE}" == "true" ]] ; then
91 # 1) name of SMF property to find in one of the service instances
92 # 2) name of variable to store the value of the property in, if found
93 # Also sets variable with name of $2_INSTANCE to the service instance the
94 # property was found in, for use in later messages.
96 # Make ${propval} be a reference to the variable named as the second arg
98 nameref propinst="${2}_INSTANCE"
100 # The "" instance is to get the properties from the base service without
101 # any instance specifier
102 for instance in ":display${DISPLAY}" ${CLASSES} "" ; do
103 propinst="svc:/application/x11/x11-server${instance}"
104 if svcprop -q -p $1 "${propinst}" ; then
105 propval="$(svcprop -p $1 "${propinst}")"
106 if [[ "${propval}" == "\"\"" ]] ; then
115 getprop options/default_depth DEFDEPTH
116 getprop options/server XSERVER
117 getprop options/server_args SERVERARGS
118 getprop options/tcp_listen TCP_LISTEN
119 getprop options/display_0_on_console CONSOLE
121 ORIGINAL_XSERVER="${XSERVER}"
123 if [[ -f ${XSERVER} ]] ; then
124 # Canonicalize path, so that we don't break people who specified path
125 # via the /usr/X -> openwin or X11 link
126 builtin -f libcmd.so.1 readlink && \
127 XSERVER=$(readlink -f ${XSERVER})
129 # Automatically select replacements for removed X servers
132 newserver="/usr/bin/Xorg"
135 newserver="/usr/bin/Xvfb"
138 fatal_error "${XSERVER} is not an executable"
142 Specified server ${XSERVER} not found, using ${newserver} instead.
143 To correct this warning, change the server property with
144 /usr/sbin/svccfg -s ${XSERVER_INSTANCE} \\
145 setprop options/server == ${newserver}
147 XSERVER="${newserver}"
151 # Make sure ${XSERVER} is a known X server binary
152 function is_known_xserver {
154 /usr/bin/Xorg) return 0 ;;
155 /usr/bin/amd64/Xorg) return 0 ;;
156 /usr/bin/i86/Xorg) return 0 ;;
157 /usr/bin/Xvfb) return 0 ;;
158 /usr/bin/amd64/Xvfb) return 0 ;;
159 /usr/bin/i86/Xvfb) return 0 ;;
160 /usr/bin/Xvnc) return 0 ;;
161 /usr/openwin/bin/Xsun) return 0 ;;
162 /usr/openwin/bin/Xvfb) return 0 ;;
163 /opt/SUNWut/lib/Xnewt) return 0 ;;
168 if ! is_known_xserver "${ORIGINAL_XSERVER}" ; then
169 if ! is_known_xserver "${XSERVER}" ; then
170 fatal_error "${XSERVER} is not a valid X server"
177 DEPTHARG="-defdepth ${DEFDEPTH:-24}"
181 if [[ "${DEFDEPTH}" != "" ]] ; then
182 DEPTHARG="-depth ${DEFDEPTH}"
187 # Should not happen, but just in case
188 if [[ "${TCP_LISTEN}" == "" ]] ; then
189 if [[ "${REMOTE}" == "true" ]] ; then
196 if [[ "${TCP_LISTEN}" == "false" ]] ; then
197 LISTENARG="-nolisten tcp"
202 if [[ ("${CONSOLE}" == "true") && ("${DISPLAY}" == "0") ]] ; then
208 ALLARGS="${DEPTHARG} ${LISTENARG} ${SERVERARGS} ${CONSOLE} $*"
210 exec ${XSERVER} :${DISPLAY} ${ALLARGS}