delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2026/05/04/14:40:27

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 644IeQW9168507
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 644IeQW9168507
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=j+sC2WDh
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77B594BA901A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1777920024;
bh=ngGlM+PVSNUeKf6vX4u0lBgtzl6ZdmfxksDE1QBHm/M=;
h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:Cc:From;
b=j+sC2WDh5hWRsS/fqIrhWlT0ky9hqGMxrvN0mEIhHyMiIQCXUD8VVYpnq3q1TlxZ1
O8HGxrK0nd9DqIZjrMvpvAbUErTHWSullyxFXWHVCCzpR44BEFXzH8U7WUqsawkjde
T60P3U6sawjVUxx1KJndkbHeSpobGAkOggl7k6eY=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C92E4B9DB40
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7C92E4B9DB40
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777920005; cv=none;
b=KZqAKicj6vpeSNVAjE+7N6YiAKXy/lXp8e8Rybf1SpPA0jq5joR3uZqbukFAupjVqZIR/pfYsPORnlaQfuc27ZmgqTca2efx4hucK6HG0W63grgnc253LgtnRsH9ODg/5jjpE8pzb1A/YO2G12RXQx+IueSEOLeXxykT1K25dRQ=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1777920005; c=relaxed/simple;
bh=pfHfhxb20gx+X2NH1VV4q3XEgNrfNyooGq9YPqIUfUA=;
h=From:Subject:To:Message-ID:Date:MIME-Version:DKIM-Signature;
b=ApYJGm2z0WzLhse+Ie7D4fuHX4/RJUhXdf6El6gk/d39OCbgJn7J9R/N6XrDFVKi4g2qdJQysyFVmF6beRdYhDli2RT69JUCFLIX6xK25v0xd0vt09mbJhso+SgpvJgS0SeNuwGdVXqplGDR3rSN9pTQEp9lCM5usL/SXZqhh/c=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C92E4B9DB40
Subject: open() creates a new file even if it fails with EMFILE
To: cygwin AT cygwin DOT com
Message-ID: <4e8b4746-e4e7-e655-a1b5-05bf5ee54a10@t-online.de>
Date: Mon, 4 May 2026 20:39:36 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101
SeaMonkey/2.53.23
MIME-Version: 1.0
X-TOI-EXPURGATEID: 150726::1777919976-05FF88E5-E6B62994/0/0 CLEAN NORMAL
X-TOI-MSGID: 95337891-76c1-4fd9-afb6-3c1722dc39df
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-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: Christian Franke via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Christian Franke <Christian DOT Franke AT t-online DOT de>
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 644IeQW9168507

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.

-- 
Regards,
Christian


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