Re: [PATCH] linux: Clean up filenames used in Linux VT init.

2011-05-16 Thread Timothy Meade
On May 14, 2011 3:39 PM, Cody Maloney cmalo...@theoreticalchaos.com
wrote:

 According to the comment in the Linux kernel source file
 drivers/tty/vt/vt_ioctl.c /dev/tty0 points to /dev/console,
 so we should just go to /dev/console, and virtual terminals
 are always labeled /dev/ttyN where N is 1..MAX_NR_CONSOLES,
 so only check /dev/ttyN.

 Signed-off-by: Cody Maloney cmalo...@theoreticalchaos.com
 ---
  hw/xfree86/os-support/linux/lnx_init.c |   39
++-
  1 files changed, 8 insertions(+), 31 deletions(-)

 diff --git a/hw/xfree86/os-support/linux/lnx_init.c
b/hw/xfree86/os-support/linux/lnx_init.c
 index 77dfb2f..04518f3 100644
 --- a/hw/xfree86/os-support/linux/lnx_init.c
 +++ b/hw/xfree86/os-support/linux/lnx_init.c
 @@ -76,17 +76,17 @@ switch_to(int vt, const char *from)
  void
  xf86OpenConsole(void)
  {
 -int i, fd = -1, ret;
 +int fd = -1, ret;
 struct vt_mode VT;
 struct vt_stat vts;
 MessageType from = X_PROBED;
 -char *tty0[] = { /dev/tty0, /dev/vc/0, NULL };
 -char *vcs[] = { /dev/vc/%d, /dev/tty%d, NULL };
 +const char *console_fname = /dev/console;
 +char *vcs = /dev/tty%d;

 if (serverGeneration == 1) {

/* when KeepTty check if we're run with euid==0 */
 -   if (KeepTty  geteuid() != 0)
 +   if (KeepTty  geteuid() != 0)
FatalError(xf86OpenConsole:
Server must be suid root for option
\KeepTTY\\n);

 @@ -96,17 +96,11 @@ xf86OpenConsole(void)
if (xf86Info.vtno != -1) {
from = X_CMDLINE;
} else {
 +   fd = open(console_fname, O_WRONLY, 0);

 -   i=0;
 -   while (tty0[i] != NULL) {
 -   if ((fd = open(tty0[i],O_WRONLY,0)) = 0)
 - break;
 -   i++;
 -   }
 -
if (fd  0)
FatalError(
 -   xf86OpenConsole: Cannot open /dev/tty0 (%s)\n,
 +   xf86OpenConsole: Cannot open /dev/console to use VT
ioctls (%s)\n,
strerror(errno));

 if (ShareVTs)
 @@ -149,13 +143,8 @@ xf86OpenConsole(void)
strerror(errno));
}

 -i=0;
 -while (vcs[i] != NULL) {
 -sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */
 -   if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) =
0)
 -   break;
 -i++;
 -}
 +sprintf(vtname, vcs, xf86Info.vtno); /* /dev/tty1-64 */
 +xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0);

