Project

General

Profile

Actions

Bug #2953

closed

open(2) returns "Permission denied" instead of "File exists"

Added by zhtw about 8 years ago. Updated over 4 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Kernel
Target version:
-
Start date:
09/22/2016
Due date:
06/16/2020
% Done:

100%

Estimated time:

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 :/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) {
puts(strerror(errno));
return 1;
}
}
a@kl:~/tmp$ ls -l aoeu
-r--r--r-
1 a users 0 23-Sep-2016 07:51 aoeu
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
FreeBSD 10.3-RELEASE FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 02:10:02 UTC 2016 :/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@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@zdev:~/tmp$ ls -l aoeu
-r--r--r-
1 a staff 0 Sep 22 22:54 aoeu
a@zdev:~/tmp$ cc test-open.c
a@zdev:~/tmp$ ./a.out
File exists

Actions #1

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.

Actions #2

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. :)

Actions #3

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!

Actions

Also available in: Atom PDF