Index: programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v retrieving revision 1.3 diff -u -d -r1.3 lnx_init.c --- programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c 14 Jan 2005 18:42:26 -0000 1.3 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c 25 Jan 2005 23:38:43 -0000 @@ -45,6 +45,8 @@ #endif static Bool KeepTty = FALSE; +static Bool VTSwitch = TRUE; +static Bool ShareVTs = FALSE; static int VTnum = -1; static int activeVT = -1; @@ -121,22 +123,37 @@ FatalError( "xf86OpenConsole: Cannot open /dev/tty0 (%s)\n", strerror(errno)); - if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || - (xf86Info.vtno == -1)) { - FatalError("xf86OpenConsole: Cannot find a free VT\n"); - } + if (ShareVTs) + { + if (ioctl(fd, VT_GETSTATE, &vts) == 0) + { + xf86Info.vtno = vts.v_active; + } else { + FatalError("xf86OpenConsole: Cannot find the current VT\n"); + } + } + else + { + if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || + (xf86Info.vtno == -1)) { + FatalError("xf86OpenConsole: Cannot find a free VT\n"); + } + } close(fd); } #ifdef USE_DEV_FB - fb_dev_name=getenv("FRAMEBUFFER"); - if (!fb_dev_name) - fb_dev_name="/dev/fb0current"; - if ((fbfd = open(fb_dev_name, O_RDONLY)) < 0) - FatalError("xf86OpenConsole: Cannot open %s (%s)\n", - fb_dev_name, strerror(errno)); - if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var)) - FatalError("xf86OpenConsole: Unable to get screen info\n"); + if (!ShareVTs) + { + fb_dev_name=getenv("FRAMEBUFFER"); + if (!fb_dev_name) + fb_dev_name="/dev/fb0current"; + if ((fbfd = open(fb_dev_name, O_RDONLY)) < 0) + FatalError("xf86OpenConsole: Cannot open %s (%s)\n", + fb_dev_name, strerror(errno)); + if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var)) + FatalError("xf86OpenConsole: Unable to get screen info\n"); + } #endif xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); @@ -158,25 +175,28 @@ xf86Info.vtno, strerror(errno)); } - /* - * Grab the vt ownership before we overwrite it. - * Hard coded /dev/tty0 into this function as well for below. - */ - if (!saveVtPerms()){ - xf86Msg(X_WARNING, - "xf86OpenConsole: Could not save ownership of VT\n"); - } + if (!ShareVTs) + { + /* + * Grab the vt ownership before we overwrite it. + * Hard coded /dev/tty0 into this function as well for below. + */ + if (!saveVtPerms()){ + xf86Msg(X_WARNING, + "xf86OpenConsole: Could not save ownership of VT\n"); + } - /* change ownership of the vt */ - chown(vtname, getuid(), getgid()); + /* change ownership of the vt */ + chown(vtname, getuid(), getgid()); - /* - * the current VT device we're running on is not "console", we want - * to grab all consoles too - * - * Why is this needed?? - */ - chown("/dev/tty0", getuid(), getgid()); + /* + * the current VT device we're running on is not "console", we want + * to grab all consoles too + * + * Why is this needed?? + */ + chown("/dev/tty0", getuid(), getgid()); + } /* * Linux doesn't switch to an active vt after the last close of a vt, @@ -199,72 +219,90 @@ } } - /* - * now get the VT - */ - SYSCALL(result = ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); - } + if (!ShareVTs) + { + /* + * now get the VT + */ + if (VTSwitch) + { + SYSCALL(result = ioctl(xf86Info.consoleFd, VT_ACTIVATE, + xf86Info.vtno)); + if (result != 0) + { + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); + } + } + + SYSCALL(result = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, + xf86Info.vtno)); + if (result != 0) + { + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); + } #if defined(DO_OS_FONTRESTORE) - lnx_savefont(); + lnx_savefont(); #endif - SYSCALL(result = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); - if (result < 0) - { - FatalError("xf86OpenConsole: VT_GETMODE failed\n"); - } + SYSCALL(result = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); + if (result < 0) + { + FatalError("xf86OpenConsole: VT_GETMODE failed\n"); + } - signal(SIGUSR1, xf86VTRequest); + signal(SIGUSR1, xf86VTRequest); - VT.mode = VT_PROCESS; - VT.relsig = SIGUSR1; - VT.acqsig = SIGUSR1; - if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) - { - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); - } - if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) - { - FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n"); - } + VT.mode = VT_PROCESS; + VT.relsig = SIGUSR1; + VT.acqsig = SIGUSR1; + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) + { + FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); + } + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) + { + FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n"); + } - /* we really should have a InitOSInputDevices() function instead - * of Init?$#*&Device(). So I just place it here */ + /* we really should have a InitOSInputDevices() function instead + * of Init?$#*&Device(). So I just place it here */ #ifdef USE_DEV_FB - /* copy info to new console */ - var.yoffset=0; - var.xoffset=0; - if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &var)) - FatalError("Unable to set screen info\n"); - close(fbfd); + /* copy info to new console */ + var.yoffset=0; + var.xoffset=0; + if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &var)) + FatalError("Unable to set screen info\n"); + close(fbfd); #endif + } + else + { + close(xf86Info.consoleFd); + } } else - { - /* serverGeneration != 1 */ - /* - * now get the VT - */ - SYSCALL(result = ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); - } + { + /* serverGeneration != 1 */ + + if (!ShareVTs && VTSwitch) + { + /* + * now get the VT + */ + SYSCALL(result = + ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); + if (result != 0) + { + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); + } + } + + SYSCALL(result = + ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); + if (result != 0) + { + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); + } } return; } @@ -276,7 +314,12 @@ #if defined(DO_OS_FONTRESTORE) struct vt_stat vts; int vtno = -1; +#endif + if (ShareVTs) + return; + +#if defined(DO_OS_FONTRESTORE) if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) == 0) vtno = vts.v_active; #endif @@ -292,19 +335,23 @@ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */ } - /* - * Perform a switch back to the active VT when we were started - */ - if (activeVT >= 0) + if (VTSwitch) { - ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT); - activeVT = -1; - } + /* + * Perform a switch back to the active VT when we were started + */ + if (activeVT >= 0) + { + ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT); + activeVT = -1; + } #if defined(DO_OS_FONTRESTORE) - if (xf86Info.vtno == vtno) - lnx_restorefont(); - lnx_freefontdata(); + if (xf86Info.vtno == vtno) + lnx_restorefont(); + lnx_freefontdata(); #endif + } + close(xf86Info.consoleFd); /* make the vt-manager happy */ restoreVtPerms(); /* restore the permissions */ @@ -324,6 +371,16 @@ KeepTty = TRUE; return(1); } + if (!strcmp(argv[i], "-novtswitch")) + { + VTSwitch = FALSE; + return(1); + } + if (!strcmp(argv[i], "-sharevts")) + { + ShareVTs = TRUE; + return(1); + } if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { if (sscanf(argv[i], "vt%2d", &VTnum) == 0) @@ -343,5 +400,7 @@ ErrorF("vtXX use the specified VT number\n"); ErrorF("-keeptty "); ErrorF("don't detach controlling tty (for debugging only)\n"); + ErrorF("-novtswitch don't immediately switch to new VT\n"); + ErrorF("-sharevts share VTs with another X server\n"); return; }