if (xf86Info.consoleFd  0)
FatalError(xf86OpenConsole: Cannot open virtual console
 @@ -172,18 +161,6 @@ xf86OpenConsole(void)
else
activeVT = vts.v_active;

 -#if 0
 -   if (!KeepTty) {
 -   /*
 -* Detach from the controlling tty to avoid char loss
 -*/
 -   if ((i = open(/dev/tty,O_RDWR)) = 0) {
 -   SYSCALL(ioctl(i, TIOCNOTTY, 0));
 -   close(i);
 -   }
 -   }
 -#endif
 -
 if (!ShareVTs)
 {
 struct termios nTty;
 --
 1.7.5.1

 ___
 xorg-devel@lists.x.org: X.Org development
 Archives: http://lists.x.org/archives/xorg-devel
 Info: http://lists.x.org/mailman/listinfo/xorg-devel

This may be different when operating under mdev, devfs, android init,
devtmpfs (devfs replacement, not sure that's what it's called), especially
/dev/vc/*

Timothy Meade (tmzt)
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH] linux: Clean up filenames used in Linux VT init.

2011-05-16 Thread Cody Maloney
On Mon, May 16, 2011 at 5:27 AM, Timothy Meade zt.t...@gmail.com wrote:

 On May 14, 2011 3:39 PM, Cody Maloney cmalo...@theoreticalchaos.com
 wrote:

 According to the comment in the Linux kernel source file
 drivers/tty/vt/vt_ioctl.c /dev/tty0 points to /dev/console,
 so we should just go to /dev/console, and virtual terminals
 are always labeled /dev/ttyN where N is 1..MAX_NR_CONSOLES,
 so only check /dev/ttyN.

 Signed-off-by: Cody Maloney cmalo...@theoreticalchaos.com
 ---
  hw/xfree86/os-support/linux/lnx_init.c |   39
 ++-
  1 files changed, 8 insertions(+), 31 deletions(-)

 diff --git a/hw/xfree86/os-support/linux/lnx_init.c
 b/hw/xfree86/os-support/linux/lnx_init.c
 index 77dfb2f..04518f3 100644
 --- a/hw/xfree86/os-support/linux/lnx_init.c
 +++ b/hw/xfree86/os-support/linux/lnx_init.c
 @@ -76,17 +76,17 @@ switch_to(int vt, const char *from)
  void
  xf86OpenConsole(void)
  {
 -    int i, fd = -1, ret;
 +    int fd = -1, ret;
     struct vt_mode VT;
     struct vt_stat vts;
     MessageType from = X_PROBED;
 -    char *tty0[] = { /dev/tty0, /dev/vc/0, NULL };
 -    char *vcs[] = { /dev/vc/%d, /dev/tty%d, NULL };
 +    const char *console_fname = /dev/console;
 +    char *vcs = /dev/tty%d;

     if (serverGeneration == 1) {

        /* when KeepTty check if we're run with euid==0 */
 -       if (KeepTty  geteuid() != 0)
 +       if (KeepTty  geteuid() != 0)
            FatalError(xf86OpenConsole:
                        Server must be suid root for option
 \KeepTTY\\n);

 @@ -96,17 +96,11 @@ xf86OpenConsole(void)
        if (xf86Info.vtno != -1) {
            from = X_CMDLINE;
        } else {
 +           fd = open(console_fname, O_WRONLY, 0);

 -           i=0;
 -           while (tty0[i] != NULL) {
 -               if ((fd = open(tty0[i],O_WRONLY,0)) = 0)
 -                 break;
 -               i++;
 -           }
 -
            if (fd  0)
                FatalError(
 -                   xf86OpenConsole: Cannot open /dev/tty0 (%s)\n,
 +                   xf86OpenConsole: Cannot open /dev/console to use VT
 ioctls (%s)\n,
                    strerror(errno));

             if (ShareVTs)
 @@ -149,13 +143,8 @@ xf86OpenConsole(void)
                        strerror(errno));
        }

 -        i=0;
 -        while (vcs[i] != NULL) {
 -            sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */
 -           if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) =
 0)
 -               break;
 -            i++;
 -        }
 +        sprintf(vtname, vcs, xf86Info.vtno); /* /dev/tty1-64 */
 +        xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0);

        if (xf86Info.consoleFd  0)
            FatalError(xf86OpenConsole: Cannot open virtual console
 @@ -172,18 +161,6 @@ xf86OpenConsole(void)
        else
            activeVT = vts.v_active;

 -#if 0
 -       if (!KeepTty) {
 -           /*
 -            * Detach from the controlling tty to avoid char loss
 -            */
 -           if ((i = open(/dev/tty,O_RDWR)) = 0) {
 -               SYSCALL(ioctl(i, TIOCNOTTY, 0));
 -               close(i);
 -           }
 -       }
 -#endif
 -
         if (!ShareVTs)
         {
             struct termios nTty;
 --
 1.7.5.1

 ___
 xorg-devel@lists.x.org: X.Org development
 Archives: http://lists.x.org/archives/xorg-devel
 Info: http://lists.x.org/mailman/listinfo/xorg-devel

 This may be different when operating under mdev, devfs, android init,
 devtmpfs (devfs replacement, not sure that's what it's called), especially
 /dev/vc/*

 Timothy Meade (tmzt)

I just checked and in android, there is no /dev/tty0, /dev/vc/*, but
there is /dev/tty and /dev/console, so the old code would have missed
completely anyways. devtmpfs doesn't add any devices directly, relying
on what the kernel creates (I'll come back to what the kernel creates
later). devfs was killed off a while ago (replaced with udev), it
maintains /dev/tty[0-9]+, as well as /dev/vc/[0-9]+. All major distros
have switched off of it in new versions (versions which contain new
Xorg). Devtmpfs serves as a container for a minimal /dev for embedded
devices such as android, and only has devices documented in
doc/devices.txt added to it. For mdev, the directory name in /sys that
mdev finds the 'dev' file is located is taken to be the filename used
for the device name, this means it could never add subdirectories, so
/dev/vc/0 could never exist.

Grepping through the kernel source, the only place where
/dev/vc/[0-9]+ is mentioned is one line:
linux-2.6.38.6/drivers/tty/vt/vt.c: 
register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, /dev/vc/0)  0)

Looking at the source code, this may or may not be created depending
on whether or not the if exits early. /dev/tty0 is always created. If
you look at the updated patch I sent
(http://lists.freedesktop.org/archives/xorg-devel/2011-May/05.html),
I use /dev/tty0 instead of /dev/console because, as Julien pointed
out, 

[PATCH] linux: Clean up filenames used in Linux VT init.

2011-05-14 Thread Cody Maloney
According to the comment in the Linux kernel source file
drivers/tty/vt/vt_ioctl.c /dev/tty0 points to /dev/console,
so we should just go to /dev/console, and virtual terminals
are always labeled /dev/ttyN where N is 1..MAX_NR_CONSOLES,
so only check /dev/ttyN.

Signed-off-by: Cody Maloney cmalo...@theoreticalchaos.com
---
 hw/xfree86/os-support/linux/lnx_init.c |   39 ++-
 1 files changed, 8 insertions(+), 31 deletions(-)

diff --git a/hw/xfree86/os-support/linux/lnx_init.c 
b/hw/xfree86/os-support/linux/lnx_init.c
index 77dfb2f..04518f3 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -76,17 +76,17 @@ switch_to(int vt, const char *from)
 void
 xf86OpenConsole(void)
 {
-int i, fd = -1, ret;
+int fd = -1, ret;
 struct vt_mode VT;
 struct vt_stat vts;
 MessageType from = X_PROBED;
-char *tty0[] = { /dev/tty0, /dev/vc/0, NULL };
-char *vcs[] = { /dev/vc/%d, /dev/tty%d, NULL };
+const char *console_fname = /dev/console;
+char *vcs = /dev/tty%d;
 
 if (serverGeneration == 1) {
 
/* when KeepTty check if we're run with euid==0 */
-   if (KeepTty  geteuid() != 0) 
+   if (KeepTty  geteuid() != 0)
FatalError(xf86OpenConsole:
Server must be suid root for option \KeepTTY\\n);
 
@@ -96,17 +96,11 @@ xf86OpenConsole(void)
if (xf86Info.vtno != -1) {
from = X_CMDLINE;
} else {
+   fd = open(console_fname, O_WRONLY, 0);
 
-   i=0;
-   while (tty0[i] != NULL) {
-   if ((fd = open(tty0[i],O_WRONLY,0)) = 0)
- break;
-   i++;
-   }
-   
if (fd  0)
FatalError(
-   xf86OpenConsole: Cannot open /dev/tty0 (%s)\n,
+   xf86OpenConsole: Cannot open /dev/console to use VT ioctls 
(%s)\n,
strerror(errno));
 
 if (ShareVTs)
@@ -149,13 +143,8 @@ xf86OpenConsole(void)
strerror(errno));
}
 
-i=0;
-while (vcs[i] != NULL) {
-sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */
-   if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) = 0)
-   break;
-i++;
-}
+sprintf(vtname, vcs, xf86Info.vtno); /* /dev/tty1-64 */
+xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0);
 
