public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Fork problems on master branch
@ 2019-06-08 19:44 Ken Brown
  2019-06-09 16:51 ` Ken Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Ken Brown @ 2019-06-08 19:44 UTC (permalink / raw)
  To: cygwin; +Cc: Michael Haubenwallner

[-- 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-23 17:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-08 19:44 Fork problems on master branch Ken Brown
2019-06-09 16:51 ` Ken Brown
2019-06-23 17:14   ` Ken Brown

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).