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 19afa7f..7c1cf71 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 f7ff7e9..a16d845 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 32a2c72..088ed40 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 4fb2b92..b28c3dc 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 2594012..f697cbd 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 f01e417..131339e 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 f9d0feb..1f93ef8 100644 (file)
@@ -217,3 +217,4 @@ finish:
     pa_xfree(dir);
     return ret;
 }
+
index 0d93011..a3276fd 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 89505cd..f8dd3f0 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