[Bug?] init.c: problems if kernel gets console=null via cmdline

Roy Marples uberlord at gentoo.org
Wed Jul 4 20:02:26 UTC 2007


On Wed, 4 Jul 2007 20:58:11 +0200
Harald Küthe <harald-tuxbox at arcor.de> wrote:
> > Try this: in init.c, add "else" clause as shown below:
> > 
> > static void console_init(void)
> > {
> >         struct serial_struct sr;
> >         char *s;
> > 
> >         s = getenv("CONSOLE");
> >         if (!s) s = getenv("console");
> >         if (s) {
> >                 int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY);
> >                 if (fd >= 0) {
> >                         dup2(fd, 0);
> >                         dup2(fd, 1);
> >                         dup2(fd, 2);
> >                         while (fd > 2) close(fd--);
> >                 }
> >                 messageD(L_LOG, "console='%s'", s);
> > +        } else {
> > +               /* Make sure fd 0,1,2 are not closed */
> > +               bb_sanitize_stdio();
> >         }
> > 
> > If it helps, I will add it in 1.6.2.
> > --
> > vda
> 
> This works, thank you for your help.
> I found out that in kernel 2.4.34 the kernel commandline argument
> "console=" is processed by the kernel itsself and therefore not
> transferred into the environment. So getenv("CONSOLE"); and
> getenv("console"); always return null. Linux-2.6.15 look similar

Why don't you use the ttyname function? That always points to the
correct tty used. On Gentoo in sysinit and boot it returns /dev/console
and in runlevel 3 (default) it returns /dev/tty1

char *tty = ttyname (fileno (stdout));
if (tty) {
	... /* same as above */
} else {
	/* Make sure fd 0,1,2 are not closed */
	bb_sanitize_stdio();
}

Thanks

Roy



More information about the busybox mailing list