Re: Writing as init without /dev/console?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <[email protected]>,
Nico Schottelius  <[email protected]> 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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux