예제 #1
0
void xf86OpenConsole()
{
    int i, fd;

    if (serverGeneration == 1)
    {
        /* check if we're run with euid==0 */
        if (geteuid() != 0)
        {
            FatalError("xf86OpenConsole: Server must be running with root "
                       "permissions\n"
                       "You should be using Xwrapper to start the server or xdm.\n"
                       "We strongly advise against making the server SUID root!\n");
        }

        if (!KeepTty)
        {
#if BSD >= 199306
            if (RunFromSmartParent) {
                if (atexit(NonBlockConsoleOff))
                    ErrorF("InitOutput: can't register NBIO exit handler\n");
                i = fcntl(2, F_GETFL, 0);
                if (i >= 0)
                    i = fcntl(2, F_SETFL, i | FNDELAY);
                if (i < 0)
                    ErrorF("InitOutput: can't put stderr in non-block mode\n");
            }
#else
            /*
             * detaching the controlling tty solves problems of kbd character
             * loss.  This is not interesting for CO driver, because it is
             * exclusive.
             */
            setpgrp(0, getpid());
            if ((i = open("/dev/tty",O_RDWR)) >= 0)
            {
                ioctl(i,TIOCNOTTY,(char *)0);
                close(i);
            }
#endif
        }

        if ((xf86Info.consoleFd = open("/dev/kbd", O_RDWR|O_NDELAY,0)) < 0)
        {
            FatalError("xf86OpenConsole: Cannot open /dev/kbd (%s)\n",
                       strerror(errno));
        }
        if ((xf86Info.screenFd = open("/dev/vga", O_RDWR|O_NDELAY,0)) < 0)
        {
            FatalError("xf86OpenConsole: Cannot open /dev/vga (%s)\n",
                       strerror(errno));
        }

        xf86Config(FALSE); /* Read XF86Config */

        if (ioctl(xf86Info.consoleFd, PCCONIOCRAW, 0) < 0)
        {
            FatalError("%s: PCCONIOCRAW failed (%s)\n",
                       "xf86OpenConsole", strerror(errno));
        }
    }
    return;
}
예제 #2
0
void xf86OpenConsole()
{
    int i;
    int fd;
    char vtname[14];

    if (serverGeneration == 1) 
    {
    	/* check if we're run with euid==0 */
    	if (geteuid() != 0)
	{
      	    FatalError("xf86OpenConsole: Server must be suid root\n");
	}
	if (Protect0)
	{
	    int fd = -1;

	    if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0)
	    {
		ErrorF("xf86OpenConsole: cannot open /dev/zero (%s)\n",
		       strerror(errno));
	    }
	    else
	    {
		if ((int)mmap(0, 0x1000, PROT_NONE,
			      MAP_FIXED | MAP_SHARED, fd, 0) == -1)
		{
		    ErrorF("xf86OpenConsole: failed to protect page 0 (%s)\n",
		       strerror(errno));
		}
		close(fd);
	    }
	}
    	if (VTnum != -1) 
	{
      	    xf86Info.vtno = VTnum;
    	}
    	else 
	{
      	    if ((fd = open("/dev/console",O_WRONLY,0)) < 0) 
	    {
        	FatalError(
		    "xf86OpenConsole: Cannot open system tty (/dev/console), (%s)\n",
		    strerror(errno));
	    }
           close(fd);
        }
        xf86Info.vtno=0;
	ErrorF("   (Intel DG/ux: using VT number: systty%d)\n\n", xf86Info.vtno);

	sprintf(vtname,"/dev/console");

	xf86Config(FALSE); /* Read XF86Config */

	if (!KeepTty)
    	{
    	    setpgrp();
	}

	if ((xf86Info.consoleFd = open("/dev/console", O_RDWR|O_NDELAY, 0)) < 0)
	{
            FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
		       vtname, strerror(errno));
	}



        if ((xf86Info.kbdFd = open("/dev/keybd", O_RDONLY|O_NDELAY, 0)) < 0)
        {
            FatalError("xf86OpenConsole: Cannot open keyboard (/dev/keybd), (%s)\n", strerror(errno));
        }
	/* change ownerships and Grab all other system consoles  */
	chown(vtname, getuid(), getgid());
        chown("/dev/syscon", getuid(), getgid());
        chown("/dev/systty", getuid(), getgid());
        if (!KeepTty)
        {
            /*
             * Detach from the controlling tty to avoid char loss
             */
            if ((i = open("/dev/tty",O_RDWR)) >= 0)
            {
                ioctl(i, TIOCNOTTY, 0);
                close(i);
            }
        }
    }
    else 
    {   
	/* serverGeneration != 1 */
	if (!xf86VTSema)
	    sleep(5);
    }
    return;
}
예제 #3
0
void xf86OpenConsole()
{
    /* try to catch problems before they become obvious */
    os2_checkinstallation();

    if (serverGeneration == 1) {
	HKBD fd;
	ULONG drive;
	ULONG dummy;
	KBDHWID hwid;
	APIRET rc;
	int VioTid;
        ULONG actual_handles;
        LONG new_handles;

	/* hv 250197 workaround for xkb-Problem: switch to X11ROOT drive */
	char *x11r = getenv("X11ROOT");
        /* Make sure X11ROOT is set before we go further sm280297 */
        if (x11r == NULL){ 
           ErrorF("The environment variable X11ROOT is not set! The xserver is aborting.\n");	
           exit(1);  
           }
        if (_chdir2(x11r) < 0) {
		ErrorF("xf86-OS/2: Cannot change to X11ROOT directory!\n");
	}

	ErrorF("xf86-OS/2: Console opened\n");
	OriginalVideoMode.cb=sizeof(VIOMODEINFO);
	rc=VioGetMode(&OriginalVideoMode,(HVIO)0);
	if(rc!=0) ErrorF("xf86-OS/2: Could not get original video mode. RC=%d\n",rc);
	xf86Info.consoleFd = -1;
        
        /* Set the number of handles to higher than the default 20. Set to 80 which should be plenty */
        new_handles = 0;
        rc = DosSetRelMaxFH(&new_handles,&actual_handles);
        if (actual_handles < 80) {
		new_handles = 80 - actual_handles;
		rc = DosSetRelMaxFH(&new_handles,&actual_handles);
		ErrorF("xf86-OS/2: Increased number of available handles to %d\n",actual_handles);
	}

	/* grab the keyboard */
	rc = KbdGetFocus(0,0);
	if (rc != 0)
		FatalError("xf86OpenConsole: cannot grab kbd focus, rc=%d\n",rc);

	/* open the keyboard */
	rc = KbdOpen(&fd);
	if (rc != 0)
		FatalError("xf86OpenConsole: cannot open keyboard, rc=%d\n",rc);
	xf86Info.consoleFd = fd;

	ErrorF("xf86-OS/2: Keyboard opened\n");

	/* assign logical keyboard */
	KbdFreeFocus(0);
	rc = KbdGetFocus(0,fd);
	if (rc != 0)
		FatalError("xf86OpenConsole: cannot set local kbd focus, rc=%d\n",rc);

/* Create kbd queue semaphore */
 
         rc = DosCreateEventSem(NULL,&hKbdSem,DC_SEM_SHARED,TRUE);
         if (rc != 0)
                  FatalError("xf86OpenConsole: cannot create keyboard queue semaphore, rc=%d\n",rc);
 
/* Create popup semaphore */

	rc=DosCreateEventSem("\\SEM32\\XF86PUP",&hevPopupPending,DC_SEM_SHARED,1);
	if(rc) ErrorF("xf86-OS/2: Could not create popup semaphore! RC=%d\n",rc);
	/* rc=VioRegister("xf86vio","XF86POPUP_SUBCLASS",0x20002004L,0L);
	if(rc) {
		FatalError("xf86-OS2: Could not register XF86VIO.DLL module. Please install in LIBPATH! RC=%d\n",rc);
	}  */

/* Start up the VIO monitor thread */
	VioTid=_beginthread(os2VideoNotify,NULL,0x4000,(void *)NULL);
	ErrorF("xf86-OS/2: Started Vio thread, Tid=%d\n",VioTid);
	rc=DosSetPriority(2,3,0,VioTid);

/* Start up the hard-error VIO monitor thread */
	VioTid=_beginthread(os2HardErrorNotify,NULL,0x4000,(void *)NULL);
	ErrorF("xf86-OS/2: Started hard error Vio mode monitor thread, Tid=%d\n",VioTid);
	rc=DosSetPriority(2,3,0,VioTid);

/* Start up the kbd monitor thread */
	VioTid=_beginthread(os2KbdMonitorThread,NULL,0x4000,(void *)NULL);
	ErrorF("xf86-OS/2: Started Kbd monitor thread, Tid=%d\n",VioTid);
	rc=DosSetPriority(2,3,0,VioTid);

/* Disable hard-errors through DosError */
	rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
	rc = DosSuppressPopUps(0x0001L,drive+96);     /* Disable popups */
	
	rc = KbdSetCp(0,0,fd);
	if(rc != 0)
		FatalError("xf86-OS/2: xf86OpenConsole: cannot set keyboard codepage, rc=%d\n",rc);

	hwid.cb = sizeof(hwid);	/* fix crash on P9000 */
	rc = KbdGetHWID(&hwid, fd);
	if (rc == 0) {
		switch (hwid.idKbd) {
		default:
		case 0xab54: /* 88/89 key */
		case 0:	/*unknown*/
		case 1: /*real AT 84 key*/
			xf86Info.kbdType = KB_84; break;
		case 0xab85: /* 122 key */
			FatalError("xf86-OS/2: OS/2 has detected an extended 122key keyboard: unsupported!\n");
		case 0xab41: /* 101/102 key */
			xf86Info.kbdType = KB_101; break;
		}				
	} else
		xf86Info.kbdType = KB_84; /*defensive*/

/* Start up the Kbd bit-bucket thread. We don't want to leave the kbd events in the driver queue */
	VioTid=_beginthread(os2KbdBitBucketThread,NULL,0x2000,(void *)NULL);
	ErrorF("xf86-OS/2: Started Kbd bit-bucket thread, Tid=%d\n",VioTid);

	xf86Config(FALSE); /* Read XF86Config */
    }
    return;
}
예제 #4
0
void xf86OpenConsole()
{
    int i, fd;
    struct vt_mode VT;
    char vtname[11];
    struct vt_stat vts;
#ifdef USE_DEV_FB
    struct fb_var_screeninfo var;
    int fbfd;
#endif

    if (serverGeneration == 1) 
    {
	/* check if we're run with euid==0 */
	if (geteuid() != 0)
	{
	    FatalError("xf86OpenConsole: Server must be running with root "
	        "permissions\n"
		"You should be using Xwrapper to start the server or xdm.\n"
		"We strongly advise against making the server SUID root!\n");
	}

	/*
	 * setup the virtual terminal manager
	 */
	if (VTnum != -1)
	{
	    xf86Info.vtno = VTnum;
	}
	else 
	{
	    if ((fd = open("/dev/tty0",O_WRONLY,0)) < 0) 
	    {
		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");
	    }
	    close(fd);
	}

	ErrorF("(using VT number %d)\n\n", xf86Info.vtno);

	sprintf(vtname,"/dev/tty%d",xf86Info.vtno); /* /dev/tty1-64 */

	xf86Config(FALSE); /* Read XF86Config */

#ifdef USE_DEV_FB
	if (fb_dev_name) {
	    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

	if (!KeepTty)
	{
	    setpgrp();
	}

	if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) < 0)
	{
	    FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
		       vtname, strerror(errno));
	}

	/* 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());

	/*
	 * Linux doesn't switch to an active vt after the last close of a vt,
	 * so we do this ourselves by remembering which is active now.
	 */
	if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) == 0)
	{
	    activeVT = vts.v_active;
	}

	if (!KeepTty)
	{
	    /*
	     * Detach from the controlling tty to avoid char loss
	     */
	    if ((i = open("/dev/tty",O_RDWR)) >= 0)
	    {
		ioctl(i, TIOCNOTTY, 0);
		close(i);
	    }
	}

	/*
	 * now get the VT
	 */
	if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
	{
	    ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n");
	}
	if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
	{
	    ErrorF("xf86OpenConsole: VT_WAITACTIVE failed\n");
	}
	if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) 
	{
	    FatalError ("xf86OpenConsole: VT_GETMODE failed\n");
	}

	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");
	}
#ifdef USE_DEV_FB
	if (fb_dev_name) {
	    /* 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 
    {
	/* serverGeneration != 1 */
	/*
	 * now get the VT
	 */
	if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
	{
	    ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n");
	}
	if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
	{
	    ErrorF("xf86OpenConsole: VT_WAITACTIVE failed\n");
	}
    }
    return;
}