delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/04/07/04:00:26

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 53780P2m1321899
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 53780P2m1321899
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=EybXvxsD
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E66BD3864832
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1744012822;
bh=X7pzS1+J6jCebjOII/trmKV44lwxaVsOuN4ZnYZ4F8E=;
h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:Cc:From;
b=EybXvxsD84TfIIoLPIBbeL4LamCpuijVtBzW3+7lJh5BeECzY3+8JNlyBRbrKU9VZ
sKvrH+0tQ+EC+NcOI9r1HbvG2sOy1zFQO0LmXT2o+HjXJXiOFi8gXNsvO6Bj13vqA+
Ip5ULY6ZIP2ltS7P/1yHbsH/IMcZ6KYirqwwlkRs=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA3363857B94
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BA3363857B94
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744012793; cv=none;
b=EuFYjGlqDO/1vR7lZ3HDaJV5LRFWYEljF2wyDhKx1YYwOnGruNuZk4mcLcFpW87Fv9/af78YFb71Qv4EFHKo8sTTalf9VLd0N2CaJsR53U0VksVRdURbdNe/A00O1mu5RpFkpHFkRuzWX+KR2fp+XZGkjFagRFqGWMj2iZRPbZ0=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1744012793; c=relaxed/simple;
bh=3h09H3D6vQDCY6pG+oFAW54dFcz/IrMJQA4diUKtTnI=;
h=From:To:Subject:Message-ID:Date:MIME-Version;
b=JvlU9BoofVFgv4QO1YXDHINoGsLUaC3uR01AJ2fxqREJGFLl2PPv7Dg/aDX+xBL8FJerFM4pdxB7haOjPsKLbCJhe5Z8RidbcQsNo4ss8Bfxi7p0rvHW3PUxN5EkeIZ1/9sj7166vuCkuOV7yz90izDElq1NE3fMXfXdBAIU7ng=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA3363857B94
To: cygwin AT cygwin DOT com
Subject: ftruncate() may fail with EISDIR if other process calls open()
Message-ID: <8006969c-037a-14a5-7a27-9572d48d605c@t-online.de>
Date: Mon, 7 Apr 2025 09:59:29 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101
SeaMonkey/2.53.20
MIME-Version: 1.0
X-TOI-EXPURGATEID: 150726::1744012769-AA7EA85A-ACBDF2D5/0/0 CLEAN NORMAL
X-TOI-MSGID: a7e55f74-dd3a-42b8-962d-81d6266d4e9a
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 53780P2m1321899

Found because 'stress-ng --fcntl 2 --verify' reports "ftruncate failed, 
errno=21":

Testcase:

$ uname -r # also with 3.6.0-1 and 3.5.7-1
3.7.0-0.43.g779e46b5b3ee.x86_64

$ cat ftruncopen.c
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
   const char name[] = "file.tmp";
   unlink(name);

   pid_t pid = fork();
   if (pid == (pid_t)-1) {
     perror("fork"); return 1;
   }

   int status = 1;
   int fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0600);
   if (fd < 0) {
     fprintf(stderr, "%d: ", (int)getpid()); perror("open");
   }
   else if (!pid && ftruncate(fd, 0) < 0) {
     fprintf(stderr, "%d: ", (int)getpid()); perror("ftruncate");
   }
   else
     status = 0;

   printf("%d: exit(%d)\n", (int)getpid(), status);
   if (!pid)
     return status;
   int status2 = 0;
   wait(&status2);
   return (status || status2);
}

$ gcc -o ftruncopen ftruncopen.c

$ while ./ftruncopen; do echo retry; done
11223: exit(0)
11222: exit(0)
retry
11225: exit(0)
11224: exit(0)
retry
11227: ftruncate: Is a directory
11226: exit(0)
11227: exit(1)


Problem did not occur if
- O_TRUNC is removed, or
- unlink() is removed and the file exists, or
- it is run with 'taskset 0x1'.

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