<p><br>
On May 14, 2011 3:39 PM, &quot;Cody Maloney&quot; &lt;<a href="mailto:cmaloney@theoreticalchaos.com">cmaloney@theoreticalchaos.com</a>&gt; wrote:<br>
&gt;<br>
&gt; According to the comment in the Linux kernel source file<br>
&gt; drivers/tty/vt/vt_ioctl.c /dev/tty0 points to /dev/console,<br>
&gt; so we should just go to /dev/console, and virtual terminals<br>
&gt; are always labeled /dev/ttyN where N is 1..MAX_NR_CONSOLES,<br>
&gt; so only check /dev/ttyN.<br>
&gt;<br>
&gt; Signed-off-by: Cody Maloney &lt;<a href="mailto:cmaloney@theoreticalchaos.com">cmaloney@theoreticalchaos.com</a>&gt;<br>
&gt; ---<br>
&gt;  hw/xfree86/os-support/linux/lnx_init.c |   39 ++++++-------------------------<br>
&gt;  1 files changed, 8 insertions(+), 31 deletions(-)<br>
&gt;<br>
&gt; diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c<br>
&gt; index 77dfb2f..04518f3 100644<br>
&gt; --- a/hw/xfree86/os-support/linux/lnx_init.c<br>
&gt; +++ b/hw/xfree86/os-support/linux/lnx_init.c<br>
&gt; @@ -76,17 +76,17 @@ switch_to(int vt, const char *from)<br>
&gt;  void<br>
&gt;  xf86OpenConsole(void)<br>
&gt;  {<br>
&gt; -    int i, fd = -1, ret;<br>
&gt; +    int fd = -1, ret;<br>
&gt;     struct vt_mode VT;<br>
&gt;     struct vt_stat vts;<br>
&gt;     MessageType from = X_PROBED;<br>
&gt; -    char *tty0[] = { &quot;/dev/tty0&quot;, &quot;/dev/vc/0&quot;, NULL };<br>
&gt; -    char *vcs[] = { &quot;/dev/vc/%d&quot;, &quot;/dev/tty%d&quot;, NULL };<br>
&gt; +    const char *console_fname = &quot;/dev/console&quot;;<br>
&gt; +    char *vcs = &quot;/dev/tty%d&quot;;<br>
&gt;<br>
&gt;     if (serverGeneration == 1) {<br>
&gt;<br>
&gt;        /* when KeepTty check if we&#39;re run with euid==0 */<br>
&gt; -       if (KeepTty &amp;&amp; geteuid() != 0)<br>
&gt; +       if (KeepTty &amp;&amp; geteuid() != 0)<br>
&gt;            FatalError(&quot;xf86OpenConsole:&quot;<br>
&gt;                       &quot; Server must be suid root for option \&quot;KeepTTY\&quot;\n&quot;);<br>
&gt;<br>
&gt; @@ -96,17 +96,11 @@ xf86OpenConsole(void)<br>
&gt;        if (xf86Info.vtno != -1) {<br>
&gt;            from = X_CMDLINE;<br>
&gt;        } else {<br>
&gt; +           fd = open(console_fname, O_WRONLY, 0);<br>
&gt;<br>
&gt; -           i=0;<br>
&gt; -           while (tty0[i] != NULL) {<br>
&gt; -               if ((fd = open(tty0[i],O_WRONLY,0)) &gt;= 0)<br>
&gt; -                 break;<br>
&gt; -               i++;<br>
&gt; -           }<br>
&gt; -<br>
&gt;            if (fd &lt; 0)<br>
&gt;                FatalError(<br>
&gt; -                   &quot;xf86OpenConsole: Cannot open /dev/tty0 (%s)\n&quot;,<br>
&gt; +                   &quot;xf86OpenConsole: Cannot open /dev/console to use VT ioctls (%s)\n&quot;,<br>
&gt;                    strerror(errno));<br>
&gt;<br>
&gt;             if (ShareVTs)<br>
&gt; @@ -149,13 +143,8 @@ xf86OpenConsole(void)<br>
&gt;                        strerror(errno));<br>
&gt;        }<br>
&gt;<br>
&gt; -        i=0;<br>
&gt; -        while (vcs[i] != NULL) {<br>
&gt; -            sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */<br>
&gt; -           if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) &gt;= 0)<br>
&gt; -               break;<br>
&gt; -            i++;<br>
&gt; -        }<br>
&gt; +        sprintf(vtname, vcs, xf86Info.vtno); /* /dev/tty1-64 */<br>
&gt; +        xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0);<br>
&gt;<br>
&gt;        if (xf86Info.consoleFd &lt; 0)<br>
&gt;            FatalError(&quot;xf86OpenConsole: Cannot open virtual console&quot;<br>
&gt; @@ -172,18 +161,6 @@ xf86OpenConsole(void)<br>
&gt;        else<br>
&gt;            activeVT = vts.v_active;<br>
&gt;<br>
&gt; -#if 0<br>
&gt; -       if (!KeepTty) {<br>
&gt; -           /*<br>
&gt; -            * Detach from the controlling tty to avoid char loss<br>
&gt; -            */<br>
&gt; -           if ((i = open(&quot;/dev/tty&quot;,O_RDWR)) &gt;= 0) {<br>
&gt; -               SYSCALL(ioctl(i, TIOCNOTTY, 0));<br>
&gt; -               close(i);<br>
&gt; -           }<br>
&gt; -       }<br>
&gt; -#endif<br>
&gt; -<br>
&gt;         if (!ShareVTs)<br>
&gt;         {<br>
&gt;             struct termios nTty;<br>
&gt; --<br>
&gt; 1.7.5.1<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; <a href="mailto:xorg-devel@lists.x.org">xorg-devel@lists.x.org</a>: X.Org development<br>
&gt; Archives: <a href="http://lists.x.org/archives/xorg-devel">http://lists.x.org/archives/xorg-devel</a><br>
&gt; Info: <a href="http://lists.x.org/mailman/listinfo/xorg-devel">http://lists.x.org/mailman/listinfo/xorg-devel</a></p>
<p>This may be different when operating under mdev, devfs, android init, devtmpfs (devfs replacement, not sure that&#39;s what it&#39;s called), especially /dev/vc/*</p>
<p>Timothy Meade (tmzt)</p>