treewide: replace /bin/ksh93 hashbangs with /bin/sh
[unleashed-userland.git] / components / x11 / xorg-server / files / Xserver
blobb0fb9323b9d23f5f7ea11cbfcb45664711f6d52d
1 #!/bin/sh
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
15 # Software.
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
30 progname=$0
31 function fatal_error
33 print -u2 "${progname}: $*"
34 exit 1
37 #########
39 # Default values
41 # Users must not modify this script to change them - change via SMF properties
44 DISPLAY="0"
45 DEFDEPTH=""
46 CLASSES=""
47 TCP_LISTEN=""
48 SERVERARGS=""
49 XSERVER="/usr/bin/Xorg"
50 CONSOLE=""
53 while getopts :c: opt; do
54 case $opt in
55 c) CLASSES+=" :${OPTARG}" ;;
56 ?) print -u2 $USAGE ; exit 2;;
57 esac
58 done
60 shift $((OPTIND - 1))
62 if (( $# > 1 )) ; then
63 case $1 in
64 :*)
65 # Strip leading ":" from $1 to get display number
66 DISPLAY="${1#:}"
67 shift
69 esac
72 REMOTE="false"
73 for a in $SERVERARGS "$*" ; do
74 case $a in
75 -query|-broadcast|-multicast|-indirect)
76 REMOTE="true"
79 # Do nothing
81 esac
82 done
84 if [[ "${REMOTE}" == "true" ]] ; then
85 CLASSES+=" :remote"
86 else
87 CLASSES+=" :local"
90 # Arguments:
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.
95 function getprop {
96 # Make ${propval} be a reference to the variable named as the second arg
97 nameref propval=$2
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
107 propval=""
109 return 0
111 done
112 return 1
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})
128 else
129 # Automatically select replacements for removed X servers
130 case ${XSERVER} in
131 */Xsun)
132 newserver="/usr/bin/Xorg"
134 */Xvfb)
135 newserver="/usr/bin/Xvfb"
138 fatal_error "${XSERVER} is not an executable"
140 esac
141 cat 1>&2 <<#EOF
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 {
153 case "$1" in
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 ;;
164 esac
165 return 1
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"
174 case ${XSERVER} in
175 # Xsun based
176 /usr/openwin/bin/*)
177 DEPTHARG="-defdepth ${DEFDEPTH:-24}"
179 # Xorg based
180 /usr/bin/*)
181 if [[ "${DEFDEPTH}" != "" ]] ; then
182 DEPTHARG="-depth ${DEFDEPTH}"
185 esac
187 # Should not happen, but just in case
188 if [[ "${TCP_LISTEN}" == "" ]] ; then
189 if [[ "${REMOTE}" == "true" ]] ; then
190 TCP_LISTEN="true"
191 else
192 TCP_LISTEN="false"
196 if [[ "${TCP_LISTEN}" == "false" ]] ; then
197 LISTENARG="-nolisten tcp"
198 else
199 LISTENARG=""
202 if [[ ("${CONSOLE}" == "true") && ("${DISPLAY}" == "0") ]] ; then
203 CONSOLE="-C"
204 else
205 CONSOLE=""
208 ALLARGS="${DEPTHARG} ${LISTENARG} ${SERVERARGS} ${CONSOLE} $*"
210 exec ${XSERVER} :${DISPLAY} ${ALLARGS}