Skip to contentSkip to conversation

Writing as init without /dev/console?

DISCUSSION Nico Schottelius 2 participants 2 messages Jun 20, 2005 – Jun 23, 2005

lore
Share & tools
lore
#0 lore raw

Hello!

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:

----------------------------------------------------------------------
#ifdef DEBUG
// printf("ARGC=%d\n",argc);
#endif

set_signals(ACT_SERV); /* set signal handlers */
#ifdef DEBUG
printf("ARGC=%d\n",argc);
#endif
----------------------------------------------------------------------

I don't know what could be the relation between this printf and the behaviour that cinit-0.1 later hangs in comm/do_result when reading the resulting byte from a socket.

If you want to see the full code, it can be found at [0].

This code contains serv/cinit.c, which is the same as found in cinit-0.0.8 [1] and serv/cinit.c-cinit0.1, which is the one with a bit more debugging and the printf() before set_signals, which makes cinit hang in comm/do_result at the position when fpoint() is called.

Perhaps this is an issue with not opening /dev/console? It's just a guess, because I don't have any idea what could cause this behaviour.

If someone has _any_ idea, I would be very thankful.

Nico

[0]: http://creme.schottelius.org/~nico/pre-release/cLinux/cinit-0.1-rc4.tar.bz2

P.S.: I do read replies to the mailing list via web-interface, replies
to me must be confirmed otherwise.

Signature · 3 lines
Keep it simple & stupid, use what's available.
Please use pgp encryption: 8D0E 27A4 is my id.
http://nico.schotteli.us | http://linux.schottelius.org
#1 lore raw

In article <[email protected]>,

Quoted 5 lines · Nico Schottelius

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.