[PATCH alsa-lib 1/3] Open device nodes with close-on-exec flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Rémi Denis-Courmont <remi@xxxxxxxxxx>

This avoid leaking device descriptors through exec. Thus ALSA
applications can safely spawn other processes in their background.

Signed-off-by: Rémi Denis-Courmont <remi@xxxxxxxxxx>
---
 include/local.h |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/local.h b/include/local.h
index b5a1c45..5b54def 100644
--- a/include/local.h
+++ b/include/local.h
@@ -230,22 +230,33 @@ 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
+	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;
+		}
+	}
+
+/* open with resmgr */
+#ifdef SUPPORT_RESMGR
 	if (errno == EAGAIN || errno == EBUSY)
 		return fd;
 	if (! access(filename, F_OK))
 		return rsm_open_device(filename, fmode);
+#endif
 	return -1;
 }
-#else
-#define snd_open_device(filename, fmode) open(filename, fmode);
-#endif
 
 /* make local functions really local */
 #define snd_dlobj_cache_lookup \
-- 
1.6.5

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel


[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux