From d9c4c9509d34ba89db06ff1252f3da18c6fd623b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 12 Sep 2007 00:17:51 +0000 Subject: [PATCH] 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 --- src/daemon/cpulimit.c | 6 +----- src/daemon/main.c | 10 +--------- src/pulse/context.c | 5 +---- src/pulse/mainloop-signal.c | 4 +--- src/pulse/mainloop.c | 5 +---- src/pulsecore/core-util.c | 13 +++++++++++++ src/pulsecore/core-util.h | 2 ++ src/pulsecore/fdsem.c | 3 +-- 8 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index 4f0adc0..0fe11ea 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 0bbddff..93d4eb6 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 1ed250f..a39646d 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 d2d42d9..b6414c4 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 fc373d9..641eded 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 62a6376..5becdef 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 fcafe63..efd19f4 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 710a74f..68207a7 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); } -- 2.7.4