105 |
@@ -1,1930 +0,0 @@
|
106 |
-#!/bin/sh
|
107 |
-# ----------------------------------------------------------------------
|
108 |
-# Copyright (C) 2005-2010 Karl J. Runge <runge@karlrunge.com>
|
109 |
-# All rights reserved.
|
110 |
-#
|
111 |
-# This file is part of Xdummy.
|
112 |
-#
|
113 |
-# Xdummy is free software; you can redistribute it and/or modify
|
114 |
-# it under the terms of the GNU General Public License as published by
|
115 |
-# the Free Software Foundation; either version 2 of the License, or (at
|
116 |
-# your option) any later version.
|
117 |
-#
|
118 |
-# Xdummy is distributed in the hope that it will be useful,
|
119 |
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
120 |
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
121 |
-# GNU General Public License for more details.
|
122 |
-#
|
123 |
-# You should have received a copy of the GNU General Public License
|
124 |
-# along with Xdummy; if not, write to the Free Software
|
125 |
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
|
126 |
-# or see <http://www.gnu.org/licenses/>.
|
127 |
-# ----------------------------------------------------------------------
|
128 |
-#
|
129 |
-#
|
130 |
-# Xdummy: an LD_PRELOAD hack to run a stock Xorg(1) or XFree86(1) server
|
131 |
-# with the "dummy" video driver to make it avoid Linux VT switching, etc.
|
132 |
-#
|
133 |
-# Run "Xdummy -help" for more info.
|
134 |
-#
|
135 |
-install=""
|
136 |
-uninstall=""
|
137 |
-runit=1
|
138 |
-prconf=""
|
139 |
-notweak=""
|
140 |
-root=""
|
141 |
-nosudo=""
|
142 |
-xserver=""
|
143 |
-geom=""
|
144 |
-nomodelines=""
|
145 |
-depth=""
|
146 |
-debug=""
|
147 |
-strace=""
|
148 |
-cmdline_config=""
|
149 |
-
|
150 |
-PATH=$PATH:/bin:/usr/bin
|
151 |
-export PATH
|
152 |
-
|
153 |
-program=`basename "$0"`
|
154 |
-
|
155 |
-help () {
|
156 |
- ${PAGER:-more} << END
|
157 |
-$program:
|
158 |
-
|
159 |
- A hack to run a stock Xorg(1) or XFree86(1) X server with the "dummy"
|
160 |
- (RAM-only framebuffer) video driver such that it AVOIDS the Linux VT
|
161 |
- switching, opening device files in /dev, keyboard and mouse conflicts,
|
162 |
- and other problems associated with the normal use of "dummy".
|
163 |
-
|
164 |
- In other words, it tries to make Xorg/XFree86 with the "dummy"
|
165 |
- device driver act more like Xvfb(1).
|
166 |
-
|
167 |
- The primary motivation for the Xdummy script is to provide a virtual X
|
168 |
- server for x11vnc but with more features than Xvfb (or Xvnc); however
|
169 |
- it could be used for other reasons (e.g. better automated testing
|
170 |
- than with Xvfb.) One nice thing is the dummy server supports RANDR
|
171 |
- dynamic resizing while Xvfb does not.
|
172 |
-
|
173 |
- So, for example, x11vnc+Xdummy terminal services are a little better
|
174 |
- than x11vnc+Xvfb.
|
175 |
-
|
176 |
- To achieve this, while running the real Xserver $program intercepts
|
177 |
- system and library calls via the LD_PRELOAD method and modifies
|
178 |
- the behavior to make it work correctly (e.g. avoid the VT stuff.)
|
179 |
- LD_PRELOAD tricks are usually "clever hacks" and so might not work
|
180 |
- in all situations or break when something changes.
|
181 |
-
|
182 |
- WARNING: Take care in using Xdummy, although it never has it is
|
183 |
- possible that it could damage hardware. One can use the -prconf
|
184 |
- option to have it print out the xorg.conf config that it would use
|
185 |
- and then inspect it carefully before actually using it.
|
186 |
-
|
187 |
- This program no longer needs to be run as root as of 12/2009.
|
188 |
- However, if there are problems for certain situations (usually older
|
189 |
- servers) it may perform better if run as root (use the -root option.)
|
190 |
- When running as root remember the previous paragraph and that Xdummy
|
191 |
- comes without any warranty.
|
192 |
-
|
193 |
- gcc/cc and other build tools are required for this script to be able
|
194 |
- to compile the LD_PRELOAD shared object. Be sure they are installed
|
195 |
- on the system. See -install and -uninstall described below.
|
196 |
-
|
197 |
- Your Linux distribution may not install the dummy driver by default,
|
198 |
- e.g:
|
199 |
-
|
200 |
- /usr/lib/xorg/modules/drivers/dummy_drv.so
|
201 |
-
|
202 |
- some have it in a package named xserver-xorg-video-dummy you that
|
203 |
- need to install.
|
204 |
-
|
205 |
-Usage:
|
206 |
-
|
207 |
- $program <${program}-args> <Xserver-args>
|
208 |
-
|
209 |
- (actually, the arguments can be supplied in any order.)
|
210 |
-
|
211 |
-Examples:
|
212 |
-
|
213 |
- $program -install
|
214 |
-
|
215 |
- $program :1
|
216 |
-
|
217 |
- $program -debug :1
|
218 |
-
|
219 |
- $program -tmpdir ~/mytmp :1 -nolisten tcp
|
220 |
-
|
221 |
-startx example:
|
222 |
-
|
223 |
- startx -e bash -- $program :2 -depth 16
|
224 |
-
|
225 |
- (if startx needs to be run as root, you can su(1) to a normal
|
226 |
- user in the bash shell and then launch ~/.xinitrc or ~/.xsession,
|
227 |
- gnome-session, startkde, startxfce4, etc.)
|
228 |
-
|
229 |
-xdm example:
|
230 |
-
|
231 |
- xdm -config /usr/local/dummy/xdm-config -nodaemon
|
232 |
-
|
233 |
- where the xdm-config file has line:
|
234 |
-
|
235 |
- DisplayManager.servers: /usr/local/dummy/Xservers
|
236 |
-
|
237 |
- and /usr/local/dummy/Xservers has lines:
|
238 |
-
|
239 |
- :1 local /usr/local/dummy/Xdummy :1 -debug
|
240 |
- :2 local /usr/local/dummy/Xdummy :2 -debug
|
241 |
-
|
242 |
- (-debug is optional)
|
243 |
-
|
244 |
-gdm/kdm example:
|
245 |
-
|
246 |
- TBD.
|
247 |
-
|
248 |
-Root permission and x11vnc:
|
249 |
-
|
250 |
- Update: as of 12/2009 this program no longer must be run as root.
|
251 |
- So try it as non-root before running it as root and/or the
|
252 |
- following schemes.
|
253 |
-
|
254 |
- In some circumstances X server program may need to be run as root.
|
255 |
- If so, one could run x11vnc as root with -unixpw (it switches
|
256 |
- to the user that logs in) and that may be OK, some other ideas:
|
257 |
-
|
258 |
- - add this to sudo via visudo:
|
259 |
-
|
260 |
- ALL ALL = NOPASSWD: /usr/local/bin/Xdummy
|
261 |
-
|
262 |
- - use this little suid wrapper:
|
263 |
-/*
|
264 |
- * xdummy.c
|
265 |
- *
|
266 |
- cc -o ./xdummy xdummy.c
|
267 |
- sudo cp ./xdummy /usr/local/bin/xdummy
|
268 |
- sudo chown root:root /usr/local/bin/xdummy
|
269 |
- sudo chmod u+s /usr/local/bin/xdummy
|
270 |
- *
|
271 |
- */
|
272 |
-#include <unistd.h>
|
273 |
-#include <stdlib.h>
|
274 |
-#include <sys/types.h>
|
275 |
-#include <stdio.h>
|
276 |
-
|
277 |
-int main (int argc, char *argv[]) {
|
278 |
- extern char **environ;
|
279 |
- char str[100];
|
280 |
- sprintf(str, "XDUMMY_UID=%d", (int) getuid());
|
281 |
- putenv(str);
|
282 |
- setuid(0);
|
283 |
- setgid(0);
|
284 |
- execv("/usr/local/bin/Xdummy", argv);
|
285 |
- exit(1);
|
286 |
- return 1;
|
287 |
-}
|
288 |
-
|
289 |
-
|
290 |
-Options:
|
291 |
-
|
292 |
- ${program}-args:
|
293 |
-
|
294 |
- -install Compile the LD_PRELOAD shared object and install it
|
295 |
- next to the $program script file as:
|
296 |
-
|
297 |
- $0.so
|
298 |
-
|
299 |
- When that file exists it is used as the LD_PRELOAD
|
300 |
- shared object without recompiling. Otherwise,
|
301 |
- each time $program is run the LD_PRELOAD shared
|
302 |
- object is compiled as a file in /tmp (or -tmpdir)
|
303 |
-
|
304 |
- If you set the environment variable
|
305 |
- INTERPOSE_GETUID=1 when building, then when
|
306 |
- $program is run as an ordinary user, the shared
|
307 |
- object will interpose getuid() calls and pretend
|
308 |
- to be root. Otherwise it doesn't pretend to
|
309 |
- be root.
|
310 |
-
|
311 |
- You can also set the CFLAGS environment variable
|
312 |
- to anything else you want on the compile cmdline.
|
313 |
-
|
314 |
- -uninstall Remove the file:
|
315 |
-
|
316 |
- $0.so
|
317 |
-
|
318 |
- The LD_PRELOAD shared object will then be compiled
|
319 |
- each time this program is run.
|
320 |
-
|
321 |
- The X server is not started under -install, -uninstall, or -prconf.
|
322 |
-
|
323 |
-
|
324 |
- :N The DISPLAY (e.g. :15) is often the first
|
325 |
- argument. It is passed to the real X server and
|
326 |
- also used by the Xdummy script as an identifier.
|
327 |
-
|
328 |
- -geom geom1[,geom2...] Take the geometry (e.g. 1024x768) or list
|
329 |
- of geometries and insert them into the Screen
|
330 |
- section of the tweaked X server config file.
|
331 |
- Use this to have a different geometry than the
|
332 |
- one(s) in the system config file.
|
333 |
-
|
334 |
- The option -geometry can be used instead of -geom;
|
335 |
- x11vnc calls Xdummy and Xvfb this way.
|
336 |
-
|
337 |
- -nomodelines When you specify -geom/-geometry, $program will
|
338 |
- create Modelines for each geometry and put them
|
339 |
- in the Monitor section. If you do not want this
|
340 |
- then supply -nomodelines.
|
341 |
-
|
342 |
- -depth n Use pixel color depth n (e.g. 8, 16, or 24). This
|
343 |
- makes sure the X config file has a Screen.Display
|
344 |
- subsection of this depth. Note this option is
|
345 |
- ALSO passed to the X server.
|
346 |
-
|
347 |
- -DEPTH n Same as -depth, except not passed to X server.
|
348 |
-
|
349 |
- -tmpdir dir Specify a temporary directory, owned by you and
|
350 |
- only writable by you. This is used in place of
|
351 |
- /tmp/Xdummy.\$USER/.. to place the $program.so
|
352 |
- shared object, tweaked config files, etc.
|
353 |
-
|
354 |
- -nonroot Run in non-root mode (working 12/2009, now default)
|
355 |
-
|
356 |
- -root Run as root (may still be needed in some
|
357 |
- environments.) Same as XDUMMY_RUN_AS_ROOT=1.
|
358 |
-
|
359 |
- -nosudo Do not try to use sudo(1) when re-running as root,
|
360 |
- use su(1) instead.
|
361 |
-
|
362 |
- -xserver path Specify the path to the Xserver to use. Default
|
363 |
- is to try "Xorg" first and then "XFree86". If
|
364 |
- those are not in \$PATH, it tries these locations:
|
365 |
- /usr/bin/Xorg
|
366 |
- /usr/X11R6/bin/Xorg
|
367 |
- /usr/X11R6/bin/XFree86
|
368 |
-
|
369 |
- -n Do not run the command to start the X server,
|
370 |
- just show the command that $program would run.
|
371 |
- The LD_PRELOAD shared object will be built,
|
372 |
- if needed. Also note any XDUMMY* environment
|
373 |
- variables that need to be set.
|
374 |
-
|
375 |
- -prconf Print, to stdout, the tweaked Xorg/XFree86
|
376 |
- config file (-config and -xf86config server
|
377 |
- options, respectively.) The Xserver is not
|
378 |
- started.
|
379 |
-
|
380 |
- -notweak Do not tweak (modify) the Xorg/XFree86 config file
|
381 |
- (system or server command line) at all. The -geom
|
382 |
- and similar config file modifications are ignored.
|
383 |
-
|
384 |
- It is up to you to make sure it is a working
|
385 |
- config file (e.g. "dummy" driver, etc.)
|
386 |
- Perhaps you want to use a file based on the
|
387 |
- -prconf output.
|
388 |
-
|
389 |
- -debug Extra debugging output.
|
390 |
-
|
391 |
- -strace strace(1) the Xserver process (for troubleshooting.)
|
392 |
- -ltrace ltrace(1) instead of strace (can be slow.)
|
393 |
-
|
394 |
- -h, -help Print out this help.
|
395 |
-
|
396 |
-
|
397 |
- Xserver-args:
|
398 |
-
|
399 |
- Most of the Xorg and XFree86 options will work and are simply
|
400 |
- passed along if you supply them. Important ones that may be
|
401 |
- supplied if missing:
|
402 |
-
|
403 |
- :N X Display number for server to use.
|
404 |
-
|
405 |
- vtNN Linux virtual terminal (VT) to use (a VT is currently
|
406 |
- still used, just not switched to and from.)
|
407 |
-
|
408 |
- -config file Driver "dummy" tweaked config file, a
|
409 |
- -xf86config file number of settings are tweaked besides Driver.
|
410 |
-
|
411 |
- If -config/-xf86config is not given, the system one
|
412 |
- (e.g. /etc/X11/xorg.conf) is used. If the system one cannot be
|
413 |
- found, a built-in one is used. Any settings in the config file
|
414 |
- that are not consistent with "dummy" mode will be overwritten
|
415 |
- (unless -notweak is specified.)
|
416 |
-
|
417 |
- Use -config xdummy-builtin to force usage of the builtin config.
|
418 |
-
|
419 |
- If "file" is only a basename (e.g. "xorg.dummy.conf") with no /'s,
|
420 |
- then no tweaking of it is done: the X server will look for that
|
421 |
- basename via its normal search algorithm. If the found file does
|
422 |
- not refer to the "dummy" driver, etc, then the X server will fail.
|
423 |
-
|
424 |
-Notes:
|
425 |
-
|
426 |
- The Xorg/XFree86 "dummy" driver is currently undocumented. It works
|
427 |
- well in this mode, but it is evidently not intended for end-users.
|
428 |
- So it could be removed or broken at any time.
|
429 |
-
|
430 |
- If the display Xserver-arg (e.g. :1) is not given, or ":" is given
|
431 |
- that indicates $program should try to find a free one (based on
|
432 |
- tcp ports.)
|
433 |
-
|
434 |
- If the display virtual terminal, VT, (e.g. vt9) is not given that
|
435 |
- indicates $program should try to find a free one (or guess a high one.)
|
436 |
-
|
437 |
- This program is not completely secure WRT files in /tmp (but it tries
|
438 |
- to a good degree.) Better is to use the -tmpdir option to supply a
|
439 |
- directory only writable by you. Even better is to get rid of users
|
440 |
- on the local machine you do not trust :-)
|
441 |
-
|
442 |
- Set XDUMMY_SET_XV=1 to turn on debugging output for this script.
|
443 |
-
|
444 |
-END
|
445 |
-}
|
446 |
-
|
447 |
-warn() {
|
448 |
- echo "$*" 1>&2
|
449 |
-}
|
450 |
-
|
451 |
-if [ "X$XDUMMY_SET_XV" != "X" ]; then
|
452 |
- set -xv
|
453 |
-fi
|
454 |
-
|
455 |
-if [ "X$XDUMMY_UID" = "X" ]; then
|
456 |
- XDUMMY_UID=`id -u`
|
457 |
- export XDUMMY_UID
|
458 |
-fi
|
459 |
-if [ "X$XDUMMY_UID" = "X0" ]; then
|
460 |
- if [ "X$SUDO_UID" != "X" ]; then
|
461 |
- XDUMMY_UID=$SUDO_UID
|
462 |
- export XDUMMY_UID
|
463 |
- fi
|
464 |
-fi
|
465 |
-
|
466 |
-# check if root=1 first:
|
467 |
-#
|
468 |
-if [ "X$XDUMMY_RUN_AS_ROOT" = "X1" ]; then
|
469 |
- root=1
|
470 |
-fi
|
471 |
-for arg in $*
|
472 |
-do
|
473 |
- if [ "X$arg" = "X-nonroot" ]; then
|
474 |
- root=""
|
475 |
- elif [ "X$arg" = "X-root" ]; then
|
476 |
- root=1
|
477 |
- fi
|
478 |
-done
|
479 |
-
|
480 |
-# See if it really needs to be run as root:
|
481 |
-#
|
482 |
-if [ "X$XDUMMY_SU_EXEC" = "X" -a "X$root" = "X1" -a "X`id -u`" != "X0" ]; then
|
483 |
- # this is to prevent infinite loop in case su/sudo doesn't work:
|
484 |
- XDUMMY_SU_EXEC=1
|
485 |
- export XDUMMY_SU_EXEC
|
486 |
-
|
487 |
- dosu=1
|
488 |
- nosudo=""
|
489 |
-
|
490 |
- for arg in $*
|
491 |
- do
|
492 |
- if [ "X$arg" = "X-nonroot" ]; then
|
493 |
- dosu=""
|
494 |
- elif [ "X$arg" = "X-nosudo" ]; then
|
495 |
- nosudo="1"
|
496 |
- elif [ "X$arg" = "X-help" ]; then
|
497 |
- dosu=""
|
498 |
- elif [ "X$arg" = "X-h" ]; then
|
499 |
- dosu=""
|
500 |
- elif [ "X$arg" = "X-install" ]; then
|
501 |
- dosu=""
|
502 |
- elif [ "X$arg" = "X-uninstall" ]; then
|
503 |
- dosu=""
|
504 |
- elif [ "X$arg" = "X-n" ]; then
|
505 |
- dosu=""
|
506 |
- elif [ "X$arg" = "X-prconf" ]; then
|
507 |
- dosu=""
|
508 |
- fi
|
509 |
- done
|
510 |
- if [ $dosu ]; then
|
511 |
- # we need to restart it with su/sudo:
|
512 |
- if type sudo > /dev/null 2>&1; then
|
513 |
- :
|
514 |
- else
|
515 |
- nosudo=1
|
516 |
- fi
|
517 |
- if [ "X$nosudo" = "X" ]; then
|
518 |
- warn "$program: supply the sudo password to restart as root:"
|
519 |
- if [ "X$XDUMMY_UID" != "X" ]; then
|
520 |
- exec sudo $0 -uid $XDUMMY_UID "$@"
|
521 |
- else
|
522 |
- exec sudo $0 "$@"
|
523 |
- fi
|
524 |
- else
|
525 |
- warn "$program: supply the root password to restart as root:"
|
526 |
- if [ "X$XDUMMY_UID" != "X" ]; then
|
527 |
- exec su -c "$0 -uid $XDUMMY_UID $*"
|
528 |
- else
|
529 |
- exec su -c "$0 $*"
|
530 |
- fi
|
531 |
- fi
|
532 |
- # DONE:
|
533 |
- exit
|
534 |
- fi
|
535 |
-fi
|
536 |
-
|
537 |
-# This will hold the X display, e.g. :20
|
538 |
-#
|
539 |
-disp=""
|
540 |
-args=""
|
541 |
-cmdline_config=""
|
542 |
-
|
543 |
-# Process Xdummy args:
|
544 |
-#
|
545 |
-while [ "X$1" != "X" ]
|
546 |
-do
|
547 |
- if [ "X$1" = "X-config" -o "X$1" = "X-xf86config" ]; then
|
548 |
- cmdline_config="$2"
|
549 |
- fi
|
550 |
- case $1 in
|
551 |
- ":"*) disp=$1
|
552 |
- ;;
|
553 |
- "-install") install=1; runit=""
|
554 |
- ;;
|
555 |
- "-uninstall") uninstall=1; runit=""
|
556 |
- ;;
|
557 |
- "-n") runit=""
|
558 |
- ;;
|
559 |
- "-no") runit=""
|
560 |
- ;;
|
561 |
- "-norun") runit=""
|
562 |
- ;;
|
563 |
- "-prconf") prconf=1; runit=""
|
564 |
- ;;
|
565 |
- "-notweak") notweak=1
|
566 |
- ;;
|
567 |
- "-noconf") notweak=1
|
568 |
- ;;
|
569 |
- "-nonroot") root=""
|
570 |
- ;;
|
571 |
- "-root") root=1
|
572 |
- ;;
|
573 |
- "-nosudo") nosudo=1
|
574 |
- ;;
|
575 |
- "-xserver") xserver="$2"; shift
|
576 |
- ;;
|
577 |
- "-uid") XDUMMY_UID="$2"; shift
|
578 |
- export XDUMMY_UID
|
579 |
- ;;
|
580 |
- "-geom") geom="$2"; shift
|
581 |
- ;;
|
582 |
- "-geometry") geom="$2"; shift
|
583 |
- ;;
|
584 |
- "-nomodelines") nomodelines=1
|
585 |
- ;;
|
586 |
- "-depth") depth="$2"; args="$args -depth $2";
|
587 |
- shift
|
588 |
- ;;
|
589 |
- "-DEPTH") depth="$2"; shift
|
590 |
- ;;
|
591 |
- "-tmpdir") XDUMMY_TMPDIR="$2"; shift
|
592 |
- ;;
|
593 |
- "-debug") debug=1
|
594 |
- ;;
|
595 |
- "-nodebug") debug=""
|
596 |
- ;;
|
597 |
- "-strace") strace=1
|
598 |
- ;;
|
599 |
- "-ltrace") strace=2
|
600 |
- ;;
|
601 |
- "-h") help; exit 0
|
602 |
- ;;
|
603 |
- "-help") help; exit 0
|
604 |
- ;;
|
605 |
- *) args="$args $1"
|
606 |
- ;;
|
607 |
- esac
|
608 |
- shift
|
609 |
-done
|
610 |
-
|
611 |
-# Try to get a username for use in our tmp directory, etc.
|
612 |
-#
|
613 |
-user=""
|
614 |
-if [ X`id -u` = "X0" ]; then
|
615 |
- user=root # this will also be used below for id=0
|
616 |
-elif [ "X$USER" != "X" ]; then
|
617 |
- user=$USER
|
618 |
-elif [ "X$LOGNAME" != "X" ]; then
|
619 |
- user=$LOGNAME
|
620 |
-fi
|
621 |
-
|
622 |
-# Keep trying...
|
623 |
-#
|
624 |
-if [ "X$user" = "X" ]; then
|
625 |
- user=`whoami 2>/dev/null`
|
626 |
-fi
|
627 |
-if [ "X$user" = "X" ]; then
|
628 |
- user=`basename "$HOME"`
|
629 |
-fi
|
630 |
-if [ "X$user" = "X" -o "X$user" = "X." ]; then
|
631 |
- user="u$$"
|
632 |
-fi
|
633 |
-
|
634 |
-if [ "X$debug" = "X1" -a "X$runit" != "X" ]; then
|
635 |
- echo ""
|
636 |
- echo "/usr/bin/env:"
|
637 |
- env | egrep -v '^(LS_COLORS|TERMCAP)' | sort
|
638 |
- echo ""
|
639 |
-fi
|
640 |
-
|
641 |
-# Function to compile the LD_PRELOAD shared object:
|
642 |
-#
|
643 |
-make_so() {
|
644 |
- # extract code embedded in this script into a tmp C file:
|
645 |
- n1=`grep -n '^#code_begin' $0 | head -1 | awk -F: '{print $1}'`
|
646 |
- n2=`grep -n '^#code_end' $0 | head -1 | awk -F: '{print $1}'`
|
647 |
- n1=`expr $n1 + 1`
|
648 |
- dn=`expr $n2 - $n1`
|
649 |
-
|
650 |
- tmp=$tdir/Xdummy.$RANDOM$$.c
|
651 |
- rm -f $tmp
|
652 |
- if [ -e $tmp -o -h $tmp ]; then
|
653 |
- warn "$tmp still exists."
|
654 |
- exit 1
|
655 |
- fi
|
656 |
- touch $tmp || exit 1
|
657 |
- tail -n +$n1 $0 | head -n $dn > $tmp
|
658 |
-
|
659 |
- # compile it to Xdummy.so:
|
660 |
- if [ -f "$SO" ]; then
|
661 |
- mv $SO $SO.$$
|
662 |
- rm -f $SO.$$
|
663 |
- fi
|
664 |
- rm -f $SO
|
665 |
- touch $SO
|
666 |
- if [ ! -f "$SO" ]; then
|
667 |
- SO=$tdir/Xdummy.$user.so
|
668 |
- warn "warning switching LD_PRELOAD shared object to: $SO"
|
669 |
- fi
|
670 |
-
|
671 |
- if [ -f "$SO" ]; then
|
672 |
- mv $SO $SO.$$
|
673 |
- rm -f $SO.$$
|
674 |
- fi
|
675 |
- rm -f $SO
|
676 |
-
|
677 |
- # we assume gcc:
|
678 |
- if [ "X$INTERPOSE_GETUID" = "X1" ]; then
|
679 |
- CFLAGS="$CFLAGS -DINTERPOSE_GETUID"
|
680 |
- fi
|
681 |
- echo "$program:" cc -shared -fPIC $CFLAGS -o $SO $tmp
|
682 |
- cc -shared -fPIC $CFLAGS -o $SO $tmp
|
683 |
- rc=$?
|
684 |
- rm -f $tmp
|
685 |
- if [ $rc != 0 ]; then
|
686 |
- warn "$program: cannot build $SO"
|
687 |
- exit 1
|
688 |
- fi
|
689 |
- if [ "X$debug" != "X" -o "X$install" != "X" ]; then
|
690 |
- warn "$program: created $SO"
|
691 |
- ls -l "$SO"
|
692 |
- fi
|
693 |
-}
|
694 |
-
|
695 |
-# Set tdir to tmp dir for make_so():
|
696 |
-if [ "X$XDUMMY_TMPDIR" != "X" ]; then
|
697 |
- tdir=$XDUMMY_TMPDIR
|
698 |
- mkdir -p $tdir
|
699 |
-else
|
700 |
- tdir="/tmp"
|
701 |
-fi
|
702 |
-
|
703 |
-# Handle -install/-uninstall case:
|
704 |
-SO=$0.so
|
705 |
-if [ "X$install" != "X" -o "X$uninstall" != "X" ]; then
|
706 |
- if [ -e "$SO" -o -h "$SO" ]; then
|
707 |
- warn "$program: removing $SO"
|
708 |
- fi
|
709 |
- if [ -f "$SO" ]; then
|
710 |
- mv $SO $SO.$$
|
711 |
- rm -f $SO.$$
|
712 |
- fi
|
713 |
- rm -f $SO
|
714 |
- if [ -e "$SO" -o -h "$SO" ]; then
|
715 |
- warn "warning: $SO still exists."
|
716 |
- exit 1
|
717 |
- fi
|
718 |
- if [ $install ]; then
|
719 |
- make_so
|
720 |
- if [ ! -f "$SO" ]; then
|
721 |
- exit 1
|
722 |
- fi
|
723 |
- fi
|
724 |
- exit 0
|
725 |
-fi
|
726 |
-
|
727 |
-# We need a tmp directory for the .so, tweaked config file, and for
|
728 |
-# redirecting filenames we cannot create (under -nonroot)
|
729 |
-#
|
730 |
-tack=""
|
731 |
-if [ "X$XDUMMY_TMPDIR" = "X" ]; then
|
732 |
- XDUMMY_TMPDIR="/tmp/Xdummy.$user"
|
733 |
-
|
734 |
- # try to tack on a unique subdir (display number or pid)
|
735 |
- # to allow multiple instances
|
736 |
- #
|
737 |
- if [ "X$disp" != "X" ]; then
|
738 |
- t0=$disp
|
739 |
- else
|
740 |
- t0=$1
|
741 |
- fi
|
742 |
- tack=`echo "$t0" | sed -e 's/^.*://'`
|
743 |
- if echo "$tack" | grep '^[0-9][0-9]*$' > /dev/null; then
|
744 |
- :
|
745 |
- else
|
746 |
- tack=$$
|
747 |
- fi
|
748 |
- if [ "X$tack" != "X" ]; then
|
749 |
- XDUMMY_TMPDIR="$XDUMMY_TMPDIR/$tack"
|
750 |
- fi
|
751 |
-fi
|
752 |
-
|
753 |
-tmp=$XDUMMY_TMPDIR
|
754 |
-if echo "$tmp" | grep '^/tmp' > /dev/null; then
|
755 |
- if [ "X$tmp" != "X/tmp" -a "X$tmp" != "X/tmp/" ]; then
|
756 |
- # clean this subdir of /tmp out, otherwise leave it...
|
757 |
- rm -rf $XDUMMY_TMPDIR
|
758 |
- if [ -e $XDUMMY_TMPDIR ]; then
|
759 |
- warn "$XDUMMY_TMPDIR still exists"
|
760 |
- exit 1
|
761 |
- fi
|
762 |
- fi
|
763 |
-fi
|
764 |
-
|
765 |
-mkdir -p $XDUMMY_TMPDIR
|
766 |
-chmod 700 $XDUMMY_TMPDIR
|
767 |
-if [ "X$tack" != "X" ]; then
|
768 |
- chmod 700 `dirname "$XDUMMY_TMPDIR"` 2>/dev/null
|
769 |
-fi
|
770 |
-
|
771 |
-# See if we can write something there:
|
772 |
-#
|
773 |
-tfile="$XDUMMY_TMPDIR/test.file"
|
774 |
-touch $tfile
|
775 |
-if [ ! -f "$tfile" ]; then
|
776 |
- XDUMMY_TMPDIR="/tmp/Xdummy.$$.$USER"
|
777 |
- warn "warning: setting tmpdir to $XDUMMY_TMPDIR ..."
|
778 |
- rm -rf $XDUMMY_TMPDIR || exit 1
|
779 |
- mkdir -p $XDUMMY_TMPDIR || exit 1
|
780 |
-fi
|
781 |
-rm -f $tfile
|
782 |
-
|
783 |
-export XDUMMY_TMPDIR
|
784 |
-
|
785 |
-# Compile the LD_PRELOAD shared object if needed (needs XDUMMY_TMPDIR)
|
786 |
-#
|
787 |
-if [ ! -f "$SO" ]; then
|
788 |
- SO="$XDUMMY_TMPDIR/Xdummy.so"
|
789 |
- make_so
|
790 |
-fi
|
791 |
-
|
792 |
-# Decide which X server to use:
|
793 |
-#
|
794 |
-if [ "X$xserver" = "X" ]; then
|
795 |
- if type Xorg >/dev/null 2>&1; then
|
796 |
- xserver="Xorg"
|
797 |
- elif type XFree86 >/dev/null 2>&1; then
|
798 |
- xserver="XFree86"
|
799 |
- elif -x /usr/bin/Xorg; then
|
800 |
- xserver="/usr/bin/Xorg"
|
801 |
- elif -x /usr/X11R6/bin/Xorg; then
|
802 |
- xserver="/usr/X11R6/bin/Xorg"
|
803 |
- elif -x /usr/X11R6/bin/XFree86; then
|
804 |
- xserver="/usr/X11R6/bin/XFree86"
|
805 |
- fi
|
806 |
- if [ "X$xserver" = "X" ]; then
|
807 |
- # just let it fail below.
|
808 |
- xserver="/usr/bin/Xorg"
|
809 |
- warn "$program: cannot locate a stock Xserver... assuming $xserver"
|
810 |
- fi
|
811 |
-fi
|
812 |
-
|
813 |
-# See if the binary is suid or not readable under -nonroot mode:
|
814 |
-#
|
815 |
-if [ "X$BASH_VERSION" != "X" ]; then
|
816 |
- xserver_path=`type -p $xserver 2>/dev/null`
|
817 |
-else
|
818 |
- xserver_path=`type $xserver 2>/dev/null | awk '{print $NF}'`
|
819 |
-fi
|
820 |
-if [ -e "$xserver_path" -a "X$root" = "X" -a "X$runit" != "X" ]; then
|
821 |
- if [ ! -r $xserver_path -o -u $xserver_path -o -g $xserver_path ]; then
|
822 |
- # XXX not quite correct with rm -rf $XDUMMY_TMPDIR ...
|
823 |
- # we keep on a filesystem we know root can write to.
|
824 |
- base=`basename "$xserver_path"`
|
825 |
- new="/tmp/$base.$user.bin"
|
826 |
- if [ -e $new ]; then
|
827 |
- snew=`ls -l $new | awk '{print $5}' | grep '^[0-9][0-9]*$'`
|
828 |
- sold=`ls -l $xserver_path | awk '{print $5}' | grep '^[0-9][0-9]*$'`
|
829 |
- if [ "X$snew" != "X" -a "X$sold" != "X" -a "X$sold" != "X$snew" ]; then
|
830 |
- warn "removing different sized copy:"
|
831 |
- ls -l $new $xserver_path
|
832 |
- rm -f $new
|
833 |
- fi
|
834 |
- fi
|
835 |
- if [ ! -e $new -o ! -s $new ]; then
|
836 |
- rm -f $new
|
837 |
- touch $new || exit 1
|
838 |
- chmod 700 $new || exit 1
|
839 |
- if [ ! -r $xserver_path ]; then
|
840 |
- warn ""
|
841 |
- warn "NEED TO COPY UNREADABLE $xserver_path to $new as root:"
|
842 |
- warn ""
|
843 |
- ls -l $xserver_path 1>&2
|
844 |
- warn ""
|
845 |
- warn "This only needs to be done once:"
|
846 |
- warn " cat $xserver_path > $new"
|
847 |
- warn ""
|
848 |
- nos=$nosudo
|
849 |
- if type sudo > /dev/null 2>&1; then
|
850 |
- :
|
851 |
- else
|
852 |
- nos=1
|
853 |
- fi
|
854 |
- if [ "X$nos" = "X1" ]; then
|
855 |
- warn "Please supply root passwd to 'su -c'"
|
856 |
- su -c "cat $xserver_path > $new"
|
857 |
- else
|
858 |
- warn "Please supply the sudo passwd if asked:"
|
859 |
- sudo /bin/sh -c "cat $xserver_path > $new"
|
860 |
- fi
|
861 |
- else
|
862 |
- warn ""
|
863 |
- warn "COPYING SETUID $xserver_path to $new"
|
864 |
- warn ""
|
865 |
- ls -l $xserver_path 1>&2
|
866 |
- warn ""
|
867 |
- cat $xserver_path > $new
|
868 |
- fi
|
869 |
- ls -l $new
|
870 |
- if [ -s $new ]; then
|
871 |
- :
|
872 |
- else
|
873 |
- rm -f $new
|
874 |
- ls -l $new
|
875 |
- exit 1
|
876 |
- fi
|
877 |
- warn ""
|
878 |
- warn "Please restart Xdummy now."
|
879 |
- exit 0
|
880 |
- fi
|
881 |
- if [ ! -O $new ]; then
|
882 |
- warn "file \"$new\" not owned by us!"
|
883 |
- ls -l $new
|
884 |
- exit 1
|
885 |
- fi
|
886 |
- xserver=$new
|
887 |
- fi
|
888 |
-fi
|
889 |
-
|
890 |
-# Work out display:
|
891 |
-#
|
892 |
-if [ "X$disp" != "X" ]; then
|
893 |
- :
|
894 |
-elif [ "X$1" != "X" ]; then
|
895 |
- if echo "$1" | grep '^:[0-9]' > /dev/null; then
|
896 |
- disp=$1
|
897 |
- shift
|
898 |
- elif [ "X$1" = "X:" ]; then
|
899 |
- # ":" means for us to find one.
|
900 |
- shift
|
901 |
- fi
|
902 |
-fi
|
903 |
-if [ "X$disp" = "X" -o "X$disp" = "X:" ]; then
|
904 |
- # try to find an open display port:
|
905 |
- # (tcp outdated...)
|
906 |
- ports=`netstat -ant | grep LISTEN | awk '{print $4}' | sed -e 's/^.*://'`
|
907 |
- n=0
|
908 |
- while [ $n -le 20 ]
|
909 |
- do
|
910 |
- port=`printf "60%02d" $n`
|
911 |
- if echo "$ports" | grep "^${port}\$" > /dev/null; then
|
912 |
- :
|
913 |
- else
|
914 |
- disp=":$n"
|
915 |
- warn "$program: auto-selected DISPLAY $disp"
|
916 |
- break
|
917 |
- fi
|
918 |
- n=`expr $n + 1`
|
919 |
- done
|
920 |
-fi
|
921 |
-
|
922 |
-# Work out which vt to use, try to find/guess an open one if necessary.
|
923 |
-#
|
924 |
-vt=""
|
925 |
-for arg in $*
|
926 |
-do
|
927 |
- if echo "$arg" | grep '^vt' > /dev/null; then
|
928 |
- vt=$arg
|
929 |
- break
|
930 |
- fi
|
931 |
-done
|
932 |
-if [ "X$vt" = "X" ]; then
|
933 |
- if [ "X$user" = "Xroot" ]; then
|
934 |
- # root can user fuser(1) to see if it is in use:
|
935 |
- if type fuser >/dev/null 2>&1; then
|
936 |
- # try /dev/tty17 thru /dev/tty32
|
937 |
- n=17
|
938 |
- while [ $n -le 32 ]
|
939 |
- do
|
940 |
- dev="/dev/tty$n"
|
941 |
- if fuser $dev >/dev/null 2>&1; then
|
942 |
- :
|
943 |
- else
|
944 |
- vt="vt$n"
|
945 |
- warn "$program: auto-selected VT $vt => $dev"
|
946 |
- break
|
947 |
- fi
|
948 |
- n=`expr $n + 1`
|
949 |
- done
|
950 |
- fi
|
951 |
- fi
|
952 |
- if [ "X$vt" = "X" ]; then
|
953 |
- # take a wild guess...
|
954 |
- vt=vt16
|
955 |
- warn "$program: selected fallback VT $vt"
|
956 |
- fi
|
957 |
-else
|
958 |
- vt=""
|
959 |
-fi
|
960 |
-
|
961 |
-# Decide flavor of Xserver:
|
962 |
-#
|
963 |
-stype=`basename "$xserver"`
|
964 |
-if echo "$stype" | grep -i xfree86 > /dev/null; then
|
965 |
- stype=xfree86
|
966 |
-else
|
967 |
- stype=xorg
|
968 |
-fi
|
969 |
-
|
970 |
-tweak_config() {
|
971 |
- in="$1"
|
972 |
- config2="$XDUMMY_TMPDIR/xdummy_modified_xconfig.conf"
|
973 |
- if [ "X$disp" != "X" ]; then
|
974 |
- d=`echo "$disp" | sed -e 's,/,,g' -e 's/:/_/g'`
|
975 |
- config2="$config2$d"
|
976 |
- fi
|
977 |
-
|
978 |
- # perl script to tweak the config file... add/delete options, etc.
|
979 |
- #
|
980 |
- env XDUMMY_GEOM=$geom \
|
981 |
- XDUMMY_DEPTH=$depth \
|
982 |
- XDUMMY_NOMODELINES=$nomodelines \
|
983 |
- perl > $config2 < $in -e '
|
984 |
- $n = 0;
|
985 |
- $geom = $ENV{XDUMMY_GEOM};
|
986 |
- $depth = $ENV{XDUMMY_DEPTH};
|
987 |
- $nomodelines = $ENV{XDUMMY_NOMODELINES};
|
988 |
- $mode_str = "";
|
989 |
- $videoram = "24000";
|
990 |
- $HorizSync = "30.0 - 130.0";
|
991 |
- $VertRefresh = "50.0 - 250.0";
|
992 |
- if ($geom ne "") {
|
993 |
- my $tmp = "";
|
994 |
- foreach $g (split(/,/, $geom)) {
|
995 |
- $tmp .= "\"$g\" ";
|
996 |
- if (!$nomodelines && $g =~ /(\d+)x(\d+)/) {
|
997 |
- my $w = $1;
|
998 |
- my $h = $2;
|
999 |
- $mode_str .= " Modeline \"$g\" ";
|
1000 |
- my $dot = sprintf("%.2f", $w * $h * 70 * 1.e-6);
|
1001 |
- $mode_str .= $dot;
|
1002 |
- $mode_str .= " " . $w;
|
1003 |
- $mode_str .= " " . int(1.02 * $w);
|
1004 |
- $mode_str .= " " . int(1.10 * $w);
|
1005 |
- $mode_str .= " " . int(1.20 * $w);
|
1006 |
- $mode_str .= " " . $h;
|
1007 |
- $mode_str .= " " . int($h + 1);
|
1008 |
- $mode_str .= " " . int($h + 3);
|
1009 |
- $mode_str .= " " . int($h + 20);
|
1010 |
- $mode_str .= "\n";
|
1011 |
- }
|
1012 |
- }
|
1013 |
- $tmp =~ s/\s*$//;
|
1014 |
- $geom = $tmp;
|
1015 |
- }
|
1016 |
- while (<>) {
|
1017 |
- if ($ENV{XDUMMY_NOTWEAK}) {
|
1018 |
- print $_;
|
1019 |
- next;
|
1020 |
- }
|
1021 |
- $n++;
|
1022 |
- if (/^\s*#/) {
|
1023 |
- # pass comments straight thru
|
1024 |
- print;
|
1025 |
- next;
|
1026 |
- }
|
1027 |
- if (/^\s*Section\s+(\S+)/i) {
|
1028 |
- # start of Section
|
1029 |
- $sect = $1;
|
1030 |
- $sect =~ s/\W//g;
|
1031 |
- $sect =~ y/A-Z/a-z/;
|
1032 |
- $sects{$sect} = 1;
|
1033 |
- print;
|
1034 |
- next;
|
1035 |
- }
|
1036 |
- if (/^\s*EndSection/i) {
|
1037 |
- # end of Section
|
1038 |
- if ($sect eq "serverflags") {
|
1039 |
- if (!$got_DontVTSwitch) {
|
1040 |
- print " ##Xdummy:##\n";
|
1041 |
- print " Option \"DontVTSwitch\" \"true\"\n";
|
1042 |
- }
|
1043 |
- if (!$got_AllowMouseOpenFail) {
|
1044 |
- print " ##Xdummy:##\n";
|
1045 |
- print " Option \"AllowMouseOpenFail\" \"true\"\n";
|
1046 |
- }
|
1047 |
- if (!$got_PciForceNone) {
|
1048 |
- print " ##Xdummy:##\n";
|
1049 |
- print " Option \"PciForceNone\" \"true\"\n";
|
1050 |
- }
|
1051 |
- } elsif ($sect eq "device") {
|
1052 |
- if (!$got_Driver) {
|
1053 |
- print " ##Xdummy:##\n";
|
1054 |
- print " Driver \"dummy\"\n";
|
1055 |
- }
|
1056 |
- if (!$got_VideoRam) {
|
1057 |
- print " ##Xdummy:##\n";
|
1058 |
- print " VideoRam $videoram\n";
|
1059 |
- }
|
1060 |
- } elsif ($sect eq "screen") {
|
1061 |
- if ($depth ne "" && !got_DefaultDepth) {
|
1062 |
- print " ##Xdummy:##\n";
|
1063 |
- print " DefaultDepth $depth\n";
|
1064 |
- }
|
1065 |
- if ($got_Monitor eq "") {
|
1066 |
- print " ##Xdummy:##\n";
|
1067 |
- print " Monitor \"Monitor0\"\n";
|
1068 |
- }
|
1069 |
- } elsif ($sect eq "monitor") {
|
1070 |
- if (!got_HorizSync) {
|
1071 |
- print " ##Xdummy:##\n";
|
1072 |
- print " HorizSync $HorizSync\n";
|
1073 |
- }
|
1074 |
- if (!got_VertRefresh) {
|
1075 |
- print " ##Xdummy:##\n";
|
1076 |
- print " VertRefresh $VertRefresh\n";
|
1077 |
- }
|
1078 |
- if (!$nomodelines) {
|
1079 |
- print " ##Xdummy:##\n";
|
1080 |
- print $mode_str;
|
1081 |
- }
|
1082 |
- }
|
1083 |
- $sect = "";
|
1084 |
- print;
|
1085 |
- next;
|
1086 |
- }
|
1087 |
-
|
1088 |
- if (/^\s*SubSection\s+(\S+)/i) {
|
1089 |
- # start of Section
|
1090 |
- $subsect = $1;
|
1091 |
- $subsect =~ s/\W//g;
|
1092 |
- $subsect =~ y/A-Z/a-z/;
|
1093 |
- $subsects{$subsect} = 1;
|
1094 |
- if ($sect eq "screen" && $subsect eq "display") {
|
1095 |
- $got_Modes = 0;
|
1096 |
- }
|
1097 |
- print;
|
1098 |
- next;
|
1099 |
- }
|
1100 |
- if (/^\s*EndSubSection/i) {
|
1101 |
- # end of SubSection
|
1102 |
- if ($sect eq "screen") {
|
1103 |
- if ($subsect eq "display") {
|
1104 |
- if ($depth ne "" && !$set_Depth) {
|
1105 |
- print " ##Xdummy:##\n";
|
1106 |
- print " Depth\t$depth\n";
|
1107 |
- }
|
1108 |
- if ($geom ne "" && ! $got_Modes) {
|
1109 |
- print " ##Xdummy:##\n";
|
1110 |
- print " Modes\t$geom\n";
|
1111 |
- }
|
1112 |
- }
|
1113 |
- }
|
1114 |
- $subsect = "";
|
1115 |
- print;
|
1116 |
- next;
|
1117 |
- }
|
1118 |
-
|
1119 |
- $l = $_;
|
1120 |
- $l =~ s/#.*$//;
|
1121 |
- if ($sect eq "serverflags") {
|
1122 |
- if ($l =~ /^\s*Option.*DontVTSwitch/i) {
|
1123 |
- $_ =~ s/false/true/ig;
|
1124 |
- $got_DontVTSwitch = 1;
|
1125 |
- }
|
1126 |
- if ($l =~ /^\s*Option.*AllowMouseOpenFail/i) {
|
1127 |
- $_ =~ s/false/true/ig;
|
1128 |
- $got_AllowMouseOpenFail = 1;
|
1129 |
- }
|
1130 |
- if ($l =~ /^\s*Option.*PciForceNone/i) {
|
1131 |
- $_ =~ s/false/true/ig;
|
1132 |
- $got_PciForceNone= 1;
|
1133 |
- }
|
1134 |
- }
|
1135 |
- if ($sect eq "module") {
|
1136 |
- if ($l =~ /^\s*Load.*\b(dri|fbdevhw)\b/i) {
|
1137 |
- $_ = "##Xdummy## $_";
|
1138 |
- }
|
1139 |
- }
|
1140 |
- if ($sect eq "monitor") {
|
1141 |
- if ($l =~ /^\s*HorizSync/i) {
|
1142 |
- $got_HorizSync = 1;
|
1143 |
- }
|
1144 |
- if ($l =~ /^\s*VertRefresh/i) {
|
1145 |
- $got_VertRefresh = 1;
|
1146 |
- }
|
1147 |
- }
|
1148 |
- if ($sect eq "device") {
|
1149 |
- if ($l =~ /^(\s*Driver)\b/i) {
|
1150 |
- $_ = "$1 \"dummy\"\n";
|
1151 |
- $got_Driver = 1;
|
1152 |
- }
|
1153 |
- if ($l =~ /^\s*VideoRam/i) {
|
1154 |
- $got_VideoRam= 1;
|
1155 |
- }
|
1156 |
- }
|
1157 |
- if ($sect eq "inputdevice") {
|
1158 |
- if ($l =~ /^\s*Option.*\bDevice\b/i) {
|
1159 |
- print " ##Xdummy:##\n";
|
1160 |
- $_ = " Option \"Device\" \"/dev/dilbert$n\"\n";
|
1161 |
- }
|
1162 |
- }
|
1163 |
- if ($sect eq "screen") {
|
1164 |
- if ($l =~ /^\s*DefaultDepth\s+(\d+)/i) {
|
1165 |
- if ($depth ne "") {
|
1166 |
- print " ##Xdummy:##\n";
|
1167 |
- $_ = " DefaultDepth\t$depth\n";
|
1168 |
- }
|
1169 |
- $got_DefaultDepth = 1;
|
1170 |
- }
|
1171 |
- if ($l =~ /^\s*Monitor\s+(\S+)/i) {
|
1172 |
- $got_Monitor = $1;
|
1173 |
- $got_Monitor =~ s/"//g;
|
1174 |
- }
|
1175 |
- if ($subsect eq "display") {
|
1176 |
- if ($geom ne "") {
|
1177 |
- if ($l =~ /^(\s*Modes)\b/i) {
|
1178 |
- print " ##Xdummy:##\n";
|
1179 |
- $_ = "$1 $geom\n";
|
1180 |
- $got_Modes = 1;
|
1181 |
- }
|
1182 |
- }
|
1183 |
- if ($l =~ /^\s*Depth\s+(\d+)/i) {
|
1184 |
- my $d = $1;
|
1185 |
- if (!$set_Depth && $depth ne "") {
|
1186 |
- $set_Depth = 1;
|
1187 |
- if ($depth != $d) {
|
1188 |
- print " ##Xdummy:##\n";
|
1189 |
- $_ = " Depth\t$depth\n";
|
1190 |
- }
|
1191 |
- }
|
1192 |
- }
|
1193 |
- }
|
1194 |
- }
|
1195 |
- print;
|
1196 |
- }
|
1197 |
- if ($ENV{XDUMMY_NOTWEAK}) {
|
1198 |
- exit;
|
1199 |
- }
|
1200 |
- # create any crucial sections that are missing:
|
1201 |
- if (! exists($sects{serverflags})) {
|
1202 |
- print "\n##Xdummy:##\n";
|
1203 |
- print "Section \"ServerFlags\"\n";
|
1204 |
- print " Option \"DontVTSwitch\" \"true\"\n";
|
1205 |
- print " Option \"AllowMouseOpenFail\" \"true\"\n";
|
1206 |
- print " Option \"PciForceNone\" \"true\"\n";
|
1207 |
- print "EndSection\n";
|
1208 |
- }
|
1209 |
- if (! exists($sects{device})) {
|
1210 |
- print "\n##Xdummy:##\n";
|
1211 |
- print "Section \"Device\"\n";
|
1212 |
- print " Identifier \"Videocard0\"\n";
|
1213 |
- print " Driver \"dummy\"\n";
|
1214 |
- print " VideoRam $videoram\n";
|
1215 |
- print "EndSection\n";
|
1216 |
- }
|
1217 |
- if (! exists($sects{monitor})) {
|
1218 |
- print "\n##Xdummy:##\n";
|
1219 |
- print "Section \"Monitor\"\n";
|
1220 |
- print " Identifier \"Monitor0\"\n";
|
1221 |
- print " HorizSync $HorizSync\n";
|
1222 |
- print " VertRefresh $VertRefresh\n";
|
1223 |
- print "EndSection\n";
|
1224 |
- }
|
1225 |
- if (! exists($sects{screen})) {
|
1226 |
- print "\n##Xdummy:##\n";
|
1227 |
- print "Section \"Screen\"\n";
|
1228 |
- print " Identifier \"Screen0\"\n";
|
1229 |
- print " Device \"Videocard0\"\n";
|
1230 |
- if ($got_Monitor ne "") {
|
1231 |
- print " Monitor \"$got_Monitor\"\n";
|
1232 |
- } else {
|
1233 |
- print " Monitor \"Monitor0\"\n";
|
1234 |
- }
|
1235 |
- if ($depth ne "") {
|
1236 |
- print " DefaultDepth $depth\n";
|
1237 |
- } else {
|
1238 |
- print " DefaultDepth 24\n";
|
1239 |
- }
|
1240 |
- print " SubSection \"Display\"\n";
|
1241 |
- print " Viewport 0 0\n";
|
1242 |
- print " Depth 24\n";
|
1243 |
- if ($got_Modes) {
|
1244 |
- ;
|
1245 |
- } elsif ($geom ne "") {
|
1246 |
- print " Modes $geom\n";
|
1247 |
- } else {
|
1248 |
- print " Modes \"1280x1024\" \"1024x768\" \"800x600\"\n";
|
1249 |
- }
|
1250 |
- print " EndSubSection\n";
|
1251 |
- print "EndSection\n";
|
1252 |
- }
|
1253 |
-';
|
1254 |
-}
|
1255 |
-
|
1256 |
-# Work out config file and tweak it.
|
1257 |
-#
|
1258 |
-if [ "X$cmdline_config" = "X" ]; then
|
1259 |
- :
|
1260 |
-elif [ "X$cmdline_config" = "Xxdummy-builtin" ]; then
|
1261 |
- :
|
1262 |
-elif echo "$cmdline_config" | grep '/' > /dev/null; then
|
1263 |
- :
|
1264 |
-else
|
1265 |
- # ignore basename only case (let server handle it)
|
1266 |
- cmdline_config=""
|
1267 |
- notweak=1
|
1268 |
-fi
|
1269 |
-
|
1270 |
-config=$cmdline_config
|
1271 |
-
|
1272 |
-if [ "X$notweak" = "X1" -a "X$root" = "X" -a -f "$cmdline_config" ]; then
|
1273 |
- # if not root we need to copy (but not tweak) the specified config.
|
1274 |
- XDUMMY_NOTWEAK=1
|
1275 |
- export XDUMMY_NOTWEAK
|
1276 |
- notweak=""
|
1277 |
-fi
|
1278 |
-
|
1279 |
-if [ ! $notweak ]; then
|
1280 |
- # tweaked config will be put in $config2:
|
1281 |
- config2=""
|
1282 |
- if [ "X$config" = "X" ]; then
|
1283 |
- # use the default one:
|
1284 |
- if [ "X$stype" = "Xxorg" ]; then
|
1285 |
- config=/etc/X11/xorg.conf
|
1286 |
- else
|
1287 |
- if [ -f "/etc/X11/XF86Config-4" ]; then
|
1288 |
- config="/etc/X11/XF86Config-4"
|
1289 |
- else
|
1290 |
- config="/etc/X11/XF86Config"
|
1291 |
- fi
|
1292 |
- fi
|
1293 |
- if [ ! -f "$config" ]; then
|
1294 |
- for c in /etc/X11/xorg.conf /etc/X11/XF86Config-4 /etc/X11/XF86Config
|
1295 |
- do
|
1296 |
- if [ -f $c ]; then
|
1297 |
- config=$c
|
1298 |
- break
|
1299 |
- fi
|
1300 |
- done
|
1301 |
- fi
|
1302 |
- fi
|
1303 |
-
|
1304 |
- if [ "X$config" = "Xxdummy-builtin" ]; then
|
1305 |
- config=""
|
1306 |
- fi
|
1307 |
-
|
1308 |
- if [ ! -f "$config" ]; then
|
1309 |
- config="$XDUMMY_TMPDIR/xorg.conf"
|
1310 |
- warn "$program: using minimal built-in xorg.conf settings."
|
1311 |
- cat > $config <<END
|
1312 |
-
|
1313 |
-Section "ServerLayout"
|
1314 |
- Identifier "Layout0"
|
1315 |
- Screen 0 "Screen0"
|
1316 |
- InputDevice "Keyboard0" "CoreKeyboard"
|
1317 |
- InputDevice "Mouse0" "CorePointer"
|
1318 |
-EndSection
|
1319 |
-
|
1320 |
-Section "Files"
|
1321 |
-EndSection
|
1322 |
-
|
1323 |
-Section "Module"
|
1324 |
- Load "dbe"
|
1325 |
- Load "extmod"
|
1326 |
- Load "freetype"
|
1327 |
- Load "glx"
|
1328 |
-EndSection
|
1329 |
-
|
1330 |
-Section "InputDevice"
|
1331 |
- Identifier "Mouse0"
|
1332 |
- Driver "mouse"
|
1333 |
- Option "Protocol" "auto"
|
1334 |
- Option "Device" "/dev/psaux"
|
1335 |
- Option "Emulate3Buttons" "no"
|
1336 |
- Option "ZAxisMapping" "4 5"
|
1337 |
-EndSection
|
1338 |
-
|
1339 |
-Section "InputDevice"
|
1340 |
- Identifier "Keyboard0"
|
1341 |
- Driver "kbd"
|
1342 |
-EndSection
|
1343 |
-
|
1344 |
-Section "Monitor"
|
1345 |
- Identifier "Monitor0"
|
1346 |
- VendorName "Unknown"
|
1347 |
- ModelName "Unknown"
|
1348 |
- HorizSync 30.0 - 130.0
|
1349 |
- VertRefresh 50.0 - 250.0
|
1350 |
- Option "DPMS"
|
1351 |
-EndSection
|
1352 |
-
|
1353 |
-Section "Device"
|
1354 |
- Identifier "Device0"
|
1355 |
- Driver "foovideo"
|
1356 |
- VendorName "foovideo Corporation"
|
1357 |
-EndSection
|
1358 |
-
|
1359 |
-Section "Screen"
|
1360 |
- Identifier "Screen0"
|
1361 |
- Device "Device0"
|
1362 |
- Monitor "Monitor0"
|
1363 |
- DefaultDepth 24
|
1364 |
- SubSection "Display"
|
1365 |
- Depth 24
|
1366 |
- Modes "1280x1024"
|
1367 |
- EndSubSection
|
1368 |
-EndSection
|
1369 |
-
|
1370 |
-END
|
1371 |
- fi
|
1372 |
-
|
1373 |
- if [ -f "$config" ]; then
|
1374 |
- tweak_config $config
|
1375 |
- fi
|
1376 |
-
|
1377 |
- # now we need to get our tweaked config file onto the command line:
|
1378 |
- if [ "X$cmdline_config" = "X" ]; then
|
1379 |
- # append to cmdline (FUBAR will be substituted below.)
|
1380 |
- if [ "X$stype" = "Xxorg" ]; then
|
1381 |
- args="$args -config FUBAR"
|
1382 |
- else
|
1383 |
- args="$args -xf86config FUBAR"
|
1384 |
- fi
|
1385 |
- fi
|
1386 |
- if [ "X$config2" != "X" ]; then
|
1387 |
- # or modify $args:
|
1388 |
- c2=$config2
|
1389 |
- if [ "X$root" = "X" ]; then
|
1390 |
- # ordinary user cannot use absolute path.
|
1391 |
- c2=`basename $config2`
|
1392 |
- fi
|
1393 |
- args=`echo "$args" | sed \
|
1394 |
- -e "s,-config *[^ ][^ ]*,-config $c2,g" \
|
1395 |
- -e "s,-xf86config *[^ ][^ ]*,-xf86config $c2,g"`
|
1396 |
- fi
|
1397 |
-fi
|
1398 |
-
|
1399 |
-if [ $prconf ]; then
|
1400 |
- warn ""
|
1401 |
- warn "Printing out the Xorg/XFree86 server config file:"
|
1402 |
- warn ""
|
1403 |
- if [ "X$config2" = "X" ]; then
|
1404 |
- warn "NO CONFIG GENERATED."
|
1405 |
- exit 1
|
1406 |
- else
|
1407 |
- cat "$config2"
|
1408 |
- fi
|
1409 |
- exit 0
|
1410 |
-fi
|
1411 |
-
|
1412 |
-if [ $debug ]; then
|
1413 |
- XDUMMY_DEBUG=1
|
1414 |
- export XDUMMY_DEBUG
|
1415 |
-fi
|
1416 |
-if [ $root ]; then
|
1417 |
- XDUMMY_ROOT=1
|
1418 |
- export XDUMMY_ROOT
|
1419 |
-fi
|
1420 |
-
|
1421 |
-# Finally, run it:
|
1422 |
-#
|
1423 |
-if [ "X$debug" != "X" -o "X$runit" = "X" ]; then
|
1424 |
- if [ ! $runit ]; then
|
1425 |
- echo ""
|
1426 |
- echo "/usr/bin/env:"
|
1427 |
- env | egrep -v '^(LS_COLORS|TERMCAP)' | sort
|
1428 |
- echo ""
|
1429 |
- echo "XDUMMY*:"
|
1430 |
- env | grep '^XDUMMY' | sort
|
1431 |
- echo ""
|
1432 |
- fi
|
1433 |
- warn ""
|
1434 |
- warn "The command to run is:"
|
1435 |
- warn ""
|
1436 |
- so=$SO
|
1437 |
- pwd=`pwd`
|
1438 |
- if echo "$so" | grep '^\./' > /dev/null; then
|
1439 |
- so=`echo "$so" | sed -e "s,^\.,$pwd,"`
|
1440 |
- fi
|
1441 |
- if echo "$so" | grep '/' > /dev/null; then
|
1442 |
- :
|
1443 |
- else
|
1444 |
- so="$pwd/$so"
|
1445 |
- fi
|
1446 |
- warn "env LD_PRELOAD=$so $xserver $disp $args $vt"
|
1447 |
- warn ""
|
1448 |
- if [ ! $runit ]; then
|
1449 |
- exit 0
|
1450 |
- fi
|
1451 |
-fi
|
1452 |
-
|
1453 |
-if [ $strace ]; then
|
1454 |
- if [ "X$strace" = "X2" ]; then
|
1455 |
- ltrace -f env LD_PRELOAD=$SO $xserver $disp $args $vt
|
1456 |
- else
|
1457 |
- strace -f env LD_PRELOAD=$SO $xserver $disp $args $vt
|
1458 |
- fi
|
1459 |
-else
|
1460 |
- exec env LD_PRELOAD=$SO $xserver $disp $args $vt
|
1461 |
-fi
|
1462 |
-
|
1463 |
-exit $?
|
1464 |
-
|
1465 |
-#########################################################################
|
1466 |
-
|
1467 |
-code() {
|
1468 |
-#code_begin
|
1469 |
-#include <stdio.h>
|
1470 |
-#define O_ACCMODE 0003
|
1471 |
-#define O_RDONLY 00
|
1472 |
-#define O_WRONLY 01
|
1473 |
-#define O_RDWR 02
|
1474 |
-#define O_CREAT 0100 /* not fcntl */
|
1475 |
-#define O_EXCL 0200 /* not fcntl */
|
1476 |
-#define O_NOCTTY 0400 /* not fcntl */
|
1477 |
-#define O_TRUNC 01000 /* not fcntl */
|
1478 |
-#define O_APPEND 02000
|
1479 |
-#define O_NONBLOCK 04000
|
1480 |
-#define O_NDELAY O_NONBLOCK
|
1481 |
-#define O_SYNC 010000
|
1482 |
-#define O_FSYNC O_SYNC
|
1483 |
-#define O_ASYNC 020000
|
1484 |
-
|
1485 |
-#include <unistd.h>
|
1486 |
-#include <stdlib.h>
|
1487 |
-#include <string.h>
|
1488 |
-
|
1489 |
-#include <linux/vt.h>
|
1490 |
-#include <linux/kd.h>
|
1491 |
-
|
1492 |
-#define __USE_GNU
|
1493 |
-#include <dlfcn.h>
|
1494 |
-
|
1495 |
-static char tmpdir[4096];
|
1496 |
-static char str1[4096];
|
1497 |
-static char str2[4096];
|
1498 |
-
|
1499 |
-static char devs[256][1024];
|
1500 |
-static int debug = -1;
|
1501 |
-static int root = -1;
|
1502 |
-static int changed_uid = 0;
|
1503 |
-static int saw_fonts = 0;
|
1504 |
-static int saw_lib_modules = 0;
|
1505 |
-
|
1506 |
-static time_t start = 0;
|
1507 |
-
|
1508 |
-void check_debug(void) {
|
1509 |
- if (debug < 0) {
|
1510 |
- if (getenv("XDUMMY_DEBUG") != NULL) {
|
1511 |
- debug = 1;
|
1512 |
- } else {
|
1513 |
- debug = 0;
|
1514 |
- }
|
1515 |
- /* prevent other processes using the preload: */
|
1516 |
- putenv("LD_PRELOAD=");
|
1517 |
- }
|
1518 |
-}
|
1519 |
-void check_root(void) {
|
1520 |
- if (root < 0) {
|
1521 |
- /* script tells us if we are root */
|
1522 |
- if (getenv("XDUMMY_ROOT") != NULL) {
|
1523 |
- root = 1;
|
1524 |
- } else {
|
1525 |
- root = 0;
|
1526 |
- }
|
1527 |
- }
|
1528 |
-}
|
1529 |
-
|
1530 |
-void check_uid(void) {
|
1531 |
- if (start == 0) {
|
1532 |
- start = time(NULL);
|
1533 |
- if (debug) fprintf(stderr, "START: %u\n", (unsigned int) start);
|
1534 |
- return;
|
1535 |
- } else if (changed_uid == 0) {
|
1536 |
- if (saw_fonts || time(NULL) > start + 20) {
|
1537 |
- if (getenv("XDUMMY_UID")) {
|
1538 |
- int uid = atoi(getenv("XDUMMY_UID"));
|
1539 |
- if (debug) fprintf(stderr, "SETREUID: %d saw_fonts=%d\n", uid, saw_fonts);
|
1540 |
- if (uid >= 0) {
|
1541 |
- /* this will simply fail in -nonroot mode: */
|
1542 |
- setreuid(uid, -1);
|
1543 |
- }
|
1544 |
- }
|
1545 |
- changed_uid = 1;
|
1546 |
- }
|
1547 |
- }
|
1548 |
-}
|
1549 |
-
|
1550 |
-#define CHECKIT if (debug < 0) check_debug(); \
|
1551 |
- if (root < 0) check_root(); \
|
1552 |
- check_uid();
|
1553 |
-
|
1554 |
-static void set_tmpdir(void) {
|
1555 |
- char *s;
|
1556 |
- static int didset = 0;
|
1557 |
- if (didset) {
|
1558 |
- return;
|
1559 |
- }
|
1560 |
- s = getenv("XDUMMY_TMPDIR");
|
1561 |
- if (! s) {
|
1562 |
- s = "/tmp";
|
1563 |
- }
|
1564 |
- tmpdir[0] = '\0';
|
1565 |
- strcat(tmpdir, s);
|
1566 |
- strcat(tmpdir, "/");
|
1567 |
- didset = 1;
|
1568 |
-}
|
1569 |
-
|
1570 |
-static char *tmpdir_path(const char *path) {
|
1571 |
- char *str;
|
1572 |
- set_tmpdir();
|
1573 |
- strcpy(str2, path);
|
1574 |
- str = str2;
|
1575 |
- while (*str) {
|
1576 |
- if (*str == '/') {
|
1577 |
- *str = '_';
|
1578 |
- }
|
1579 |
- str++;
|
1580 |
- }
|
1581 |
- strcpy(str1, tmpdir);
|
1582 |
- strcat(str1, str2);
|
1583 |
- return str1;
|
1584 |
-}
|
1585 |
-
|
1586 |
-int open(const char *pathname, int flags, unsigned short mode) {
|
1587 |
- int fd;
|
1588 |
- char *store_dev = NULL;
|
1589 |
- static int (*real_open)(const char *, int , unsigned short) = NULL;
|
1590 |
-
|
1591 |
- CHECKIT
|
1592 |
- if (! real_open) {
|
1593 |
- real_open = (int (*)(const char *, int , unsigned short))
|
1594 |
- dlsym(RTLD_NEXT, "open");
|
1595 |
- }
|
1596 |
-
|
1597 |
- if (strstr(pathname, "lib/modules/")) {
|
1598 |
- /* not currently used. */
|
1599 |
- saw_lib_modules = 1;
|
1600 |
- }
|
1601 |
-
|
1602 |
- if (!root) {
|
1603 |
- if (strstr(pathname, "/dev/") == pathname) {
|
1604 |
- store_dev = strdup(pathname);
|
1605 |
- }
|
1606 |
- if (strstr(pathname, "/dev/tty") == pathname && strcmp(pathname, "/dev/tty")) {
|
1607 |
- pathname = tmpdir_path(pathname);
|
1608 |
- if (debug) fprintf(stderr, "OPEN: %s -> %s (as FIFO)\n", store_dev, pathname);
|
1609 |
- /* we make it a FIFO so ioctl on it does not fail */
|
1610 |
- unlink(pathname);
|
1611 |
- mkfifo(pathname, 0666);
|
1612 |
- } else if (0) {
|
1613 |
- /* we used to handle more /dev files ... */
|
1614 |
- fd = real_open(pathname, O_WRONLY|O_CREAT, 0777);
|
1615 |
- close(fd);
|
1616 |
- }
|
1617 |
- }
|
1618 |
-
|
1619 |
- fd = real_open(pathname, flags, mode);
|
1620 |
-
|
1621 |
- if (debug) fprintf(stderr, "OPEN: %s %d %d fd=%d\n", pathname, flags, mode, fd);
|
1622 |
-
|
1623 |
- if (! root) {
|
1624 |
- if (store_dev) {
|
1625 |
- if (fd < 256) {
|
1626 |
- strcpy(devs[fd], store_dev);
|
1627 |
- }
|
1628 |
- free(store_dev);
|
1629 |
- }
|
1630 |
- }
|
1631 |
-
|
1632 |
- return(fd);
|
1633 |
-}
|
1634 |
-
|
1635 |
-int open64(const char *pathname, int flags, unsigned short mode) {
|
1636 |
- int fd;
|
1637 |
-
|
1638 |
- CHECKIT
|
1639 |
- if (debug) fprintf(stderr, "OPEN64: %s %d %d\n", pathname, flags, mode);
|
1640 |
-
|
1641 |
- fd = open(pathname, flags, mode);
|
1642 |
- return(fd);
|
1643 |
-}
|
1644 |
-
|
1645 |
-int rename(const char *oldpath, const char *newpath) {
|
1646 |
- static int (*real_rename)(const char *, const char *) = NULL;
|
1647 |
-
|
1648 |
- CHECKIT
|
1649 |
- if (! real_rename) {
|
1650 |
- real_rename = (int (*)(const char *, const char *))
|
1651 |
- dlsym(RTLD_NEXT, "rename");
|
1652 |
- }
|
1653 |
-
|
1654 |
- if (debug) fprintf(stderr, "RENAME: %s %s\n", oldpath, newpath);
|
1655 |
-
|
1656 |
- if (root) {
|
1657 |
- return(real_rename(oldpath, newpath));
|
1658 |
- }
|
1659 |
-
|
1660 |
- if (strstr(oldpath, "/var/log") == oldpath) {
|
1661 |
- if (debug) fprintf(stderr, "RENAME: returning 0\n");
|
1662 |
- return 0;
|
1663 |
- }
|
1664 |
- return(real_rename(oldpath, newpath));
|
1665 |
-}
|
1666 |
-
|
1667 |
-FILE *fopen(const char *pathname, const char *mode) {
|
1668 |
- static FILE* (*real_fopen)(const char *, const char *) = NULL;
|
1669 |
- char *str;
|
1670 |
-
|
1671 |
- if (! saw_fonts) {
|
1672 |
- if (strstr(pathname, "/fonts/")) {
|
1673 |
- if (strstr(pathname, "fonts.dir")) {
|
1674 |
- saw_fonts = 1;
|
1675 |
- } else if (strstr(pathname, "fonts.alias")) {
|
1676 |
- saw_fonts = 1;
|
1677 |
- }
|
1678 |
- }
|
1679 |
- }
|
1680 |
-
|
1681 |
- CHECKIT
|
1682 |
- if (! real_fopen) {
|
1683 |
- real_fopen = (FILE* (*)(const char *, const char *))
|
1684 |
- dlsym(RTLD_NEXT, "fopen");
|
1685 |
- }
|
1686 |
-
|
1687 |
- if (debug) fprintf(stderr, "FOPEN: %s %s\n", pathname, mode);
|
1688 |
-
|
1689 |
- if (strstr(pathname, "xdummy_modified_xconfig.conf")) {
|
1690 |
- /* make our config appear to be in /etc/X11, etc. */
|
1691 |
- char *q = strrchr(pathname, '/');
|
1692 |
- if (q != NULL && getenv("XDUMMY_TMPDIR") != NULL) {
|
1693 |
- strcpy(str1, getenv("XDUMMY_TMPDIR"));
|
1694 |
- strcat(str1, q);
|
1695 |
- if (debug) fprintf(stderr, "FOPEN: %s -> %s\n", pathname, str1);
|
1696 |
- pathname = str1;
|
1697 |
- }
|
1698 |
- }
|
1699 |
-
|
1700 |
- if (root) {
|
1701 |
- return(real_fopen(pathname, mode));
|
1702 |
- }
|
1703 |
-
|
1704 |
- str = (char *) pathname;
|
1705 |
- if (strstr(pathname, "/var/log") == pathname) {
|
1706 |
- str = tmpdir_path(pathname);
|
1707 |
- if (debug) fprintf(stderr, "FOPEN: %s -> %s\n", pathname, str);
|
1708 |
- }
|
1709 |
- return(real_fopen(str, mode));
|
1710 |
-}
|
1711 |
-
|
1712 |
-
|
1713 |
-#define RETURN0 if (debug) \
|
1714 |
- {fprintf(stderr, "IOCTL: covered %d 0x%x\n", fd, req);} return 0;
|
1715 |
-#define RETURN1 if (debug) \
|
1716 |
- {fprintf(stderr, "IOCTL: covered %d 0x%x\n", fd, req);} return -1;
|
1717 |
-
|
1718 |
-int ioctl(int fd, int req, void *ptr) {
|
1719 |
- static int closed_xf86Info_consoleFd = 0;
|
1720 |
- static int (*real_ioctl)(int, int , void *) = NULL;
|
1721 |
-
|
1722 |
- CHECKIT
|
1723 |
- if (! real_ioctl) {
|
1724 |
- real_ioctl = (int (*)(int, int , void *))
|
1725 |
- dlsym(RTLD_NEXT, "open");
|
1726 |
- }
|
1727 |
- if (debug) fprintf(stderr, "IOCTL: %d 0x%x %p\n", fd, req, ptr);
|
1728 |
-
|
1729 |
- /* based on xorg-x11-6.8.1-dualhead.patch */
|
1730 |
- if (req == VT_GETMODE) {
|
1731 |
- /* close(xf86Info.consoleFd) */
|
1732 |
- if (0 && ! closed_xf86Info_consoleFd) {
|
1733 |
- /* I think better not to close it... */
|
1734 |
- close(fd);
|
1735 |
- closed_xf86Info_consoleFd = 1;
|
1736 |
- }
|
1737 |
- RETURN0
|
1738 |
- } else if (req == VT_SETMODE) {
|
1739 |
- RETURN0
|
1740 |
- } else if (req == VT_GETSTATE) {
|
1741 |
- RETURN0
|
1742 |
- } else if (req == KDSETMODE) {
|
1743 |
- RETURN0
|
1744 |
- } else if (req == KDSETLED) {
|
1745 |
- RETURN0
|
1746 |
- } else if (req == KDGKBMODE) {
|
1747 |
- RETURN0
|
1748 |
- } else if (req == KDSKBMODE) {
|
1749 |
- RETURN0
|
1750 |
- } else if (req == VT_ACTIVATE) {
|
1751 |
- RETURN0
|
1752 |
- } else if (req == VT_WAITACTIVE) {
|
1753 |
- RETURN0
|
1754 |
- } else if (req == VT_RELDISP) {
|
1755 |
- if (ptr == (void *) 1) {
|
1756 |
- RETURN1
|
1757 |
- } else if (ptr == (void *) VT_ACKACQ) {
|
1758 |
- RETURN0
|
1759 |
- }
|
1760 |
- }
|
1761 |
-
|
1762 |
- return(real_ioctl(fd, req, ptr));
|
1763 |
-}
|
1764 |
-
|
1765 |
-typedef void (*sighandler_t)(int);
|
1766 |
-#define SIGUSR1 10
|
1767 |
-#define SIG_DFL ((sighandler_t)0)
|
1768 |
-
|
1769 |
-sighandler_t signal(int signum, sighandler_t handler) {
|
1770 |
- static sighandler_t (*real_signal)(int, sighandler_t) = NULL;
|
1771 |
-
|
1772 |
- CHECKIT
|
1773 |
- if (! real_signal) {
|
1774 |
- real_signal = (sighandler_t (*)(int, sighandler_t))
|
1775 |
- dlsym(RTLD_NEXT, "signal");
|
1776 |
- }
|
1777 |
-
|
1778 |
- if (debug) fprintf(stderr, "SIGNAL: %d %p\n", signum, handler);
|
1779 |
-
|
1780 |
- if (signum == SIGUSR1) {
|
1781 |
- if (debug) fprintf(stderr, "SIGNAL: skip SIGUSR1\n");
|
1782 |
- return SIG_DFL;
|
1783 |
- }
|
1784 |
-
|
1785 |
- return(real_signal(signum, handler));
|
1786 |
-}
|
1787 |
-
|
1788 |
-int close(int fd) {
|
1789 |
- static int (*real_close)(int) = NULL;
|
1790 |
-
|
1791 |
- CHECKIT
|
1792 |
- if (! real_close) {
|
1793 |
- real_close = (int (*)(int)) dlsym(RTLD_NEXT, "close");
|
1794 |
- }
|
1795 |
-
|
1796 |
- if (debug) fprintf(stderr, "CLOSE: %d\n", fd);
|
1797 |
- if (!root) {
|
1798 |
- if (fd < 256) {
|
1799 |
- devs[fd][0] = '\0';
|
1800 |
- }
|
1801 |
- }
|
1802 |
- return(real_close(fd));
|
1803 |
-}
|
1804 |
-
|
1805 |
-struct stat {
|
1806 |
- int foo;
|
1807 |
-};
|
1808 |
-
|
1809 |
-int stat(const char *path, struct stat *buf) {
|
1810 |
- static int (*real_stat)(const char *, struct stat *) = NULL;
|
1811 |
-
|
1812 |
- CHECKIT
|
1813 |
- if (! real_stat) {
|
1814 |
- real_stat = (int (*)(const char *, struct stat *))
|
1815 |
- dlsym(RTLD_NEXT, "stat");
|
1816 |
- }
|
1817 |
-
|
1818 |
- if (debug) fprintf(stderr, "STAT: %s\n", path);
|
1819 |
-
|
1820 |
- return(real_stat(path, buf));
|
1821 |
-}
|
1822 |
-
|
1823 |
-int stat64(const char *path, struct stat *buf) {
|
1824 |
- static int (*real_stat64)(const char *, struct stat *) = NULL;
|
1825 |
-
|
1826 |
- CHECKIT
|
1827 |
- if (! real_stat64) {
|
1828 |
- real_stat64 = (int (*)(const char *, struct stat *))
|
1829 |
- dlsym(RTLD_NEXT, "stat64");
|
1830 |
- }
|
1831 |
-
|
1832 |
- if (debug) fprintf(stderr, "STAT64: %s\n", path);
|
1833 |
-
|
1834 |
- return(real_stat64(path, buf));
|
1835 |
-}
|
1836 |
-
|
1837 |
-int chown(const char *path, uid_t owner, gid_t group) {
|
1838 |
- static int (*real_chown)(const char *, uid_t, gid_t) = NULL;
|
1839 |
-
|
1840 |
- CHECKIT
|
1841 |
- if (! real_chown) {
|
1842 |
- real_chown = (int (*)(const char *, uid_t, gid_t))
|
1843 |
- dlsym(RTLD_NEXT, "chown");
|
1844 |
- }
|
1845 |
-
|
1846 |
- if (root) {
|
1847 |
- return(real_chown(path, owner, group));
|
1848 |
- }
|
1849 |
-
|
1850 |
- if (debug) fprintf(stderr, "CHOWN: %s %d %d\n", path, owner, group);
|
1851 |
-
|
1852 |
- if (strstr(path, "/dev") == path) {
|
1853 |
- if (debug) fprintf(stderr, "CHOWN: return 0\n");
|
1854 |
- return 0;
|
1855 |
- }
|
1856 |
-
|
1857 |
- return(real_chown(path, owner, group));
|
1858 |
-}
|
1859 |
-
|
1860 |
-extern int *__errno_location (void);
|
1861 |
-#ifndef ENODEV
|
1862 |
-#define ENODEV 19
|
1863 |
-#endif
|
1864 |
-
|
1865 |
-int ioperm(unsigned long from, unsigned long num, int turn_on) {
|
1866 |
- static int (*real_ioperm)(unsigned long, unsigned long, int) = NULL;
|
1867 |
-
|
1868 |
- CHECKIT
|
1869 |
- if (! real_ioperm) {
|
1870 |
- real_ioperm = (int (*)(unsigned long, unsigned long, int))
|
1871 |
- dlsym(RTLD_NEXT, "ioperm");
|
1872 |
- }
|
1873 |
- if (debug) fprintf(stderr, "IOPERM: %d %d %d\n", (int) from, (int) num, turn_on);
|
1874 |
- if (root) {
|
1875 |
- return(real_ioperm(from, num, turn_on));
|
1876 |
- }
|
1877 |
- if (from == 0 && num == 1024 && turn_on == 1) {
|
1878 |
- /* we want xf86EnableIO to fail */
|
1879 |
- if (debug) fprintf(stderr, "IOPERM: setting ENODEV.\n");
|
1880 |
- *__errno_location() = ENODEV;
|
1881 |
- return -1;
|
1882 |
- }
|
1883 |
- return 0;
|
1884 |
-}
|
1885 |
-
|
1886 |
-int iopl(int level) {
|
1887 |
- static int (*real_iopl)(int) = NULL;
|
1888 |
-
|
1889 |
- CHECKIT
|
1890 |
- if (! real_iopl) {
|
1891 |
- real_iopl = (int (*)(int)) dlsym(RTLD_NEXT, "iopl");
|
1892 |
- }
|
1893 |
- if (debug) fprintf(stderr, "IOPL: %d\n", level);
|
1894 |
- if (root) {
|
1895 |
- return(real_iopl(level));
|
1896 |
- }
|
1897 |
- return 0;
|
1898 |
-}
|
1899 |
-
|
1900 |
-#ifdef INTERPOSE_GETUID
|
1901 |
-
|
1902 |
-/*
|
1903 |
- * we got things to work w/o pretending to be root.
|
1904 |
- * so we no longer interpose getuid(), etc.
|
1905 |
- */
|
1906 |
-
|
1907 |
-uid_t getuid(void) {
|
1908 |
- static uid_t (*real_getuid)(void) = NULL;
|
1909 |
- CHECKIT
|
1910 |
- if (! real_getuid) {
|
1911 |
- real_getuid = (uid_t (*)(void)) dlsym(RTLD_NEXT, "getuid");
|
1912 |
- }
|
1913 |
- if (root) {
|
1914 |
- return(real_getuid());
|
1915 |
- }
|
1916 |
- if (debug) fprintf(stderr, "GETUID: 0\n");
|
1917 |
- return 0;
|
1918 |
-}
|
1919 |
-uid_t geteuid(void) {
|
1920 |
- static uid_t (*real_geteuid)(void) = NULL;
|
1921 |
- CHECKIT
|
1922 |
- if (! real_geteuid) {
|
1923 |
- real_geteuid = (uid_t (*)(void)) dlsym(RTLD_NEXT, "geteuid");
|
1924 |
- }
|
1925 |
- if (root) {
|
1926 |
- return(real_geteuid());
|
1927 |
- }
|
1928 |
- if (debug) fprintf(stderr, "GETEUID: 0\n");
|
1929 |
- return 0;
|
1930 |
-}
|
1931 |
-uid_t geteuid_kludge1(void) {
|
1932 |
- static uid_t (*real_geteuid)(void) = NULL;
|
1933 |
- CHECKIT
|
1934 |
- if (! real_geteuid) {
|
1935 |
- real_geteuid = (uid_t (*)(void)) dlsym(RTLD_NEXT, "geteuid");
|
1936 |
- }
|
1937 |
- if (debug) fprintf(stderr, "GETEUID: 0 saw_libmodules=%d\n", saw_lib_modules);
|
1938 |
- if (root && !saw_lib_modules) {
|
1939 |
- return(real_geteuid());
|
1940 |
- } else {
|
1941 |
- saw_lib_modules = 0;
|
1942 |
- return 0;
|
1943 |
- }
|
1944 |
-}
|
1945 |
-
|
1946 |
-uid_t getuid32(void) {
|
1947 |
- static uid_t (*real_getuid32)(void) = NULL;
|
1948 |
- CHECKIT
|
1949 |
- if (! real_getuid32) {
|
1950 |
- real_getuid32 = (uid_t (*)(void)) dlsym(RTLD_NEXT, "getuid32");
|
1951 |
- }
|
1952 |
- if (root) {
|
1953 |
- return(real_getuid32());
|
1954 |
- }
|
1955 |
- if (debug) fprintf(stderr, "GETUID32: 0\n");
|
1956 |
- return 0;
|
1957 |
-}
|
1958 |
-uid_t geteuid32(void) {
|
1959 |
- static uid_t (*real_geteuid32)(void) = NULL;
|
1960 |
- CHECKIT
|
1961 |
- if (! real_geteuid32) {
|
1962 |
- real_geteuid32 = (uid_t (*)(void)) dlsym(RTLD_NEXT, "geteuid32");
|
1963 |
- }
|
1964 |
- if (root) {
|
1965 |
- return(real_geteuid32());
|
1966 |
- }
|
1967 |
- if (debug) fprintf(stderr, "GETEUID32: 0\n");
|
1968 |
- return 0;
|
1969 |
-}
|
1970 |
-
|
1971 |
-gid_t getgid(void) {
|
1972 |
- static gid_t (*real_getgid)(void) = NULL;
|
1973 |
- CHECKIT
|
1974 |
- if (! real_getgid) {
|
1975 |
- real_getgid = (gid_t (*)(void)) dlsym(RTLD_NEXT, "getgid");
|
1976 |
- }
|
1977 |
- if (root) {
|
1978 |
- return(real_getgid());
|
1979 |
- }
|
1980 |
- if (debug) fprintf(stderr, "GETGID: 0\n");
|
1981 |
- return 0;
|
1982 |
-}
|
1983 |
-gid_t getegid(void) {
|
1984 |
- static gid_t (*real_getegid)(void) = NULL;
|
1985 |
- CHECKIT
|
1986 |
- if (! real_getegid) {
|
1987 |
- real_getegid = (gid_t (*)(void)) dlsym(RTLD_NEXT, "getegid");
|
1988 |
- }
|
1989 |
- if (root) {
|
1990 |
- return(real_getegid());
|
1991 |
- }
|
1992 |
- if (debug) fprintf(stderr, "GETEGID: 0\n");
|
1993 |
- return 0;
|
1994 |
-}
|
1995 |
-gid_t getgid32(void) {
|
1996 |
- static gid_t (*real_getgid32)(void) = NULL;
|
1997 |
- CHECKIT
|
1998 |
- if (! real_getgid32) {
|
1999 |
- real_getgid32 = (gid_t (*)(void)) dlsym(RTLD_NEXT, "getgid32");
|
2000 |
- }
|
2001 |
- if (root) {
|
2002 |
- return(real_getgid32());
|
2003 |
- }
|
2004 |
- if (debug) fprintf(stderr, "GETGID32: 0\n");
|
2005 |
- return 0;
|
2006 |
-}
|
2007 |
-gid_t getegid32(void) {
|
2008 |
- static gid_t (*real_getegid32)(void) = NULL;
|
2009 |
- CHECKIT
|
2010 |
- if (! real_getegid32) {
|
2011 |
- real_getegid32 = (gid_t (*)(void)) dlsym(RTLD_NEXT, "getegid32");
|
2012 |
- }
|
2013 |
- if (root) {
|
2014 |
- return(real_getegid32());
|
2015 |
- }
|
2016 |
- if (debug) fprintf(stderr, "GETEGID32: 0\n");
|
2017 |
- return 0;
|
2018 |
-}
|
2019 |
-#endif
|
2020 |
-
|
2021 |
-#if 0
|
2022 |
-/* maybe we need to interpose on strcmp someday... here is the template */
|
2023 |
-int strcmp(const char *s1, const char *s2) {
|
2024 |
- static int (*real_strcmp)(const char *, const char *) = NULL;
|
2025 |
- CHECKIT
|
2026 |
- if (! real_strcmp) {
|
2027 |
- real_strcmp = (int (*)(const char *, const char *)) dlsym(RTLD_NEXT, "strcmp");
|
2028 |
- }
|
2029 |
- if (debug) fprintf(stderr, "STRCMP: '%s' '%s'\n", s1, s2);
|
2030 |
- return(real_strcmp(s1, s2));
|
2031 |
-}
|
2032 |
-#endif
|
2033 |
-
|
2034 |
-#code_end
|
2035 |
-}
|