Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Sep 1998 08:16:27 +0100
From:      Mark Ovens <marko@uk.radan.com>
To:        Brian Somers <brian@awfulhak.org>
Cc:        questions@FreeBSD.ORG, freebsd-users@freebsd-uk.eu.org
Subject:   Re: Help needed with fork(), pipe() & dup2()
Message-ID:  <35F8CE4B.ED9E33F3@uk.radan.com>
References:  <199809110054.BAA05212@woof.lan.awfulhak.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?35F8CE4B.ED9E33F3>