[DragonFlyBSD - Bug #2953] open(2) returns "Permission denied" instead of "File exists"
bugtracker-admin at leaf.dragonflybsd.org
bugtracker-admin at leaf.dragonflybsd.org
Tue Jun 18 11:39:07 PDT 2019
Issue #2953 has been updated by swildner.
As I read the standard, open() should return EEXIST as soon as the file exists and O_EXCL and O_CREAT are passed, without further conditions.
----------------------------------------
Bug #2953: open(2) returns "Permission denied" instead of "File exists"
http://bugs.dragonflybsd.org/issues/2953#change-13709
* Author: zhtw
* Status: New
* Priority: Normal
* Assignee:
* Category: Kernel
* Target version:
----------------------------------------
I am porting ChezScheme to DragonFly. Turned out ChezScheme has very thorough set of tests. I found that open(2) returns wrong error code when a file is opened for writing with both O_EXCL and O_CREAT flags set, but it (the file) is not writable.
Not sure if this is actually considered "wrong" by Posix, but most (if not all) Unixes agree on that and return "File exists."
I only checked Darwin and FreeBSD (besides DragonFly), but all ChezScheme tests pass on Linux as well, so I'm guessing Linux behaves the same way.
a at kl:~/tmp$ uname -a
DragonFly kl.zta.lk 4.6-RELEASE DragonFly v4.6.0.10.g16fba-RELEASE #10: Wed Aug 17 14:26:31 CEST 2016 root at kl.zta.lk:/usr/obj/usr/src/sys/X86_64_GENERIC x86_64
a at kl:~/tmp$ cat test-open.c
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
int main()
{
int fd = open("aoeu", O_WRONLY | O_EXCL | O_CREAT);
if (fd == -1) {
puts(strerror(errno));
return 1;
}
}
a at kl:~/tmp$ ls -l aoeu
-r--r--r-- 1 a users 0 23-Sep-2016 07:51 aoeu
a at kl:~/tmp$ cc test-open.c
a at kl:~/tmp$ ./a.out
Permission denied
The same program returns "File exists." both on FreeBSD 10.3 & Darwin 15.6.0.
(Almost certainly the same on Linux.)
$ uname -a
FreeBSD 10.3-RELEASE FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 02:10:02 UTC 2016 root at releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
$ ls -l aoeu
-r--r--r-- 1 a a 0 Sep 22 23:28 aoeu
$ cc test-open.c
$ ./a.out
File exists
a at zdev:~/tmp$ uname -a
Darwin zdev.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
a at zdev:~/tmp$ ls -l aoeu
-r--r--r-- 1 a staff 0 Sep 22 22:54 aoeu
a at zdev:~/tmp$ cc test-open.c
a at zdev:~/tmp$ ./a.out
File exists
--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account
More information about the Bugs
mailing list