]> code.delx.au - pulseaudio/commitdiff
make use F_CLOEXEC wherever useful
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Sep 2004 22:36:49 +0000 (22:36 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Sep 2004 22:36:49 +0000 (22:36 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@174 fefdeb5f-60dc-0310-8127-8f9354f1896f

doc/todo
polyp/mainloop-signal.c
polyp/module-pipe-sink.c
polyp/oss-util.c
polyp/socket-client.c
polyp/socket-server.c
polyp/socket-util.c
polyp/util.c
polyp/util.h

index 19afa7face47b53066d484d4822130e7d2025274..7c1cf71e0fd03b7ef3c2b133b481c34d0198b4c9 100644 (file)
--- a/doc/todo
+++ b/doc/todo
@@ -13,7 +13,6 @@
 - remove all gcc warnings
 - add total sample cache size to stat
 - make fragments settings runtime configurable
-- CLOEXEC
 - logging
 - automatic termination of daemon if unused
 - add sample directory
index f7ff7e93be257dde000e249bb6fe43091946dec3..a16d84571ae32793acabebaf756fc16a3dc8b9ce 100644 (file)
@@ -93,6 +93,8 @@ int pa_signal_init(struct pa_mainloop_api *a) {
 
     pa_make_nonblock_fd(signal_pipe[0]);
     pa_make_nonblock_fd(signal_pipe[1]);
+    pa_fd_set_cloexec(signal_pipe[0], 1);
+    pa_fd_set_cloexec(signal_pipe[1], 1);
 
     api = a;
     io_event = api->io_new(api, signal_pipe[0], PA_IO_EVENT_INPUT, callback, NULL);
index 32a2c722b982c90f27ba763f0865067ee4589361..088ed405d3b4ddbc99010b61d7f6f9cf46e8ee94 100644 (file)
@@ -143,6 +143,8 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
         goto fail;
     }
 
+    pa_fd_set_cloexec(fd, 1);
+    
     if (fstat(fd, &st) < 0) {
         fprintf(stderr, __FILE__": fstat('%s'): %s\n", p, strerror(errno));
         goto fail;
index 4fb2b92989315177efa3f39dd6d3ae68ae8b3ecf..b28c3dc9526d6a8ca1844144c0471c63e82ab4ea 100644 (file)
@@ -35,6 +35,7 @@
 #include <fcntl.h>
 
 #include "oss-util.h"
+#include "util.h"
 
 int pa_oss_open(const char *device, int *mode, int* pcaps) {
     int fd = -1;
@@ -77,6 +78,8 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) {
             goto fail;
         }
     }
+
+    pa_fd_set_cloexec(fd, 1);
     
     return fd;
 
index 25940122397050a8c1ceb99533a0f44dd0187108..f697cbdbc55fa92442e76765782e81724cb3dc52 100644 (file)
@@ -152,6 +152,7 @@ struct pa_socket_client* pa_socket_client_new_ipv4(struct pa_mainloop_api *m, ui
         goto fail;
     }
 
+    pa_fd_set_cloexec(c->fd, 1);
     pa_socket_tcp_low_delay(c->fd);
 
     sa.sin_family = AF_INET;
@@ -181,6 +182,7 @@ struct pa_socket_client* pa_socket_client_new_unix(struct pa_mainloop_api *m, co
         goto fail;
     }
 
+    pa_fd_set_cloexec(c->fd, 1);
     pa_socket_low_delay(c->fd);
 
     sa.sun_family = AF_LOCAL;
@@ -208,6 +210,7 @@ struct pa_socket_client* pa_socket_client_new_sockaddr(struct pa_mainloop_api *m
         goto fail;
     }
 
+    pa_fd_set_cloexec(c->fd, 1);
     if (sa->sa_family == AF_INET)
         pa_socket_tcp_low_delay(c->fd);
     else
index f01e417c4cf134182faba86fce5d88de6136c852..131339eda929d95381b750f91067489aa947cbb0 100644 (file)
@@ -38,6 +38,7 @@
 #include "socket-server.h"
 #include "socket-util.h"
 #include "xmalloc.h"
+#include "util.h"
 
 struct pa_socket_server {
     int ref;
@@ -65,6 +66,8 @@ static void callback(struct pa_mainloop_api *mainloop, struct pa_io_event *e, in
         goto finish;
     }
 
+    pa_fd_set_cloexec(nfd, 1);
+    
     if (!s->on_connection) {
         close(nfd);
         goto finish;
@@ -122,6 +125,8 @@ struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, co
         goto fail;
     }
 
+    pa_fd_set_cloexec(fd, 1);
+
     sa.sun_family = AF_LOCAL;
     strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
     sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
@@ -166,6 +171,8 @@ struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, ui
         goto fail;
     }
 
+    pa_fd_set_cloexec(fd, 1);
+
     if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
         fprintf(stderr, "setsockopt(): %s\n", strerror(errno));
 
index f9d0febfa2d1979475ddb8c2190bc8b167132a11..1f93ef88175a53940cfecac453ee6a6ecb4c3a87 100644 (file)
@@ -217,3 +217,4 @@ finish:
     pa_xfree(dir);
     return ret;
 }
+
index 0d930118b5ddfdf318612cd5d9933f04afe20b2d..a3276fdfcbde3284595898b6ddef3acfdd55bc19 100644 (file)
@@ -249,3 +249,18 @@ void pa_reset_priority(void) {
 
     setpriority(PRIO_PROCESS, 0, 0);
 }
+
+int pa_fd_set_cloexec(int fd, int b) {
+    int v;
+    assert(fd >= 0);
+
+    if ((v = fcntl(fd, F_GETFD, 0)) < 0)
+        return -1;
+    
+    v = (v & ~FD_CLOEXEC) | (b ? FD_CLOEXEC : 0);
+    
+    if (fcntl(fd, F_SETFD, v) < 0)
+        return -1;
+    
+    return 0;
+}
index 89505cde234d2aeed2b4a450aabcc6f323af7321..f8dd3f0462cfdf13be9d9ba0fe8fe798fabb3c7c 100644 (file)
@@ -44,4 +44,6 @@ uint32_t pa_age(struct timeval *tv);
 void pa_raise_priority(void);
 void pa_reset_priority(void);
 
+int pa_fd_set_cloexec(int fd, int b);
+
 #endif