if (xf86Info.consoleFd  0)
FatalError(xf86OpenConsole: Cannot open virtual console
@@ -172,18 +161,6 @@ xf86OpenConsole(void)
else
activeVT = vts.v_active;
 
-#if 0
-   if (!KeepTty) {
-   /*
-* Detach from the controlling tty to avoid char loss
-*/
-   if ((i = open(/dev/tty,O_RDWR)) = 0) {
-   SYSCALL(ioctl(i, TIOCNOTTY, 0));
-   close(i);
-   }
-   }
-#endif
-
 if (!ShareVTs)
 {
 struct termios nTty;
-- 
1.7.5.1

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] linux: Clean up filenames used in Linux VT init.

2011-05-14 Thread Julien Cristau
On Sat, May 14, 2011 at 13:38:27 -0700, Cody Maloney wrote:

 According to the comment in the Linux kernel source file
 drivers/tty/vt/vt_ioctl.c /dev/tty0 points to /dev/console,
 so we should just go to /dev/console, and virtual terminals
 are always labeled /dev/ttyN where N is 1..MAX_NR_CONSOLES,
 so only check /dev/ttyN.
 
 Signed-off-by: Cody Maloney cmalo...@theoreticalchaos.com
 ---
  hw/xfree86/os-support/linux/lnx_init.c |   39 ++-
  1 files changed, 8 insertions(+), 31 deletions(-)
 
NAK.  I think this breaks system with a serial console, where you can't
always use VT ioctls on /dev/console.

Cheers,
Julien
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] linux: Clean up filenames used in Linux VT init.

