From owner-freebsd-questions Sat Sep 12 14:18:42 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA13484 for freebsd-questions-outgoing; Sat, 12 Sep 1998 14:18:42 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from awfulhak.org (awfulhak.force9.co.uk [195.166.136.63]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA13470 for ; Sat, 12 Sep 1998 14:18:30 -0700 (PDT) (envelope-from brian@Awfulhak.org) Received: from woof.lan.awfulhak.org (brian@woof.lan.awfulhak.org [172.16.0.7]) by awfulhak.org (8.8.8/8.8.8) with ESMTP id VAA28821; Sat, 12 Sep 1998 21:38:07 +0100 (BST) (envelope-from brian@Awfulhak.org) Received: from woof.lan.awfulhak.org (brian@localhost [127.0.0.1]) by woof.lan.awfulhak.org (8.9.1/8.9.1) with ESMTP id LAA28513; Sat, 12 Sep 1998 11:25:51 +0100 (BST) (envelope-from brian@woof.lan.awfulhak.org) Message-Id: <199809121025.LAA28513@woof.lan.awfulhak.org> X-Mailer: exmh version 2.0.2 2/24/98 To: Mark Ovens cc: Brian Somers , questions@FreeBSD.ORG, freebsd-users@freebsd-uk.eu.org Subject: Re: Help needed with fork(), pipe() & dup2() In-reply-to: Your message of "Fri, 11 Sep 1998 08:16:27 BST." <35F8CE4B.ED9E33F3@uk.radan.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 12 Sep 1998 11:25:32 +0100 From: Brian Somers Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Brian Somers wrote: > > > > > > The parent should not be mucking around with STDIN and gets() at all. > > In my experience, way to many library calls use unexpected routines > > like err() and abort(). Besides, gets() produces warnings for a > > reason. > > > > Instead, change the parent if() block to [.....] > The major change here seems to be using fdopen() instead of dup2() and > reading the pipe with fgets() rather than gets(), but only for the > parent. Can I take it that dup2() can still be used for the child? The major change is that the parent doesn't muck around with STDIN_FILENO - other things may break when this is dup'd or reopened. The child is correct to dup2 to STDOUT_FILENO as the intention is to redirect the exec'd program output. Nothing can get screwed up as the exec will throw away the current process. Of course an exit() should be done after the exec() in case the exec fails. > Leo has tried your mods and it works fine. I'll try it tonight. He > also tried the original code and got the same results - works under > Linux but not FreeBSD. Maybe the linux stuff depends less on having STDIN_FILENO intact. As I suggested before, far to many of the library routines in FreeBSD use stdin/stdout/stderr. A library routine should never make assumptions about these descriptors unless it's documented as doing so, for example, the ppp code closes these descriptors near the start of main()..... and can end up reusing them for other purposes. > -- > When everything's coming your way, you're in the wrong lane. > > Mark Ovens, CNC Applications Engineer, Radan Computational Ltd > Sheet Metal CAD/CAM Solutions > mailto:marko@uk.radan.com http://www.radan.com -- Brian , , Don't _EVER_ lose your sense of humour.... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message