I try to set O_CLOEXEC flag using open() and have no sucess.
Consider the following microtest:
#include <stdio.h>
#include <fcntl.h>
int main() {
int fd = open("test.c", O_RDONLY | O_CLOEXEC);
int ret = fcntl(fd, F_GETFL);
if(ret & O_CLOEXEC) {
printf("OK!\n");
} else {
printf("FAIL!\n");
}
printf("fd = %d\n", fd);
printf("ret = %x, O_CLOEXEC = %x\n", ret, O_CLOEXEC);
return 0;
}
When running on linux with kernel version 2.6 the test succeeds and prints "OK!", but fails with 3.8 or 3.9 kernels.
What's wrong? Thanks!