4 Nov
2009
4 Nov
'09
8:03 p.m.
On Wed, 04.11.09 20:38, RĂ©mi Denis-Courmont (remi@remlab.net) wrote:
static inline int snd_open_device(const char *filename, int fmode) {
- int fd = open(filename, fmode);
- int fd;
+#ifdef O_CLOEXEC
- fd = open(filename, fmode|O_CLOEXEC); if (fd >= 0) return fd;
- if (errno == EINVAL)
+#endif
- {
fd = open(filename, fmode);
if (fd >= 0) {
fcntl(fd, F_SETFD, FD_CLOEXEC);
return fd;
}
That's actually not how things works. O_CLOEXEC is silently ignored by old kernels. (The calls with SOCK_CLOEXEC fail with EINVAL while the calls with O_CLOEXEC silently succeed) You need to set FD_CLOEXEC unconditionally to cover all cases:
fd = open(fn, fmode #ifdef O_CLOEXEC |O_CLOEXEC #endif ); fcntl(fd, F_SETFD, FD_CLOEXEC);
Lennart
--
Lennart Poettering Red Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/ GnuPG 0x1A015CC4