zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Cc: Zsh hackers list <zsh-workers@sunsite.auc.dk>
Subject: Re: File descriptor madness
Date: Thu, 9 May 2002 13:36:49 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0205091252340.7898-100000@ns1.sodaware.com> (raw)
In-Reply-To: <20020509185715.C4F301C0AB@pwstephenson.fsnet.co.uk>

On Thu, 9 May 2002, Peter Stephenson wrote:

> Apart from 0, which I suppose we need to test with open(), I had in mind
> just using dup() to dup 0 and see where the fd ended up.  This would in
> one go show open fd's (avoided) and open new fd's to block them.  Or
> doesn't that work?

Just one dup() will only show you where the first hole in the sequence of
fd numbers is, not whether there are any more descriptors open above that.
So you'd have to do (psuedo-code)

	if (!is_a_valid_fd(0)) { was_closed[0] = open(...); }
	while ((i = dup(0)) < 10) { was_closed[i] = 1; }
	/* ... initialize the shell ... */
	for (i = 0; i < 10; ++i) { if (was_closed[i]) close(i); }

I was merely wondering aloud whether it would be faster to do

	for (i = 0; !pipe(&just_opened[i]); ++i) {
	  if (just_opened[++i]) >= 9) break;
	}
	/* ... initialize the shell ... */
	while (i >= 0) { close(just_opened[i--]); }

Replace pipe() with something else if there's a faster way to create new
descriptors.  It's possible/probable that dup() is a lot faster, but it'd
be nice not to need to hit the filesystem for that initial open(...) in
the first example.


  reply	other threads:[~2002-05-09 20:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-09 18:15 Peter Stephenson
2002-05-09 18:47 ` Danek Duvall
2002-05-09 19:08   ` Bart Schaefer
2002-05-09 18:57     ` Peter Stephenson
2002-05-09 20:36       ` Bart Schaefer [this message]
2002-05-10 17:24         ` Peter Stephenson
2002-05-10 17:41           ` Peter Stephenson
2002-05-13  9:38             ` Peter Stephenson
2002-05-10 17:57           ` Slightly OT " Borsenkow Andrej

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=Pine.LNX.4.44.0205091252340.7898-100000@ns1.sodaware.com \
    --to=schaefer@brasslantern.com \
    --cc=pws@pwstephenson.fsnet.co.uk \
    --cc=zsh-workers@sunsite.auc.dk \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).