Date: Wed, 28 Sep 2022 20:48:53 -0400
From: "David H. Gutteridge" <[email protected]>
Message-ID: <[email protected]>
| (O_CLOEXEC, on the other hand, is ignored, at the moment.)
No it isn't, your test is faulty, O_CLOEXEC is a different
kind of flag, applies at a different level, and is fetched
a different way.
That's what dholland@ tried to tell you a few days ago.
kre
|
| $ cat open_test.c
| #include <fcntl.h>
| #include <stdio.h>
| #include <unistd.h>
|
| int main(int argc, char* argv[])
| {
| int fd, flags;
|
| printf("Regular file (read-only) with O_NONBLOCK | O_CLOEXEC.\n");
| if ((fd = open("/etc/release", O_RDONLY | O_NONBLOCK | O_CLOEXEC)) < 0)
| printf("Failed to get file handle.\n");
| else {
| printf("Descriptor flags: %d\n", flags = fcntl(fd, F_GETFD));
| printf("Status flags: %d\n", flags = fcntl(fd, F_GETFL, 0));
| close(fd);
| }
|
| printf("POSIX pt cloning device with O_NONBLOCK | O_CLOEXEC.\n");
| if ((fd = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_NONBLOCK |
| O_CLOEXEC)) < 0)
| printf("Failed to open /dev/ptmx.\n");
| else {
| printf("Descriptor flags: %d\n", flags = fcntl(fd, F_GETFD));
| printf("Status flags: %d\n", flags = fcntl(fd, F_GETFL, 0));
| close(fd);
| }
|
| return 0;
| }
|
| $ ./open_test
| Regular file (read-only) with O_NONBLOCK | O_CLOEXEC.
| Descriptor flags: 1
| Status flags: 4
| POSIX pt cloning device with O_NONBLOCK | O_CLOEXEC.
| Descriptor flags: 0
| Status flags: 6
|
| Regards,
|
| Dave
|