public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: cygwin <cygwin@cygwin.com>
Cc: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
Subject: Fork problems on master branch
Date: Sat, 08 Jun 2019 19:44:00 -0000	[thread overview]
Message-ID: <330c76fd-af22-beb9-08b6-707c73df3b75@cornell.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 1182 bytes --]

Earlier today I reported on the cygwin-patches list a fork problem with a 
cygwin1.dll built from the master branch of the Cygwin source repo.  See 
https://cygwin.com/ml/cygwin-patches/2019-q2/msg00155.html.  A bisection showed 
that commit f03ea8e1 was the first bad commit for the problem being discussed there.

I've just run into a second fork problem for which I think the same commit is 
the first bad one.  I can't be positive, because the problem is sporadic, so I 
might have marked some bad commits as good if I didn't run the test enough times.

The test case for this (attached) is one that I used when testing my new FIFO 
code.  Normally I run this program in one terminal and type

   echo blah > /tmp/myfifo

in a second terminal.  For the present purposes, however, you can skip the 
second part and simply terminate fifo_fork_test with C-c.

In my testing, I found that running the test program would yield "read: Bad 
address" about 1 out of 10 times.  Occasionally I would get "read: Communication 
error on send" instead.  Both error messages indicate a problem with the child 
process reading from an fd inherited from the parent.

Ken

[-- Attachment #2: fifo_fork_test.c --]
[-- Type: text/plain, Size: 1071 bytes --]

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>

int
main ()
{
  int fd;
  ssize_t nbytes;
  char buf[6];

  if (mkfifo ("/tmp/myfifo", S_IRUSR | S_IWUSR | S_IWGRP) < 0
      && errno != EEXIST)
    {
      perror ("mkfifo");
      exit (-1);
    }

  if ((fd = open ("/tmp/myfifo", O_RDWR)) < 0)
  /* if ((fd = open ("/tmp/myfifo", O_RDONLY)) < 0) */
    {
      perror ("open");
      exit (-1);
    }

  switch (fork ())
    {
    case -1:
      perror ("fork");
      exit (-1);
    case 0:			/* Child. */
      nbytes = read (fd, buf, 5);
      if (nbytes != 5)
	{
	  perror ("read");
	  exit (-1);
	}
      buf[5] = '\0';
      printf ("child read %d bytes: %s\n", nbytes, buf);
      if (close (fd) < 0)
	{
	  perror ("child close");
	  exit (-1);
	}
      exit (0);
    default:			/* Parent. */
      if (close (fd) < 0)
	{
	  perror ("parent close");
	  exit (-1);
	}
      printf ("parent waiting for child to read\n");
      wait (NULL);
      break;
    }
}

      

[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2019-06-08 19:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-08 19:44 Ken Brown [this message]
2019-06-09 16:51 ` Ken Brown
2019-06-23 17:14   ` Ken Brown

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=330c76fd-af22-beb9-08b6-707c73df3b75@cornell.edu \
    --to=kbrown@cornell.edu \
    --cc=cygwin@cygwin.com \
    --cc=michael.haubenwallner@ssi-schaefer.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).