summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-09-01 22:36:49 +0000
committerLennart Poettering <lennart@poettering.net>2004-09-01 22:36:49 +0000
commit5f52999c016495be1c34effdacd230a79cb52d0b (patch)
treed4c0cadb808185ae8d8c6b03dea370b33cce78e5
parent348738751c50c7d3c4c9ed22801a0c2cb917b790 (diff)
make use F_CLOEXEC wherever useful
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@174 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--doc/todo1
-rw-r--r--polyp/mainloop-signal.c2
-rw-r--r--polyp/module-pipe-sink.c2
-rw-r--r--polyp/oss-util.c3
-rw-r--r--polyp/socket-client.c3
-rw-r--r--polyp/socket-server.c7
-rw-r--r--polyp/socket-util.c1
-rw-r--r--polyp/util.c15
-rw-r--r--polyp/util.h2
9 files changed, 35 insertions, 1 deletions
diff --git a/doc/todo b/doc/todo
index 19afa7fa..7c1cf71e 100644
--- 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
diff --git a/polyp/mainloop-signal.c b/polyp/mainloop-signal.c
index f7ff7e93..a16d8457 100644
--- a/polyp/mainloop-signal.c
+++ b/polyp/mainloop-signal.c
@@ -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);
diff --git a/polyp/module-pipe-sink.c b/polyp/module-pipe-sink.c
index 32a2c722..088ed405 100644
--- a/polyp/module-pipe-sink.c
+++ b/polyp/module-pipe-sink.c
@@ -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;
diff --git a/polyp/oss-util.c b/polyp/oss-util.c
index 4fb2b929..b28c3dc9 100644
--- a/polyp/oss-util.c
+++ b/polyp/oss-util.c
@@ -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;
diff --git a/polyp/socket-client.c b/polyp/socket-client.c
index 25940122..f697cbdb 100644
--- a/polyp/socket-client.c
+++ b/polyp/socket-client.c
@@ -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
diff --git a/polyp/socket-server.c b/polyp/socket-server.c
index f01e417c..131339ed 100644
--- a/polyp/socket-server.c
+++ b/polyp/socket-server.c
@@ -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));
diff --git a/polyp/socket-util.c b/polyp/socket-util.c
index f9d0febf..1f93ef88 100644
--- a/polyp/socket-util.c
+++ b/polyp/socket-util.c
@@ -217,3 +217,4 @@ finish:
pa_xfree(dir);
return ret;
}
+
diff --git a/polyp/util.c b/polyp/util.c
index 0d930118..a3276fdf 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -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;
+}
diff --git a/polyp/util.h b/polyp/util.h
index 89505cde..f8dd3f04 100644
--- a/polyp/util.h
+++ b/polyp/util.h
@@ -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