This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

CygPerl hangs opening FIFO after fork (in both parent&child)

The attached test case is simple and fairly short.  It does not
depend on File::BOM (and has none of the code from it).

It's only dependency (other than perl) is the POSIX module,
where, from, the "fifo" command is taken.

Conceptually, it is simple:

- Create fifo (works)
- Fork        (works)
- Open fifo for communication between parent and child      (FAILS)

   (if successful, try to pass a short message, from child to
   parent, parent validates, then both processes exit)
   Both the child and the parent hang on the "open".

Fork by itself works. Fifo communication, by itself, works.

Is this a simple enough test case?

#!/usr/bin/perl -w
use strict;
use POSIX qw( mkfifo );

my $message = <<EOM;
Hello, World.
That is all

my $testno=1;
#unbuffer outputs
select STDERR; $|=1; select STDOUT; $|=1;

sub check {
	my ($stat,$msg)=@_;
	printf "Test $testno had status %s;%s\n", 
	return $stat;

my $fifo = 'test_fifo';
unlink $fifo if (-e $fifo); 					#prior hang?: cleanup

check( mkfifo($fifo, 0700), "Created fifo $fifo" ) or warn $!;

my $pid = fork;
if ($pid) {

	check( 1 ,"parent: forked ok, about to open fifo");
    open my $reader, '<', $fifo or die "$$: Couldn't read '$fifo': $!";

	#### cygwin never gets here....

	check( 1, "parent: after open about to read from child");
	my $child_msg = <$reader>;

	check ( ($child_msg eq $message) ,
		"parent: received msg from child, closing reader...");
    close $reader;

	check( 1 ,"parent: closed reader, about to wait on child");
    check( (waitpid($pid,0) > 0), "waitpid($pid) > 0");

    check(unlink($fifo), "removed $fifo") or warn $!;

} elsif (defined $pid) {
	check( 1, "child: fork ok, about to open fifo");
    open my $writer, '>', $fifo or die "$$: Couldn't write '$fifo': $!";

	#### cygwin never gets here....

	check (1, "child: after opening fifo for write; about to print");
    print $writer $message;

    # diag "$$: Wrote ", length $message, " bytes to fifo";
	check (1, "child: wrote; about to close");	
    close $writer;

	check (1, "child: closed; about to exit");
    exit 0;

} else {
    die "$0: fork failed: $!";
Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]