Re: Writing as init without /dev/console?

From: Miquel van Smoorenburg
Date: Thu Jun 23 2005 - 04:03:35 EST


In article <20050620135132.GB2779@xxxxxxxxxxxxxxx>,
Nico Schottelius <nico-kernel@xxxxxxxxxxxxxxx> wrote:
>Currently I do not open /dev/console in cinit, but currently
>I do see very strange behaviour:
>
>If the first printf() in the following code (from serv/cinit.c) is
>enabled, the socket communication will later fail:

printf() prints to stdout i.e. filedescriptor #1. If you do not
open stdin/stdout/stderr in your program, you do not know what
is going to be fd #1 later on .. in your case, the socket probably
is fd #1 and the printf() is happily printing to it.

To prevent this, do something like this at the start of your program:

int n;

do {
n = open("/dev/null", O_RDWR);
} while (n >= 0 && n <= 2);
close(n);

Mike.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/