1 #!/bin/ksh93 |
|
2 # |
|
3 # |
|
4 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. |
|
5 # |
|
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: |
|
12 # |
|
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. |
|
16 # |
|
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. |
|
24 # |
|
25 |
|
26 USAGE="Usage: $0 [-c <class>] :<display> [<X server arguments>]" |
|
27 |
|
28 PATH=/usr/bin:/usr/sbin |
|
29 |
|
30 progname=$0 |
|
31 function fatal_error |
|
32 { |
|
33 print -u2 "${progname}: $*" |
|
34 exit 1 |
|
35 } |
|
36 |
|
37 ######### |
|
38 # |
|
39 # Default values |
|
40 # |
|
41 # Users must not modify this script to change them - change via SMF properties |
|
42 # |
|
43 |
|
44 DISPLAY="0" |
|
45 DEFDEPTH="" |
|
46 CLASSES="" |
|
47 TCP_LISTEN="" |
|
48 SERVERARGS="" |
|
49 XSERVER="/usr/bin/Xorg" |
|
50 CONSOLE="" |
|
51 |
|
52 |
|
53 while getopts :c: opt; do |
|
54 case $opt in |
|
55 c) CLASSES+=" :${OPTARG}" ;; |
|
56 ?) print -u2 $USAGE ; exit 2;; |
|
57 esac |
|
58 done |
|
59 |
|
60 shift $((OPTIND - 1)) |
|
61 |
|
62 if (( $# > 1 )) ; then |
|
63 case $1 in |
|
64 :*) |
|
65 # Strip leading ":" from $1 to get display number |
|
66 DISPLAY="${1#:}" |
|
67 shift |
|
68 ;; |
|
69 esac |
|
70 fi |
|
71 |
|
72 REMOTE="false" |
|
73 for a in $SERVERARGS "$*" ; do |
|
74 case $a in |
|
75 -query|-broadcast|-multicast|-indirect) |
|
76 REMOTE="true" |
|
77 ;; |
|
78 *) |
|
79 # Do nothing |
|
80 ;; |
|
81 esac |
|
82 done |
|
83 |
|
84 if [[ "${REMOTE}" == "true" ]] ; then |
|
85 CLASSES+=" :remote" |
|
86 else |
|
87 CLASSES+=" :local" |
|
88 fi |
|
89 |
|
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" |
|
99 |
|
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="" |
|
108 fi |
|
109 return 0 |
|
110 fi |
|
111 done |
|
112 return 1 |
|
113 } |
|
114 |
|
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 |
|
120 |
|
121 ORIGINAL_XSERVER="${XSERVER}" |
|
122 |
|
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" |
|
133 ;; |
|
134 */Xvfb) |
|
135 newserver="/usr/bin/Xvfb" |
|
136 ;; |
|
137 *) |
|
138 fatal_error "${XSERVER} is not an executable" |
|
139 ;; |
|
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} |
|
146 EOF |
|
147 XSERVER="${newserver}" |
|
148 fi |
|
149 |
|
150 |
|
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 |
|
166 } |
|
167 |
|
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" |
|
171 fi |
|
172 fi |
|
173 |
|
174 case ${XSERVER} in |
|
175 # Xsun based |
|
176 /usr/openwin/bin/*) |
|
177 DEPTHARG="-defdepth ${DEFDEPTH:-24}" |
|
178 ;; |
|
179 # Xorg based |
|
180 /usr/bin/*) |
|
181 if [[ "${DEFDEPTH}" != "" ]] ; then |
|
182 DEPTHARG="-depth ${DEFDEPTH}" |
|
183 fi |
|
184 ;; |
|
185 esac |
|
186 |
|
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" |
|
193 fi |
|
194 fi |
|
195 |
|
196 if [[ "${TCP_LISTEN}" == "false" ]] ; then |
|
197 LISTENARG="-nolisten tcp" |
|
198 else |
|
199 LISTENARG="" |
|
200 fi |
|
201 |
|
202 if [[ ("${CONSOLE}" == "true") && ("${DISPLAY}" == "0") ]] ; then |
|
203 CONSOLE="-C" |
|
204 else |
|
205 CONSOLE="" |
|
206 fi |
|
207 |
|
208 ALLARGS="${DEPTHARG} ${LISTENARG} ${SERVERARGS} ${CONSOLE} $*" |
|
209 |
|
210 exec ${XSERVER} :${DISPLAY} ${ALLARGS} |
|