From owner-freebsd-questions Fri Sep 11 00:17:24 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id AAA23529 for freebsd-questions-outgoing; Fri, 11 Sep 1998 00:17:24 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from post.mail.demon.net (post-12.mail.demon.net [194.217.242.41]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id AAA23509 for ; Fri, 11 Sep 1998 00:17:20 -0700 (PDT) (envelope-from marko@uk.radan.com) Received: from [158.152.75.22] (helo=uk.radan.com) by post.mail.demon.net with smtp (Exim 2.02 #1) id 0zHNS8-0004Qs-00; Fri, 11 Sep 1998 07:17:09 +0000 Organisation: Radan Computational Ltd., Bath, UK. Phone: +44-1225-320320 Fax: +44-1225-320311 Received: from beavis.uk.radan.com (beavis [193.114.228.122]) by uk.radan.com (8.6.10/8.6.10) with SMTP id IAA01347; Fri, 11 Sep 1998 08:16:36 +0100 Received: from uk.radan.com (gppsun4) by beavis.uk.radan.com (4.1/SMI-4.1) id AA02332; Fri, 11 Sep 98 08:16:35 BST Message-Id: <35F8CE4B.ED9E33F3@uk.radan.com> Date: Fri, 11 Sep 1998 08:16:27 +0100 From: Mark Ovens Organization: Radan Computational Ltd X-Mailer: Mozilla 4.03 [en] (X11; I; SunOS 4.1.3_U1 sun4m) Mime-Version: 1.0 To: Brian Somers Cc: questions@FreeBSD.ORG, freebsd-users@freebsd-uk.eu.org Subject: Re: Help needed with fork(), pipe() & dup2() References: <199809110054.BAA05212@woof.lan.awfulhak.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 > > FILE *in; > int len; > > close(fd[1]); > if ((in = fdopen(fd[0], "r")) == NULL) { > close(fd[0]); /* child gets SIGPIPE */ > vomit(); > } > line[sizoef line - 1] = '\0'; > while (fgets(line, sizeof line - 1, in)) { > len = strlen(line); > if (len && line[len-1] == '\n') > line[--len] = '\0'; > . > . > . > } > fclose(in); > close(fd[0]); > 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? 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. -- 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message