[alsa-devel] [PATCH 1/3] Open device nodes with close-on-exec flag
Lennart Poettering
mznyfn at 0pointer.de
Wed Nov 4 20:03:11 CET 2009
On Wed, 04.11.09 20:38, Rémi Denis-Courmont (remi at 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
More information about the Alsa-devel
mailing list