Bug #2953
closedopen(2) returns "Permission denied" instead of "File exists"
100%
Description
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@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@kl.zta.lk:/usr/obj/usr/src/sys/X86_64_GENERIC x86_64
a@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) { 1 a users 0 23-Sep-2016 07:51 aoeu
puts(strerror(errno));
return 1;
}
}
a@kl:~/tmp$ ls -l aoeu
-r--r--r-
a@kl:~/tmp$ cc test-open.c
a@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 1 a a 0 Sep 22 23:28 aoeu
FreeBSD 10.3-RELEASE FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 02:10:02 UTC 2016 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
$ ls -l aoeu
-r--r--r-
$ cc test-open.c
$ ./a.out
File exists
a@zdev:~/tmp$ uname a 1 a staff 0 Sep 22 22:54 aoeu
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@zdev:~/tmp$ ls -l aoeu
-r--r--r-
a@zdev:~/tmp$ cc test-open.c
a@zdev:~/tmp$ ./a.out
File exists
Updated by swildner over 5 years ago
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.
Updated by deef over 4 years ago
- Due date set to 06/16/2020
- Status changed from New to Resolved
- % Done changed from 0 to 100
Fixed in commit 9f86c598+. Thank you for reporting this.
BTW, if there is anything else interesting reported by ChezScheme tests on DragonFly, please report that also. :)
Updated by zhtw over 4 years ago
Wow!
This was blocking me from creating a proper pull-request for ChezScheme that would enable DF support. Of course it didn't stop me from using ChezScheme - I simply ignored the failing tests. Now I can restart my attempt.
Thanks a lot!