[PATCH 4/4] Xorg.wrap: Make the console check portable

Guillem Jover guillem at hadrons.org
Tue Apr 15 09:39:00 PDT 2014


On Mon, 2014-04-14 at 18:30:55 +0200, walter harms wrote:
> > +static int on_console(int fd)
> > +{
> > +#if defined(__linux__)
> > +    struct stat st;
> > +    int r;
> > +
> > +    r = fstat(fd, &st);
> > +    if (r == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4)
> > +      return 1;
> 
> this looks strange, any chr-device major 4 is a console ?
> can someone comment on this ?

I had spotted that in the original code too, which had a less restrictive
check than the Debian wrapper:

  <http://anonscm.debian.org/gitweb/?p=pkg-xorg/debian/xorg.git;a=blob;f=debian/local/xserver-wrapper.c;hb=HEAD

But according to «linux/Documentation/devices.txt», major 4 minor 0-63
are virtual consoles, and 64-255 are UART serial ports, so all those
seem fine to allow starting the server from. It also says ancient
Linux versions used to have BSD PTY on this major too, but I'm not
sure how relevant those kernels would be now, or if such versions are
supposed to be supported at all. Although it would probably be better
to be defensive about this, to also guard against new minor additions
to that major.

> mots time people what /dev/console not /dev/tty0.

These both are the “current console”, and are not devices a process
would (generally?) get on its standard streams, AFAIK.

> > @@ -176,8 +206,7 @@ int main(int argc, char *argv[])
> >          case CONSOLE_ONLY:
> >              /* Some of stdin / stdout / stderr maybe redirected to a file */
> >              for (i = STDIN_FILENO; i <= STDERR_FILENO; i++) {
> > -                r = fstat(i, &st);
> > -                if (r == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4)
> > +                if (on_console(i))
> >                      break;
> >              }
> >              if (i > STDERR_FILENO) {

Thanks,
Guillem


More information about the xorg-devel mailing list