mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Miquel van Smoorenburg" <miquels@cistron.nl>
To: linux-kernel@vger.kernel.org
Subject: Re: Writing as init without /dev/console?
Date: Thu, 23 Jun 2005 08:27:50 +0000 (UTC)	[thread overview]
Message-ID: <d9drq6$7hf$1@news.cistron.nl> (raw)
In-Reply-To: <20050620135132.GB2779@schottelius.org>

In article <20050620135132.GB2779@schottelius.org>,
Nico Schottelius  <nico-kernel@schottelius.org> 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.


      reply	other threads:[~2005-06-23  8:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 13:51 Nico Schottelius
2005-06-23  8:27 ` Miquel van Smoorenburg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='d9drq6$7hf$1@news.cistron.nl' \
    --to=miquels@cistron.nl \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®