Hi Corinna,

On 3/26/2019 4:36 AM, Corinna Vinschen wrote:
> Hi Ken,
> 
> On Mar 25 23:06, Ken Brown wrote:
>> The second patch in this series enables opening a FIFO with O_RDWR
>> access.  The underlying Windows named pipe is creted with duplex
>> access, and its handle is made the I/O handle of the first client.
>>
>> While testing this, I had some mysterious crashes, which are fixed by
>> the first patch.
> 
> I rebased the topic/fifo branch on top of master and force-pushed with
> your patches.  Make sure to reset your working tree to origin/topic/fifo
> and add any further patches on top.

I'm comfortable now with merging topic/fifo into master.  I've tested the new 
select and fork code [*], and they seem to work as expected.  That was the last 
thing holding me up.

As soon as the merge is done, I'll send a patch with release notes.

Ken

[*] For the record, I'm attaching the two test programs I used.  In each case I 
ran the program in one terminal and typed "echo blah > /tmp/myfifo" in a second 
terminal.
#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[5];

  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)
    {
      perror ("open");
      exit (-1);
    }

  switch (fork ())
    {
    case -1:
      perror ("fork");
      exit (-1);
    case 0:                     /* Child. */
      nbytes = read (fd, buf, 4);
      if (nbytes != 4)
        {
          perror ("read");
          exit (-1);
        }
      buf[4] = '\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;
    }
}

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

int
main ()
{
  int fd, nfds;
  fd_set readfds;
  ssize_t nbytes;
  char buf[5];

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

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

  FD_ZERO (&readfds);
  FD_SET (fd, &readfds);

  if ((nfds = select (fd + 1, &readfds, NULL, NULL, NULL)) < 0)
    {
      perror ("select");
      exit (-1);
    }

  if (FD_ISSET (fd, &readfds))
    printf ("/tmp/myfifo is ready for reading\n");
  else
    printf ("something's wrong\n");
  nbytes = read (fd, buf, 4);
  if (nbytes != 4)
    {
      perror ("read");
      exit (-1);
    }
  buf[4] = '\0';
  printf ("read %d bytes: %s\n", nbytes, buf);
  if (close (fd) < 0)
    {
      perror ("close");
      exit (-1);
    }
}

Reply via email to