2011-05-14 Thread Cody Maloney
I'm not an expert in this in any way, but looking at
http://www.kernel.org/doc/Documentation/devices.txt
it states under the terminal devices section, The console device,
/dev/console, is the device to which system messages should be sent.
Based on the sparse mailing list postings/documentation I could find I
believe that /dev/vc/* is legacy from devfs, in udev only /dev/tty* is
used.

Cody

On Sat, May 14, 2011 at 12:49 PM, Julien Cristau jcris...@debian.org wrote:

 On Sat, May 14, 2011 at 13:38:27 -0700, Cody Maloney wrote:

  According to the comment in the Linux kernel source file
  drivers/tty/vt/vt_ioctl.c /dev/tty0 points to /dev/console,
  so we should just go to /dev/console, and virtual terminals
  are always labeled /dev/ttyN where N is 1..MAX_NR_CONSOLES,
  so only check /dev/ttyN.
 
  Signed-off-by: Cody Maloney cmalo...@theoreticalchaos.com
  ---
   hw/xfree86/os-support/linux/lnx_init.c |   39 
  ++-
   1 files changed, 8 insertions(+), 31 deletions(-)
 
 NAK.  I think this breaks system with a serial console, where you can't
 always use VT ioctls on /dev/console.

 Cheers,
 Julien
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] linux: Clean up filenames used in Linux VT init.

2011-05-14 Thread Cody Maloney
After a little bit more searching I found conflicting information in
http://www.kernel.org/doc/Documentation/serial-console.txt, which says
/dev/tty0 should be used. I can switch the code to use /dev/tty0
instead of /dev/console since the documentation seems to uniformly say
that should work, while it conflicts itself about /dev/console.

Cody

On Sat, May 14, 2011 at 2:09 PM, Cody Maloney
cmalo...@theoreticalchaos.com wrote:
 I'm not an expert in this in any way, but looking at
 http://www.kernel.org/doc/Documentation/devices.txt
 it states under the terminal devices section, The console device,
 /dev/console, is the device to which system messages should be sent.
 Based on the sparse mailing list postings/documentation I could find I
 believe that /dev/vc/* is legacy from devfs, in udev only /dev/tty* is
 used.

 Cody

 On Sat, May 14, 2011 at 12:49 PM, Julien Cristau jcris...@debian.org wrote:

 On Sat, May 14, 2011 at 13:38:27 -0700, Cody Maloney wrote:

  According to the comment in the Linux kernel source file
  drivers/tty/vt/vt_ioctl.c /dev/tty0 points to /dev/console,
  so we should just go to /dev/console, and virtual terminals
  are always labeled /dev/ttyN where N is 1..MAX_NR_CONSOLES,
  so only check /dev/ttyN.
 
  Signed-off-by: Cody Maloney cmalo...@theoreticalchaos.com
  ---
   hw/xfree86/os-support/linux/lnx_init.c |   39 
  ++-
   1 files changed, 8 insertions(+), 31 deletions(-)
 
 NAK.  I think this breaks system with a serial console, where you can't
 always use VT ioctls on /dev/console.

 Cheers,
 Julien

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


[PATCH] linux: Clean up filenames used in Linux VT init.

2011-05-14 Thread Cody Maloney
According to the kernel documentation doc/Documentation/serial-console.txt and
doc/Documentation/devices.txt we should use /dev/ttyN. /dev/tty0 for the VT
ioctls, and /dev/ttyN for all the virtual terminals. Checking /dev/vc is
therefore unnecessary.

Signed-off-by: Cody Maloney cmalo...@theoreticalchaos.com
---
 hw/xfree86/os-support/linux/lnx_init.c |   39 ++-
 1 files changed, 8 insertions(+), 31 deletions(-)

diff --git a/hw/xfree86/os-support/linux/lnx_init.c 
b/hw/xfree86/os-support/linux/lnx_init.c
index 77dfb2f..9ee93b2 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -76,12 +76,12 @@ switch_to(int vt, const char *from)
 void
 xf86OpenConsole(void)
 {
-int i, fd = -1, ret;
+int fd = -1, ret;
 struct vt_mode VT;
 struct vt_stat vts;
 MessageType from = X_PROBED;
-char *tty0[] = { /dev/tty0, /dev/vc/0, NULL };
-char *vcs[] = { /dev/vc/%d, /dev/tty%d, NULL };
+const char *console_fname = /dev/tty0;
+const char *tty = /dev/tty%d;
 
 if (serverGeneration == 1) {
 
@@ -96,18 +96,12 @@ xf86OpenConsole(void)
if (xf86Info.vtno != -1) {
from = X_CMDLINE;
} else {
+   fd = open(console_fname, O_WRONLY, 0);
 
-   i=0;
-   while (tty0[i] != NULL) {
-   if ((fd = open(tty0[i],O_WRONLY,0)) = 0)
- break;
-   i++;
-   }
-   
if (fd  0)
FatalError(
-   xf86OpenConsole: Cannot open /dev/tty0 (%s)\n,
-   strerror(errno));
+   xf86OpenConsole: Cannot open /dev/console to use VT
+   ioctls (%s)\n, strerror(errno));
 
 if (ShareVTs)
 {
@@ -149,13 +143,8 @@ xf86OpenConsole(void)
strerror(errno));
}
 
-i=0;
-while (vcs[i] != NULL) {
-sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */
-   if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) = 0)
-   break;
-i++;
-}
+sprintf(vtname, tty, xf86Info.vtno); /* /dev/tty1-64 */
+xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0);
 
if (xf86Info.consoleFd  0)
FatalError(xf86OpenConsole: Cannot open virtual console
@@ -172,18 +161,6 @@ xf86OpenConsole(void)
else
activeVT = vts.v_active;
 
-#if 0
-   if (!KeepTty) {
-   /*
-* Detach from the controlling tty to avoid char loss
-*/
-   if ((i = open(/dev/tty,O_RDWR)) = 0) {
-   SYSCALL(ioctl(i, TIOCNOTTY, 0));
-   close(i);
-   }
-   }
-#endif
-
 if (!ShareVTs)
 {
 struct termios nTty;
-- 
1.7.5.1

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel