delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2026/05/04/18:53:59

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 644MrxPZ330290
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 644MrxPZ330290
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=AZRQdRr2
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 647C64BAD15B
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1777935237;
bh=yJbaLGZv5T8eMEUz9GORTfEUlgoP1EetThydM8tM+Jc=;
h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=AZRQdRr2ngC1DE6ma5cG7k2mco82yo9vS6Ozzx+qSYtEyHjO64G5TOjZGkSUSoe5q
LSPc57hYe3NZaHYZEDpz06T7ywTXUsZVpoDn+eVhjX2Sj5yfeEG8N9s/mHjJ0hbxyk
wCrrU82m7nOKriN15W9nrYDeovhzThWkmlTwkHYc=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F2D24BABF30
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4F2D24BABF30
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777935188; cv=none;
b=B7gSjiH/bBWd09SfZdJGpCQkUPlOvnZfEl+0bT+OKZ6BlWmCJr0H7K8M27DJb0WnWYDtNkBo3fOSC14AwSlUONEb0i9DTIgU6O8A8zEgc8rAHsCkYIYsVEb9pmEKTEEH7GuKNrQMy3PaSk5/QxnPsE3e6Iijkv6DJKpsbN2VsAg=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1777935188; c=relaxed/simple;
bh=xde83tK4FMMJhnSBu8TOfv3/bk+pFReWCBiAoIWEOWs=;
h=Message-ID:Date:MIME-Version:Subject:To:From;
b=b74oZygdXdhBMi1FwXkNU+Mva+N8UKj4GEZxthEBpBxswnbyMZoIo74ywpEUBAIVAAhhE/I/ZIPihx58KaT+RICVJuGzhmJ1x3KlH7nKuWtKhCvSxi68/8QTlFylnE0GbKwogv2nd5Ww7m6BHOHdbOphgoyPm9CZFStvzLXlWuk=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F2D24BABF30
Message-ID: <9ea723d3-d3d1-414c-97b5-7c822b796a47@maxrnd.com>
Date: Mon, 4 May 2026 15:53:05 -0700
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: open() creates a new file even if it fails with EMFILE
To: cygwin AT cygwin DOT com
References: <4e8b4746-e4e7-e655-a1b5-05bf5ee54a10 AT t-online DOT de>
In-Reply-To: <4e8b4746-e4e7-e655-a1b5-05bf5ee54a10@t-online.de>
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: Mark Geisert via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Mark Geisert <mark AT maxrnd DOT com>
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>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 644MrxPZ330290

Hi Christian,

On 5/4/2026 11:39 AM, Christian Franke via Cygwin wrote:
> Could be reproduced with 3.6.9 and current HEAD.
> 
> Testcase:
> 
> $ uname -r # or 3.6.9-1.x86_64
> 3.7.0-0.483.ga1f347c0d5b8.x86_64
> 
> $ cat openmany.c
> #include <errno.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <sys/stat.h>
> 
> int main()
> {
>    for (int i = 0; i < 10000; i++) {
>      char name[32];
>      snprintf(name, sizeof(name), "file-%04d.tmp", i);
>      errno = 0;
>      int fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
>      if (fd >= 0)
>        continue;
>      printf("open(%s, ...)=%d (errno=%d)\n", name, fd, errno);
>      struct stat st;
>      printf("stat(%s, ...)=%d\n", name, stat(name, &st));
>      break;
>    }
>    return 0;
> }
> 
> $ gcc -o openmany openmany.c
> 
> $ ls file-*.tmp
> ls: cannot access 'file-*.tmp': No such file or directory
> 
> $ ulimit -n
> 3200
> 
> $ ./openmany
> open(file-3197.tmp, ...)=-1 (errno=24)
> stat(file-3197.tmp, ...)=0
> 
> $ ls file-*.tmp
> file-0000.tmp
> file-0001.tmp
> ...
> file-3195.tmp
> file-3196.tmp
> file-3197.tmp
> 
> $ grep -w 24 /usr/include/sys/errno.h
> #define EMFILE 24       /* File descriptor value too large */
> 
> 
> Looks like the fd is allocated too late.

Thanks for the report and especially for the STC.  It is during fdtable 
extension that the limit is checked; by then NtCreateFile() has already 
been called successfully.  We need to consider a fix that avoids 
needlessly creating a file that can't be operated on anyway.

..mark


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