summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-09-12 00:17:51 +0000
committerLennart Poettering <lennart@poettering.net>2007-09-12 00:17:51 +0000
commitd9c4c9509d34ba89db06ff1252f3da18c6fd623b (patch)
treec43528c07e55bd4aaa2cf618056e7679c9c7f14a
parent7f92542420ef6085b6f090954052266cc70af8a1 (diff)
add new pa_pipe_close() API to close two fds at the same time
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1812 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/daemon/cpulimit.c6
-rw-r--r--src/daemon/main.c10
-rw-r--r--src/pulse/context.c5
-rw-r--r--src/pulse/mainloop-signal.c4
-rw-r--r--src/pulse/mainloop.c5
-rw-r--r--src/pulsecore/core-util.c13
-rw-r--r--src/pulsecore/core-util.h2
-rw-r--r--src/pulsecore/fdsem.c3
8 files changed, 21 insertions, 27 deletions
diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c
index 4f0adc06..0fe11ea6 100644
--- a/src/daemon/cpulimit.c
+++ b/src/daemon/cpulimit.c
@@ -222,11 +222,7 @@ void pa_cpu_limit_done(void) {
api = NULL;
}
- if (the_pipe[0] >= 0)
- pa_assert_se(pa_close(the_pipe[0]) == 0);
- if (the_pipe[1] >= 0)
- pa_assert_se(pa_close(the_pipe[1]) == 0);
- the_pipe[0] = the_pipe[1] = -1;
+ pa_close_pipe(the_pipe);
if (installed) {
pa_assert_se(sigaction(SIGXCPU, &sigaction_prev, NULL) >= 0);
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 0bbddffa..93d4eb6b 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -158,14 +158,6 @@ static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e,
}
}
-static void close_pipe(int p[2]) {
- if (p[0] != -1)
- pa_assert_se(pa_close(p[0]) == 0);
- if (p[1] != -1)
- pa_assert_se(pa_close(p[1]) == 0);
- p[0] = p[1] = -1;
-}
-
#define set_env(key, value) putenv(pa_sprintf_malloc("%s=%s", (key), (value)))
#if defined(HAVE_PWD_H) && defined(HAVE_GRP_H)
@@ -745,7 +737,7 @@ finish:
if (valid_pid_file)
pa_pid_file_remove();
- close_pipe(daemon_pipe);
+ pa_close_pipe(daemon_pipe);
#ifdef OS_IS_WIN32
WSACleanup();
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 1ed250f9..a39646d3 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -585,10 +585,7 @@ static int context_connect_spawn(pa_context *c) {
return 0;
fail:
- if (fds[0] != -1)
- pa_assert_se(pa_close(fds[0]) == 0);
- if (fds[1] != -1)
- pa_assert_se(pa_close(fds[1]) == 0);
+ pa_close_pipe(fds);
unlock_autospawn_lock_file(c);
diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c
index d2d42d99..b6414c4e 100644
--- a/src/pulse/mainloop-signal.c
+++ b/src/pulse/mainloop-signal.c
@@ -147,9 +147,7 @@ void pa_signal_done(void) {
api->io_free(io_event);
io_event = NULL;
- pa_assert_se(close(signal_pipe[0]) == 0);
- pa_assert_se(close(signal_pipe[1]) == 0);
- signal_pipe[0] = signal_pipe[1] = -1;
+ pa_close_pipe(signal_pipe);
api = NULL;
}
diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index fc373d97..641eded4 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -605,10 +605,7 @@ void pa_mainloop_free(pa_mainloop* m) {
pa_xfree(m->pollfds);
- if (m->wakeup_pipe[0] >= 0)
- pa_assert_se(pa_close(m->wakeup_pipe[0]) == 0);
- if (m->wakeup_pipe[1] >= 0)
- pa_assert_se(pa_close(m->wakeup_pipe[1]) == 0);
+ pa_close_pipe(m->wakeup_pipe);
pa_xfree(m);
}
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 62a63761..5becdef0 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -1323,3 +1323,16 @@ void *pa_will_need(const void *p, size_t l) {
return (void*) p;
}
+
+void pa_close_pipe(int fds[2]) {
+ pa_assert(fds);
+
+ if (fds[0] >= 0)
+ pa_assert_se(pa_close(fds[0]) == 0);
+
+ if (fds[1] >= 0)
+ pa_assert_se(pa_close(fds[1]) == 0);
+
+ fds[0] = fds[1] = -1;
+}
+
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index fcafe63d..efd19f45 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -120,4 +120,6 @@ static inline unsigned pa_make_power_of_two(unsigned n) {
return n + 1;
}
+void pa_close_pipe(int fds[2]);
+
#endif
diff --git a/src/pulsecore/fdsem.c b/src/pulsecore/fdsem.c
index 710a74f5..68207a76 100644
--- a/src/pulsecore/fdsem.c
+++ b/src/pulsecore/fdsem.c
@@ -67,8 +67,7 @@ pa_fdsem *pa_fdsem_new(void) {
void pa_fdsem_free(pa_fdsem *f) {
pa_assert(f);
- pa_assert_se(pa_close(f->fds[0]) == 0);
- pa_assert_se(pa_close(f->fds[1]) == 0);
+ pa_close_pipe(f->fds);
pa_xfree(f);
}