delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/05/15/19:47:15

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 54FNlEaP3519819
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 54FNlEaP3519819
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=ME2its6Y
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1432385841E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1747352831;
bh=5X72XcRz8ZDKKztUYgU8TwrFlKL1IgCVhioIfBFFA70=;
h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=ME2its6YVKunlAkP2DXJWy+sJIYGKIG1c8RdlVRHEgtJ1xIQgdwMnN5OGCo7SsJ3q
iKQWKEGmNekmrLxeA/KZwlFzMQFBG7BqSK1WIuxv5lyJlyq4YhU8ys+IO+s9yMspea
1kzM8x3DHqbBdwy+nfyJGMCb1ZPd/tNh8jvymNPM=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE8513858C56
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EE8513858C56
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747352805; cv=none;
b=BaVd+sz0a1IKwcQFJz0S0VSKg3QKtloKDkKgQKWRClodt4JVVBFZr34UbapdBJc9iOZqTTd7ETYJuuFSpAoGRbs0Zd7nuMmiKag62ivyzPzHlmMY3MXDFgt/xsghp0iurfk7jl0B7G2EfC5IXiwl8zc/xQs2abr/8JWvGE5ma74=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1747352805; c=relaxed/simple;
bh=RWR7hfAIvvPanDBfeWbTKqjVLWHeZ5lpthowwJLkF6k=;
h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature;
b=Ps3g7eTrL0KFVQkxooD1UuWS8LRd90aiyjCVbTtsN1aC3mVdgr3VvC9VyE+P2iORjuO/TzL8pv5W/6FaYv6sIKy/un9NtR6XzaapNut7znVSyZGbMEFYOP1uuzSzeJQ0faIrhQZ+xOQT4wbgyvqtztKtQYFvwJegwJrparcu1L0=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE8513858C56
Date: Fri, 16 May 2025 08:46:40 +0900
To: cygwin AT cygwin DOT com
Subject: Re: FIFO hangs (Probably a bug of cygwin fifo)
Message-Id: <20250516084640.2b20feda1c8f65cddbd264bc@nifty.ne.jp>
In-Reply-To: <adf4f021-6a6f-4bc1-96db-f0ea5b9cd2f9@cornell.edu>
References: <20250514182934 DOT ee8ff6c46ecfc44c69e70b72 AT nifty DOT ne DOT jp>
<adf4f021-6a6f-4bc1-96db-f0ea5b9cd2f9 AT cornell DOT edu>
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Mime-Version: 1.0
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Takashi Yano via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

Hi Ken,

On Thu, 15 May 2025 18:18:26 -0400
Ken Brown wrote:
> Hi Takashi,
> 
> On 5/14/2025 5:29 AM, Takashi Yano via Cygwin wrote:
> > Hi Ken,
> > 
> > I encountered the problem with fifo. The following STC hangs
> > in cygwin while it works in linux.
> > 
> > Perhaps, cygheap->fdtab.lock() causes a deadlock between
> > both open().
> > 
> > Could you please take a look?
> > 
> > #include <unistd.h>
> > #include <pthread.h>
> > #include <sys/stat.h>
> > #include <fcntl.h>
> > 
> > #define fifo1 "/tmp/fifo-test"
> > 
> > void *thr1(void *)
> > {
> > 	int fd;
> > 	usleep(100000);
> > 	fd = open(fifo1, O_WRONLY);
> > 	write(fd, "A", 1);
> > 	usleep(100000);
> > 	close(fd);
> > 	return NULL;
> > }
> > 
> > int main()
> > {
> > 	int fd;
> > 	pthread_t th;
> > 	char c;
> > 	mkfifo(fifo1, 0600);
> > 	pthread_create(&th, NULL, thr1, NULL);
> > 	fd = open(fifo1, O_RDONLY);
> > 	pthread_join(th, NULL);
> > 	read(fd, &c, 1);
> > 	write(1, &c, 1);
> > 	close(fd);
> > 	return 0;
> > }
> > 
> 
> Thanks for the STC.  I can reproduce the problem.  I'll take a look.

Thanks in advance.

I'm not sure it is the right thing, but I found the following patch
solves the issue. What do you think?

diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_includes/cygheap.h
index fed87ec2b..7d11fbb37 100644
--- a/winsup/cygwin/local_includes/cygheap.h
+++ b/winsup/cygwin/local_includes/cygheap.h
@@ -604,6 +604,8 @@ class cygheap_fdnew : public cygheap_fdmanip
   {
     if (cygheap->fdtab[fd])
       cygheap->fdtab[fd]->inc_refcnt ();
+    if (locked)
+      cygheap->fdtab.unlock ();
   }
   void operator = (fhandler_base *fh) {cygheap->fdtab[fd] = fh;}
 };
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index c93bf4c95..d6a2c2d3b 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1472,11 +1472,6 @@ open (const char *unix_path, int flags, ...)
       mode = va_arg (ap, mode_t);
       va_end (ap);
 
-      cygheap_fdnew fd;
-
-      if (fd < 0)
-	__leave;		/* errno already set */
-
       /* When O_PATH is specified in flags, flag bits other than O_CLOEXEC,
 	 O_DIRECTORY, and O_NOFOLLOW are ignored. */
       if (flags & O_PATH)
@@ -1577,6 +1572,12 @@ open (const char *unix_path, int flags, ...)
       if ((flags & O_TMPFILE) && !fh->pc.isremote ())
 	try_to_bin (fh->pc, fh->get_handle (), DELETE,
 		    FILE_OPEN_FOR_BACKUP_INTENT);
+
+      cygheap_fdnew fd;
+
+      if (fd < 0)
+	__leave;		/* errno already set */
+
       fd = fh;
       if (fd <= 2)
 	set_std_handle (fd);

-- 
Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019