OSDN Git Service

Open device nodes with close-on-exec flag
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 7 Nov 2009 19:29:23 +0000 (21:29 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sun, 8 Nov 2009 08:23:07 +0000 (09:23 +0100)
Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/local.h

index b5a1c45..fa3f0b7 100644 (file)
@@ -230,22 +230,28 @@ extern snd_lib_error_handler_t snd_err_msg;
 # define link_warning(symbol, msg)
 #endif
 
-/* open with resmgr */
-#ifdef SUPPORT_RESMGR
 static inline int snd_open_device(const char *filename, int fmode)
 {
-       int fd = open(filename, fmode);
+       int fd;
+
+#ifdef O_CLOEXEC
+       fmode |= O_CLOEXEC;
+#endif
+       fd = open(filename, fmode);
+
+/* open with resmgr */
+#ifdef SUPPORT_RESMGR
+       if (fd < 0) {
+               if (errno == EAGAIN || errno == EBUSY)
+                       return fd;
+               if (! access(filename, F_OK))
+                       fd = rsm_open_device(filename, fmode);
+       }
+#endif
        if (fd >= 0)
-               return fd;
-       if (errno == EAGAIN || errno == EBUSY)
-               return fd;
-       if (! access(filename, F_OK))
-               return rsm_open_device(filename, fmode);
-       return -1;
+               fcntl(fd, F_SETFD, FD_CLOEXEC);
+       return fd;
 }
-#else
-#define snd_open_device(filename, fmode) open(filename, fmode);
-#endif
 
 /* make local functions really local */
 #define snd_dlobj_cache_lookup \