From 781eb594bb77ea814976c6628483b7ba9de2db70 Mon Sep 17 00:00:00 2001 From: Jason Newton Date: Thu, 8 Oct 2009 20:46:52 -0700 Subject: module-equalizer-sink: fixed equalizer state save/restore --- src/modules/module-equalizer-sink.c | 56 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/modules/module-equalizer-sink.c b/src/modules/module-equalizer-sink.c index 3a28b497..f5c1fb70 100755 --- a/src/modules/module-equalizer-sink.c +++ b/src/modules/module-equalizer-sink.c @@ -814,33 +814,35 @@ static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t s static void pack(char **strs, size_t len, char **packed, size_t *length){ size_t t_len = 0; size_t headers = (1+len) * sizeof(uint16_t); - size_t offset = sizeof(uint16_t); + char *p; for(size_t i = 0; i < len; ++i){ t_len += strlen(strs[i]); } *length = headers + t_len; - *packed = pa_xmalloc0(*length); - ((uint16_t *) *packed)[0] = (uint16_t) len; + p = *packed = pa_xmalloc0(*length); + *((uint16_t *) p) = (uint16_t) len; + p += sizeof(uint16_t); for(size_t i = 0; i < len; ++i){ uint16_t l = strlen(strs[i]); - *((uint16_t *)(*packed + offset)) = l; - offset += sizeof(uint16_t); - memcpy(*packed + offset, strs[i], l); - offset += l; + *((uint16_t *) p) = (uint16_t) l; + p += sizeof(uint16_t); + memcpy(p, strs[i], l); + p += l; } } static void unpack(char *str, size_t length, char ***strs, size_t *len){ - size_t offset = sizeof(uint16_t); - *len = ((uint16_t *)str)[0]; + char *p = str; + *len = *((uint16_t *) p); + p += sizeof(uint16_t); *strs = pa_xnew(char *, *len); + for(size_t i = 0; i < *len; ++i){ - size_t l = *((uint16_t *)(str+offset)); - size_t e = PA_MIN(offset + l, length) - offset; - offset = PA_MIN(offset + sizeof(uint16_t), length); - (*strs)[i] = pa_xnew(char, e + 1); - memcpy((*strs)[i], str + offset, e); - (*strs)[i][e] = '\0'; - offset += l; + size_t l = *((uint16_t *) p); + p += sizeof(uint16_t); + (*strs)[i] = pa_xnew(char, l + 1); + memcpy((*strs)[i], p, l); + (*strs)[i][l] = '\0'; + p += l; } } static void save_profile(struct userdata *u, size_t channel, char *name){ @@ -885,17 +887,17 @@ static void save_state(struct userdata *u){ pack(u->base_profiles, u->channels, &packed, &packed_length); state = (float *) pa_xmalloc0(filter_state_size + packed_length); + memcpy(state + FILTER_STATE_SIZE, packed, packed_length); + pa_xfree(packed); for(size_t c = 0; c < u->channels; ++c){ a_i = pa_aupdate_read_begin(u->a_H[c]); - state[c * CHANNEL_PROFILE_SIZE] = u->Xs[a_i][c]; + state[c * CHANNEL_PROFILE_SIZE] = u->Xs[c][a_i]; H = u->Hs[c][a_i]; - H_n = state + c * CHANNEL_PROFILE_SIZE + 1; + H_n = &state[c * CHANNEL_PROFILE_SIZE + 1]; memcpy(H_n, H, FILTER_SIZE * sizeof(float)); pa_aupdate_read_end(u->a_H[c]); } - memcpy(((char *)state) + filter_state_size, packed, packed_length); - pa_xfree(packed); key.data = state_name; key.size = strlen(key.data); @@ -978,13 +980,13 @@ static void load_state(struct userdata *u){ memcpy(u->Hs[c][a_i], H, FILTER_SIZE * sizeof(float)); pa_aupdate_write_end(u->a_H[c]); } - //unpack(((char *)value.data) + FILTER_STATE_SIZE, value.size - FILTER_STATE_SIZE, &names, &n_profs); - //n_profs = PA_MIN(n_profs, u->channels); - //for(size_t c = 0; c < n_profs; ++c){ - // pa_xfree(u->base_profiles[c]); - // u->base_profiles[c] = names[c]; - //} - //pa_xfree(names); + unpack(((char *)value.data) + FILTER_STATE_SIZE * sizeof(float), value.size - FILTER_STATE_SIZE * sizeof(float), &names, &n_profs); + n_profs = PA_MIN(n_profs, u->channels); + for(size_t c = 0; c < n_profs; ++c){ + pa_xfree(u->base_profiles[c]); + u->base_profiles[c] = names[c]; + } + pa_xfree(names); } pa_datum_free(&value); }else{ -- cgit From 8f2289c563090562d194c6336ccf4ba75a1eacd0 Mon Sep 17 00:00:00 2001 From: Jason Newton Date: Sun, 18 Oct 2009 14:52:32 -0700 Subject: module-equalizer-sink: *fixed SSE2 optimized dsp logic (default if available) *cleaned up whitespace formatting (again) --- src/modules/module-equalizer-sink.c | 186 +++++++++++++++++------------------- 1 file changed, 90 insertions(+), 96 deletions(-) diff --git a/src/modules/module-equalizer-sink.c b/src/modules/module-equalizer-sink.c index f5c1fb70..814a00fa 100755 --- a/src/modules/module-equalizer-sink.c +++ b/src/modules/module-equalizer-sink.c @@ -337,7 +337,7 @@ static void sink_set_mute_cb(pa_sink *s) { pa_sink_input_set_mute(u->sink_input, s->muted, s->save_muted); } - +#ifndef __SSE2__ //reference implementation static void dsp_logic( float * restrict dst,//used as a temp array too, needs to be fft_length! @@ -351,12 +351,12 @@ static void dsp_logic( fftwf_complex * restrict output_window,//The transformed window'd src struct userdata *u){ //use a linear-phase sliding STFT and overlap-add method (for each channel) - //zero padd the data - memset(dst + u->window_size, 0, (u->fft_size - u->window_size) * sizeof(float)); //window the data for(size_t j = 0; j < u->window_size; ++j){ dst[j] = X * W[j] * src[j]; } + //zero padd the the remaining fft window + memset(dst + u->window_size, 0, (u->fft_size - u->window_size) * sizeof(float)); //Processing is done here! //do fft fftwf_execute_dft_r2c(u->forward_plan, dst, output_window); @@ -390,112 +390,104 @@ static void dsp_logic( (u->samples_gathered - u->R) * sizeof(float) ); } - +#else typedef float v4sf __attribute__ ((__aligned__(v_size * sizeof(float)))); typedef union float_vector { float f[v_size]; v4sf v; -#ifdef __SSE2__ __m128 m; -#endif } float_vector_t; -////regardless of sse enabled, the loops in here assume -////16 byte aligned addresses and memory allocations divisible by v_size -//void dsp_logic( -// float * restrict dst,//used as a temp array too, needs to be fft_length! -// float * restrict src,/*input data w/ overlap at start, -// *automatically cycled in routine -// */ -// float * restrict overlap,//The size of the overlap -// const float X,//multipliar -// const float * restrict H,//The freq. magnitude scalers filter -// const float * restrict W,//The windowing function -// fftwf_complex * restrict output_window,//The transformed window'd src -// struct userdata *u){//Collection of constants - //float_vector_t x = {X, X, X, X}; -// const size_t window_size = PA_ROUND_UP(u->window_size,v_size); -// const size_t fft_h = PA_ROUND_UP(FILTER_SIZE, v_size / 2); -// //const size_t R = PA_ROUND_UP(u->R, v_size); -// const size_t overlap_size = PA_ROUND_UP(u->overlap_size, v_size); -// overlap_size = PA_ROUND_UP(u->overlap_size, v_size); -// -// //assert(u->samples_gathered >= u->R); -// //zero out the bit beyond the real overlap so we don't add garbage -// for(size_t j = overlap_size; j > u->overlap_size; --j){ -// overlap[j-1] = 0; -// } -// //use a linear-phase sliding STFT and overlap-add method -// //zero padd the data -// memset(dst + u->window_size, 0, (u->fft_size - u->window_size)*sizeof(float)); -// //window the data -// for(size_t j = 0; j < window_size; j += v_size){ -// //dst[j] = W[j]*src[j]; -// float_vector_t *d = (float_vector_t*) (dst+j); -// float_vector_t *w = (float_vector_t*) (W+j); -// float_vector_t *s = (float_vector_t*) (src+j); +//regardless of sse enabled, the loops in here assume +//16 byte aligned addresses and memory allocations divisible by v_size +static void dsp_logic( + float * restrict dst,//used as a temp array too, needs to be fft_length! + float * restrict src,/*input data w/ overlap at start, + *automatically cycled in routine + */ + float * restrict overlap,//The size of the overlap + const float X,//multipliar + const float * restrict H,//The freq. magnitude scalers filter + const float * restrict W,//The windowing function + fftwf_complex * restrict output_window,//The transformed window'd src + struct userdata *u){//Collection of constants + const size_t overlap_size = PA_ROUND_UP(u->overlap_size, v_size); + + + //assert(u->samples_gathered >= u->R); + //use a linear-phase sliding STFT and overlap-add method + for(size_t j = 0; j < u->window_size; j += v_size){ + //dst[j] = W[j] * src[j]; + float_vector_t *d = (float_vector_t*) (dst + j); + float_vector_t *w = (float_vector_t*) (W + j); + float_vector_t *s = (float_vector_t*) (src + j); //#if __SSE2__ -// d->m = _mm_mul_ps(x->m, _mm_mul_ps(w->m, s->m)); + d->m = _mm_mul_ps(w->m, s->m); //#else -// d->v = x->v * w->v * s->v; +// d->v = w->v * s->v; //#endif -// } -// //Processing is done here! -// //do fft -// fftwf_execute_dft_r2c(u->forward_plan, dst, output_window); -// -// -// //perform filtering - purely magnitude based -// for(size_t j = 0;j < fft_h; j+=v_size/2){ -// //output_window[j][0]*=H[j]; -// //output_window[j][1]*=H[j]; -// float_vector_t *d = (float_vector_t*)(output_window+j); -// float_vector_t h; -// h.f[0] = h.f[1] = H[j]; -// h.f[2] = h.f[3] = H[j+1]; + } + //zero padd the the remaining fft window + memset(dst + u->window_size, 0, (u->fft_size - u->window_size) * sizeof(float)); + + //Processing is done here! + //do fft + fftwf_execute_dft_r2c(u->forward_plan, dst, output_window); + //perform filtering - purely magnitude based + for(size_t j = 0; j < FILTER_SIZE; j += v_size / 2){ + //output_window[j][0]*=H[j]; + //output_window[j][1]*=H[j]; + float_vector_t *d = (float_vector_t*)( ((float *) output_window) + 2 * j); + float_vector_t h; + h.f[0] = h.f[1] = H[j]; + h.f[2] = h.f[3] = H[j + 1]; //#if __SSE2__ -// d->m = _mm_mul_ps(d->m, h.m); + d->m = _mm_mul_ps(d->m, h.m); //#else -// d->v = d->v*h->v; +// d->v = d->v * h.v; //#endif -// } -// //inverse fft -// fftwf_execute_dft_c2r(u->inverse_plan, output_window, dst); -// -// ////debug: tests overlaping add -// ////and negates ALL PREVIOUS processing -// ////yields a perfect reconstruction if COLA is held -// //for(size_t j = 0; j < u->window_size; ++j){ -// // dst[j] = W[j]*src[j]; -// //} -// -// //overlap add and preserve overlap component from this window (linear phase) -// for(size_t j = 0; j < overlap_size; j+=v_size){ -// //dst[j]+=overlap[j]; -// //overlap[j]+=dst[j+R]; -// float_vector_t *d = (float_vector_t*)(dst+j); -// float_vector_t *o = (float_vector_t*)(overlap+j); + } + + //inverse fft + fftwf_execute_dft_c2r(u->inverse_plan, output_window, dst); + + ////debug: tests overlaping add + ////and negates ALL PREVIOUS processing + ////yields a perfect reconstruction if COLA is held + //for(size_t j = 0; j < u->window_size; ++j){ + // dst[j] = W[j] * src[j]; + //} + + //overlap add and preserve overlap component from this window (linear phase) + for(size_t j = 0; j < overlap_size; j += v_size){ + //dst[j]+=overlap[j]; + //overlap[j]+=dst[j+R]; + float_vector_t *d = (float_vector_t*)(dst + j); + float_vector_t *o = (float_vector_t*)(overlap + j); //#if __SSE2__ -// d->m = _mm_add_ps(d->m, o->m); -// o->m = ((float_vector_t*)(dst+u->R+j))->m; + d->m = _mm_add_ps(d->m, o->m); + o->m = ((float_vector_t*)(dst + u->R + j))->m; //#else -// d->v = d->v+o->v; -// o->v = ((float_vector_t*)(dst+u->R+j))->v; +// d->v = d->v + o->v; +// o->v = ((float_vector_t*)(dst + u->R + j))->v; //#endif -// } -// //memcpy(overlap, dst+u->R, u->overlap_size*sizeof(float)); -// -// //////debug: tests if basic buffering works -// //////shouldn't modify the signal AT ALL (beyond roundoff) -// //for(size_t j = 0; j < u->window_size; ++j){ -// // dst[j] = src[j]; -// //} -// -// //preseve the needed input for the next window's overlap -// memmove(src, src + u->R, -// u->overlap_size * sizeof(float) -// ); -//} + } + //memcpy(overlap, dst+u->R, u->overlap_size * sizeof(float)); //overlap preserve (debug) + //zero out the bit beyond the real overlap so we don't add garbage next iteration + memset(overlap + u->overlap_size, 0, overlap_size - u->overlap_size); + + ////debug: tests if basic buffering works + ////shouldn't modify the signal AT ALL (beyond roundoff) + //for(size_t j = 0; j < u->window_size; ++j){ + // dst[j] = src[j]; + //} + + //preseve the needed input for the next window's overlap + memmove(src, src + u->R, + (u->samples_gathered - u->R) * sizeof(float) + ); +} +#endif static void process_samples(struct userdata *u, pa_memchunk *tchunk){ size_t fs = pa_frame_size(&(u->sink->sample_spec)); @@ -685,7 +677,7 @@ static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) { //invalidate the output q pa_memblockq_seek(u->input_q, - (int64_t) amount, PA_SEEK_RELATIVE, TRUE); pa_log("Resetting filter"); - reset_filter(u); + //reset_filter(u); //this is the "proper" thing to do... } } @@ -1064,9 +1056,12 @@ int pa__init(pa_module*m) { pa_modargs_get_value_boolean(ma, "set_default", &u->set_default); u->channels = ss.channels; - u->fft_size = pow(2, ceil(log(ss.rate)/log(2)));//probably unstable near corner cases of powers of 2 + u->fft_size = pow(2, ceil(log(ss.rate) / log(2)));//probably unstable near corner cases of powers of 2 pa_log_debug("fft size: %ld", u->fft_size); u->window_size = 15999; + if(u->window_size % 2 == 0){ + u->window_size--; + } u->R = (u->window_size + 1) / 2; u->overlap_size = u->window_size - u->R; u->samples_gathered = 0; @@ -1090,7 +1085,6 @@ int pa__init(pa_module*m) { u->a_H[c] = pa_aupdate_new(); u->input[c] = NULL; u->overlap_accum[c] = alloc(u->overlap_size, sizeof(float)); - memset(u->overlap_accum[c], 0, u->overlap_size*sizeof(float)); } u->output_window = alloc((FILTER_SIZE), sizeof(fftwf_complex)); u->forward_plan = fftwf_plan_dft_r2c_1d(u->fft_size, u->work_buffer, u->output_window, FFTW_ESTIMATE); -- cgit From d25b9eab0fff1040713cf297f40450e0f7641870 Mon Sep 17 00:00:00 2001 From: Jason Newton Date: Mon, 19 Oct 2009 18:28:25 -0700 Subject: module-equalizer-sink: drop source executable permissions configure.ac: add enable/disable + summary line for fftw --- configure.ac | 6 ++++++ src/modules/module-equalizer-sink.c | 0 2 files changed, 6 insertions(+) mode change 100755 => 100644 src/modules/module-equalizer-sink.c diff --git a/configure.ac b/configure.ac index 77ec8846..b34821ad 100644 --- a/configure.ac +++ b/configure.ac @@ -1513,6 +1513,11 @@ if test "x${HAVE_SIMPLEDB}" = "x1" ; then ENABLE_SIMPLEDB=yes fi +ENABLE_FFTW=no +if test "x${HAVE_FFTW}" = "x1" ; then + ENABLE_FFTW=yes +fi + ENABLE_OPENSSL=no if test "x${HAVE_OPENSSL}" = "x1" ; then ENABLE_OPENSSL=yes @@ -1563,6 +1568,7 @@ echo " Enable tdb: ${ENABLE_TDB} Enable gdbm: ${ENABLE_GDBM} Enable simple database: ${ENABLE_SIMPLEDB} + Enable fftw: ${ENABLE_FFTW} System User: ${PA_SYSTEM_USER} System Group: ${PA_SYSTEM_GROUP} diff --git a/src/modules/module-equalizer-sink.c b/src/modules/module-equalizer-sink.c old mode 100755 new mode 100644 -- cgit From 744490a681be7356efba4160bfb29a3e76e85888 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 21:29:01 +0100 Subject: memblock: decrease tile size to 64k again --- src/pulsecore/memblock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c index eac4a59b..f38b17c6 100644 --- a/src/pulsecore/memblock.c +++ b/src/pulsecore/memblock.c @@ -54,7 +54,7 @@ * stored in SHM and our OS does not commit the memory before we use * it for the first time. */ #define PA_MEMPOOL_SLOTS_MAX 1024 -#define PA_MEMPOOL_SLOT_SIZE (128*1024) +#define PA_MEMPOOL_SLOT_SIZE (64*1024) #define PA_MEMEXPORT_SLOTS_MAX 128 -- cgit From 4538523a2999ee36e19f3f09a8ca5328185f9a67 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 23:26:48 +0100 Subject: libpulse: introduce pa_context_get_tile_size() call --- src/map-file | 1 + src/pulse/context.c | 17 +++++++++++++++++ src/pulse/context.h | 22 +++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/map-file b/src/map-file index 6f7bdace..50111224 100644 --- a/src/map-file +++ b/src/map-file @@ -66,6 +66,7 @@ pa_context_get_source_info_list; pa_context_get_source_output_info; pa_context_get_source_output_info_list; pa_context_get_state; +pa_context_get_tile_size; pa_context_is_local; pa_context_is_pending; pa_context_kill_client; diff --git a/src/pulse/context.c b/src/pulse/context.c index 7468d0a9..e33143d9 100644 --- a/src/pulse/context.c +++ b/src/pulse/context.c @@ -1488,6 +1488,7 @@ pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_even struct timeval tv; pa_assert(c); + pa_assert(PA_REFCNT_VALUE(c) >= 1); pa_assert(c->mainloop); if (usec == PA_USEC_INVALID) @@ -1502,8 +1503,10 @@ void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec) struct timeval tv; pa_assert(c); + pa_assert(PA_REFCNT_VALUE(c) >= 1); pa_assert(c->mainloop); + if (usec == PA_USEC_INVALID) c->mainloop->time_restart(e, NULL); else { @@ -1511,3 +1514,17 @@ void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec) c->mainloop->time_restart(e, &tv); } } + +size_t pa_context_get_tile_size(pa_context *c, const pa_sample_spec *ss) { + size_t fs, mbs; + + pa_assert(c); + pa_assert(PA_REFCNT_VALUE(c) >= 1); + + PA_CHECK_VALIDITY_RETURN_ANY(c, !pa_detect_fork(), PA_ERR_FORKED, (size_t) -1); + PA_CHECK_VALIDITY_RETURN_ANY(c, !ss || pa_sample_spec_valid(ss), PA_ERR_INVALID, (size_t) -1); + + fs = ss ? pa_frame_size(ss) : 1; + mbs = PA_ROUND_DOWN(pa_mempool_block_size_max(c->mempool), fs); + return PA_MAX(mbs, fs); +} diff --git a/src/pulse/context.h b/src/pulse/context.h index ecff58df..6ac8ee56 100644 --- a/src/pulse/context.h +++ b/src/pulse/context.h @@ -255,12 +255,28 @@ pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[] uint32_t pa_context_get_index(pa_context *s); /** Create a new timer event source for the specified time (wrapper - for mainloop->time_new). \since 0.9.16 */ + * for mainloop->time_new). \since 0.9.16 */ pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata); -/** Restart a running or expired timer event source (wrapper - for mainloop->time_restart). \since 0.9.16 */ + +/** Restart a running or expired timer event source (wrapper for + * mainloop->time_restart). \since 0.9.16 */ void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec); +/* Return the optimal block size for passing around audio buffers. It + * is recommended to allocate buffers of the size returned here when + * writing audio data to playback streams, if the latency constraints + * permit this. It is not recommended writing larger blocks than this + * because usually they will then be split up internally into chunks + * of this size. It is not recommended writing smaller blocks than + * this (unless required due to latency demands) because this + * increases CPU usage. If ss is NULL you will be returned the + * byte-exact tile size. If you pass a valid ss, then the tile size + * will be rounded down to multiple of the frame size. This is + * supposed to be used in a construct such as + * pa_context_get_tile_size(pa_stream_get_context(s), + * pa_stream_get_sample_spec(ss)); \since 0.9.20 */ +size_t pa_context_get_tile_size(pa_context *c, const pa_sample_spec *ss); + PA_C_DECL_END #endif -- cgit From 7c55d6e91d21971e187bf9602dce38cb49666cc4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 23:27:14 +0100 Subject: clients: drop definition of BUFSIZE which is unused --- src/utils/pactl.c | 2 -- src/utils/pasuspender.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/utils/pactl.c b/src/utils/pactl.c index 141ab5b1..51de1204 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -44,8 +44,6 @@ #include #include -#define BUFSIZE (16*1024) - static pa_context *context = NULL; static pa_mainloop_api *mainloop_api = NULL; diff --git a/src/utils/pasuspender.c b/src/utils/pasuspender.c index c327ee41..534b77b4 100644 --- a/src/utils/pasuspender.c +++ b/src/utils/pasuspender.c @@ -45,8 +45,6 @@ #include #include -#define BUFSIZE 1024 - static pa_context *context = NULL; static pa_mainloop_api *mainloop_api = NULL; static char **child_argv = NULL; -- cgit From 8678f565322ccc1bfbaa0f21024f7255ed58b933 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 23:27:50 +0100 Subject: pactl: include information about client context in pactl stat output --- src/utils/pactl.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/utils/pactl.c b/src/utils/pactl.c index 51de1204..7ef02ec9 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -156,10 +156,23 @@ static void get_server_info_callback(pa_context *c, const pa_server_info *i, voi return; } + printf(_("Server String: %s\n" + "Library Protocol Version: %u\n" + "Server Protocol Version: %u\n" + "Is Local: %s\n" + "Client Index: %u\n" + "Tile Size: %zu\n"), + pa_context_get_server(c), + pa_context_get_protocol_version(c), + pa_context_get_server_protocol_version(c), + pa_yes_no(pa_context_is_local(c)), + pa_context_get_index(c), + pa_context_get_tile_size(c, NULL)); + pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec); pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map); - printf(_("User name: %s\n" + printf(_("User Name: %s\n" "Host Name: %s\n" "Server Name: %s\n" "Server Version: %s\n" -- cgit From 78984e439553f5e6eeb97c90ec1df9141fbe91d8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 23:28:12 +0100 Subject: pactl: format cookie a little bit nicer --- src/utils/pactl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/pactl.c b/src/utils/pactl.c index 7ef02ec9..ee67c425 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -180,7 +180,7 @@ static void get_server_info_callback(pa_context *c, const pa_server_info *i, voi "Default Channel Map: %s\n" "Default Sink: %s\n" "Default Source: %s\n" - "Cookie: %08x\n"), + "Cookie: %04x:%04x\n"), i->user_name, i->host_name, i->server_name, @@ -189,7 +189,8 @@ static void get_server_info_callback(pa_context *c, const pa_server_info *i, voi cm, i->default_sink_name, i->default_source_name, - i->cookie); + i->cookie >> 16, + i->cookie & 0xFFFFU); complete_action(); } -- cgit From 27c6a80ccb9ccfdd00524360938599cf2d14d4b6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 23:47:21 +0100 Subject: protocol-native: declare that user configured volumes are always absolute --- src/pulsecore/protocol-native.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index d06dd4eb..b7471c0a 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1047,8 +1047,10 @@ static playback_stream* playback_stream_new( data.sink = sink; pa_sink_input_new_data_set_sample_spec(&data, ss); pa_sink_input_new_data_set_channel_map(&data, map); - if (volume) + if (volume) { pa_sink_input_new_data_set_volume(&data, volume); + data.volume_is_absolute = TRUE; + } if (muted_set) pa_sink_input_new_data_set_muted(&data, muted); data.sync_base = ssync ? ssync->sink_input : NULL; -- cgit From 2501687579e359d5032a4d165b2ffc8f5b1b8ba6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 23:47:50 +0100 Subject: libpulse: explain semantics of pa_stream_connect_playback() in more detail --- src/pulse/stream.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pulse/stream.h b/src/pulse/stream.h index 2e8e71a0..bc54a118 100644 --- a/src/pulse/stream.h +++ b/src/pulse/stream.h @@ -401,7 +401,22 @@ int pa_stream_is_suspended(pa_stream *s); * not, and negative on error. \since 0.9.11 */ int pa_stream_is_corked(pa_stream *s); -/** Connect the stream to a sink */ +/** Connect the stream to a sink. It is strongly recommended to pass + * NULL in both dev and volume and not to set either + * PA_STREAM_START_MUTED nor PA_STREAM_START_UNMUTED -- unless these + * options are directly dependant on user input or configuration. If + * you follow this rule then the sound server will have the full + * flexibility to choose the device, volume and mute status + * automatically, based on server-side policies, heuristics and stored + * information from previous uses. Also the server may choose to + * reconfigure audio devices to make other sinks/sources or + * capabilities available to be able to accept the stream. Before + * 0.9.20 it was not defined whether the 'volume' parameter was + * interpreted relative to the sink's current volume or treated as + * absolute device volume. Since 0.9.20 it is an absolute volume when + * the sink is in flat volume mode, and relative otherwise, thus + * making sure the volume passed here has always the same semantics as + * the volume passed to pa_context_set_sink_input_volume(). */ int pa_stream_connect_playback( pa_stream *s /**< The stream to connect to a sink */, const char *dev /**< Name of the sink to connect to, or NULL for default */ , -- cgit From 546bcf3f2f9711f0d08c21c3b775994844e7e2a2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2009 23:50:42 +0100 Subject: protocol-native: if a client set volume/mute/device store it since it is user input --- src/pulsecore/protocol-native.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index b7471c0a..010420ef 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1044,15 +1044,21 @@ static playback_stream* playback_stream_new( data.driver = __FILE__; data.module = c->options->module; data.client = c->client; - data.sink = sink; + if (sink) { + data.sink = sink; + data.save_sink = TRUE; + } pa_sink_input_new_data_set_sample_spec(&data, ss); pa_sink_input_new_data_set_channel_map(&data, map); if (volume) { pa_sink_input_new_data_set_volume(&data, volume); data.volume_is_absolute = TRUE; + data.save_volume = TRUE; } - if (muted_set) + if (muted_set) { pa_sink_input_new_data_set_muted(&data, muted); + data.save_muted = TRUE; + } data.sync_base = ssync ? ssync->sink_input : NULL; data.flags = flags; -- cgit From f27a50691c8fe45bac7dd6b21fac91a359def3a1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 29 Oct 2009 00:46:22 +0100 Subject: libpulse: introduce PA_STREAM_RELATIVE_VOLUME --- PROTOCOL | 6 ++++++ configure.ac | 2 +- src/pulse/def.h | 10 +++++++++- src/pulse/stream.c | 10 +++++++++- src/pulsecore/protocol-native.c | 17 ++++++++++++++--- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/PROTOCOL b/PROTOCOL index 92cc2832..883b8bb6 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -188,3 +188,9 @@ new messages: PA_COMMAND_SET_SINK_PORT PA_COMMAND_SET_SOURCE_PORT + +## v17, implemented by >= 0.9.20 + +new flag at end of CREATE_PLAYBACK_STREAM: + + bool relative_volume diff --git a/configure.ac b/configure.ac index b34821ad..d7f55acf 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ AC_SUBST(PA_MAJORMINORMICRO, pa_major.pa_minor.pa_micro) AC_SUBST(PACKAGE_URL, [http://pulseaudio.org/]) AC_SUBST(PA_API_VERSION, 12) -AC_SUBST(PA_PROTOCOL_VERSION, 16) +AC_SUBST(PA_PROTOCOL_VERSION, 17) # The stable ABI for client applications, for the version info x:y:z # always will hold y=z diff --git a/src/pulse/def.h b/src/pulse/def.h index 5d0a0b4b..30a076d5 100644 --- a/src/pulse/def.h +++ b/src/pulse/def.h @@ -276,11 +276,18 @@ typedef enum pa_stream_flags { * whether to create the stream in muted or in unmuted * state. \since 0.9.15 */ - PA_STREAM_FAIL_ON_SUSPEND = 0x20000U + PA_STREAM_FAIL_ON_SUSPEND = 0x20000U, /**< If the sink/source this stream is connected to is suspended * during the creation of this stream, cause it to fail. If the * sink/source is being suspended during creation of this stream, * make sure this stream is terminated. \since 0.9.15 */ + + PA_STREAM_RELATIVE_VOLUME = 0x40000U, + /**< If a volume is passed when this stream is created, consider + * it relative to the sink's current volume, never as absolute + * device volume. If this is not specified the volume will be + * consider absolute when the sink is in flat volume mode, + * relative otherwise. \since 0.9.20 */ } pa_stream_flags_t; /** \cond fulldocs */ @@ -307,6 +314,7 @@ typedef enum pa_stream_flags { #define PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND #define PA_STREAM_START_UNMUTED PA_STREAM_START_UNMUTED #define PA_STREAM_FAIL_ON_SUSPEND PA_STREAM_FAIL_ON_SUSPEND +#define PA_STREAM_RELATIVE_VOLUME PA_STREAM_RELATIVE_VOLUME /** \endcond */ diff --git a/src/pulse/stream.c b/src/pulse/stream.c index 2bc2b1e4..29979625 100644 --- a/src/pulse/stream.c +++ b/src/pulse/stream.c @@ -1025,7 +1025,8 @@ static int create_stream( PA_STREAM_EARLY_REQUESTS| PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND| PA_STREAM_START_UNMUTED| - PA_STREAM_FAIL_ON_SUSPEND)), PA_ERR_INVALID); + PA_STREAM_FAIL_ON_SUSPEND| + PA_STREAM_RELATIVE_VOLUME)), PA_ERR_INVALID); PA_CHECK_VALIDITY(s->context, s->context->version >= 12 || !(flags & PA_STREAM_VARIABLE_RATE), PA_ERR_NOTSUPPORTED); PA_CHECK_VALIDITY(s->context, s->context->version >= 13 || !(flags & PA_STREAM_PEAK_DETECT), PA_ERR_NOTSUPPORTED); @@ -1158,6 +1159,13 @@ static int create_stream( pa_tagstruct_put_boolean(t, flags & PA_STREAM_FAIL_ON_SUSPEND); } + if (s->context->version >= 17) { + + if (s->direction == PA_STREAM_PLAYBACK) + pa_tagstruct_put_boolean(t, flags & PA_STREAM_RELATIVE_VOLUME); + + } + pa_pstream_send_tagstruct(s->context->pstream, t); pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s, NULL); diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 010420ef..bb29a196 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1002,6 +1002,7 @@ static playback_stream* playback_stream_new( pa_proplist *p, pa_bool_t adjust_latency, pa_bool_t early_requests, + pa_bool_t relative_volume, int *ret) { playback_stream *s, *ssync; @@ -1052,7 +1053,7 @@ static playback_stream* playback_stream_new( pa_sink_input_new_data_set_channel_map(&data, map); if (volume) { pa_sink_input_new_data_set_volume(&data, volume); - data.volume_is_absolute = TRUE; + data.volume_is_absolute = !relative_volume; data.save_volume = TRUE; } if (muted_set) { @@ -1846,7 +1847,8 @@ static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, u early_requests = FALSE, dont_inhibit_auto_suspend = FALSE, muted_set = FALSE, - fail_on_suspend = FALSE; + fail_on_suspend = FALSE, + relative_volume = FALSE; pa_sink_input_flags_t flags = 0; pa_proplist *p; pa_bool_t volume_set = TRUE; @@ -1939,6 +1941,15 @@ static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, u } } + if (c->version >= 17) { + + if (pa_tagstruct_get_boolean(t, &relative_volume) < 0) { + protocol_error(c); + pa_proplist_free(p); + return; + } + } + if (!pa_tagstruct_eof(t)) { protocol_error(c); pa_proplist_free(p); @@ -1978,7 +1989,7 @@ static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, u * flag. For older versions we synthesize it here */ muted_set = muted_set || muted; - s = playback_stream_new(c, sink, &ss, &map, &attr, volume_set ? &volume : NULL, muted, muted_set, syncid, &missing, flags, p, adjust_latency, early_requests, &ret); + s = playback_stream_new(c, sink, &ss, &map, &attr, volume_set ? &volume : NULL, muted, muted_set, syncid, &missing, flags, p, adjust_latency, early_requests, relative_volume, &ret); pa_proplist_free(p); CHECK_VALIDITY(c->pstream, s, tag, ret); -- cgit From 2edb4df175ee69e386ec3923e69af6899f55e2eb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 29 Oct 2009 01:49:40 +0100 Subject: smoother: add comments about optimization recommendations from Jason Newton --- src/pulsecore/time-smoother.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pulsecore/time-smoother.c b/src/pulsecore/time-smoother.c index d6c37878..1371ad56 100644 --- a/src/pulsecore/time-smoother.c +++ b/src/pulsecore/time-smoother.c @@ -196,6 +196,13 @@ static double avg_gradient(pa_smoother *s, pa_usec_t x) { int64_t ax = 0, ay = 0, k, t; double r; + /* FIXME: Optimization: Jason Newton suggested that instead of + * going through the history on each iteration we could calculated + * avg_gradient() as we go. + * + * Second idea: it might make sense to weight history entries: + * more recent entries should matter more than old ones. */ + /* Too few measurements, assume gradient of 1 */ if (s->n_history < s->min_history) return 1; -- cgit From e7e4e4459e6dad888d1f9a01d0b185221e1a120e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 29 Oct 2009 01:52:39 +0100 Subject: simd: update test cases --- src/pulsecore/svolume_mmx.c | 4 ++++ src/pulsecore/svolume_sse.c | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 745c7de0..5bf72ed0 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -25,6 +25,8 @@ #endif #include +#include + #include #include #include @@ -287,6 +289,8 @@ static void run_test (void) { } stop = pa_rtclock_now(); pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start)); + + pa_assert_se(memcmp(samples_ref, samples, sizeof(samples)) == 0); } #endif diff --git a/src/pulsecore/svolume_sse.c b/src/pulsecore/svolume_sse.c index 1cc4e0aa..620524fa 100644 --- a/src/pulsecore/svolume_sse.c +++ b/src/pulsecore/svolume_sse.c @@ -25,6 +25,8 @@ #endif #include +#include + #include #include #include @@ -261,7 +263,7 @@ static void run_test (void) { func = pa_get_volume_func (PA_SAMPLE_S16NE); - printf ("checking SSE %zd\n", sizeof (samples)); + printf ("checking SSE2 %zd\n", sizeof (samples)); pa_random (samples, sizeof (samples)); memcpy (samples_ref, samples, sizeof (samples)); @@ -273,7 +275,7 @@ static void run_test (void) { volumes[i] = volumes[padding]; func (samples_ref, volumes, CHANNELS, sizeof (samples)); - pa_volume_s16ne_sse (samples, volumes, CHANNELS, sizeof (samples)); + pa_volume_s16ne_sse2 (samples, volumes, CHANNELS, sizeof (samples)); for (i = 0; i < SAMPLES; i++) { if (samples[i] != samples_ref[i]) { printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], @@ -284,7 +286,7 @@ static void run_test (void) { start = pa_rtclock_now(); for (j = 0; j < TIMES; j++) { memcpy (samples, samples_orig, sizeof (samples)); - pa_volume_s16ne_sse (samples, volumes, CHANNELS, sizeof (samples)); + pa_volume_s16ne_sse2 (samples, volumes, CHANNELS, sizeof (samples)); } stop = pa_rtclock_now(); pa_log_info("SSE: %llu usec.", (long long unsigned int)(stop - start)); @@ -296,6 +298,8 @@ static void run_test (void) { } stop = pa_rtclock_now(); pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start)); + + pa_assert_se(memcmp(samples_ref, samples, sizeof(samples)) == 0); } #endif #endif /* defined (__i386__) || defined (__amd64__) */ -- cgit From 9c1a98953f25aff7f11af80a073c9c46dee2438c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 03:30:42 +0100 Subject: core-util: introduce FD_CLOEXEC wrappers for open/socket/pipe/accept --- configure.ac | 2 +- src/pulsecore/core-util.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ src/pulsecore/core-util.h | 6 ++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d7f55acf..1022a6ea 100644 --- a/configure.ac +++ b/configure.ac @@ -445,7 +445,7 @@ AC_CHECK_FUNCS_ONCE([lstat]) # Non-standard -AC_CHECK_FUNCS_ONCE([setresuid setresgid setreuid setregid seteuid setegid ppoll strsignal sig2str strtof_l]) +AC_CHECK_FUNCS_ONCE([setresuid setresgid setreuid setregid seteuid setegid ppoll strsignal sig2str strtof_l pipe2 accept4]) AC_FUNC_ALLOCA diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 27e09cbc..34516eea 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2889,3 +2889,82 @@ const char *pa_get_temp_dir(void) { return "/tmp"; } + +int pa_open_cloexec(const char *fn, int flags, mode_t mode) { + int fd; + +#ifdef O_NOCTTY + flags |= O_NOCTTY; +#endif + +#ifdef O_CLOEXEC + if ((fd = open(fn, flags|O_CLOEXEC, mode)) >= 0) + return fd; + + if (errno != EINVAL) + return fd; +#endif + + if ((fd = open(fn, flags, mode)) < 0) + return fd; + + pa_make_fd_cloexec(fd); + return fd; +} + +int pa_socket_cloexec(int domain, int type, int protocol) { + int fd; + +#ifdef SOCK_CLOEXEC + if ((fd = socket(domain, type | SOCK_CLOEXEC, protocol)) >= 0) + return fd; + + if (errno != EINVAL) + return fd; +#endif + + if ((fd = socket(domain, type, protocol)) < 0) + return fd; + + pa_make_fd_cloexec(fd); + return fd; +} + +int pa_pipe_cloexec(int pipefd[2]) { + int r; + +#ifdef HAVE_PIPE2 + if ((r = pipe2(pipefd, O_CLOEXEC)) >= 0) + return r; + + if (errno != EINVAL && errno != ENOSYS) + return r; +#endif + + if ((r = pipe(pipefd)) < 0) + return r; + + pa_make_fd_cloexec(pipefd[0]); + pa_make_fd_cloexec(pipefd[1]); + + return 0; +} + +int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { + int fd; + +#ifdef HAVE_ACCEPT4 + if ((fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC)) >= 0) + return fd; + + if (errno != EINVAL && errno != ENOSYS) + return fd; +#endif + + if ((fd = accept(sockfd, addr, addrlen)) < 0) + return fd; + + pa_make_fd_cloexec(fd); + + return 0; +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 9986b14a..323fdcb4 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef HAVE_SYS_RESOURCE_H #include @@ -258,4 +259,9 @@ pa_bool_t pa_run_from_build_tree(void); const char *pa_get_temp_dir(void); +int pa_open_cloexec(const char *fn, int flags, mode_t mode); +int pa_socket_cloexec(int domain, int type, int protocol); +int pa_pipe_cloexec(int pipefd[2]); +int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen); + #endif -- cgit From 65e7bc18a9a7b89e55b87a74ae47d45269b51847 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 03:32:38 +0100 Subject: use cloexec wrappers wherever applicable --- src/daemon/cpulimit.c | 4 +--- src/modules/module-mmkbd-evdev.c | 2 +- src/modules/module-pipe-sink.c | 3 +-- src/modules/module-pipe-source.c | 3 +-- src/modules/module-solaris.c | 2 +- src/modules/oss/oss-util.c | 12 +++++------- src/modules/rtp/module-rtp-recv.c | 2 +- src/modules/rtp/module-rtp-send.c | 6 ++---- src/pulse/mainloop-signal.c | 4 +--- src/pulse/mainloop.c | 4 +--- src/pulsecore/authkey.c | 10 +++------- src/pulsecore/core-util.c | 5 +---- src/pulsecore/cpu-arm.c | 2 +- src/pulsecore/fdsem.c | 13 ++++--------- src/pulsecore/lock-autospawn.c | 5 +---- src/pulsecore/pid.c | 5 +---- src/pulsecore/random.c | 6 +----- src/pulsecore/sink.c | 4 ++-- src/pulsecore/socket-client.c | 4 +--- src/pulsecore/socket-server.c | 16 ++++------------ src/pulsecore/socket-util.c | 2 +- src/pulsecore/sound-file-stream.c | 6 +----- src/pulsecore/sound-file.c | 6 +----- src/utils/pacat.c | 2 +- src/utils/pacmd.c | 2 +- 25 files changed, 39 insertions(+), 91 deletions(-) diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c index c2877ecf..f5042a75 100644 --- a/src/daemon/cpulimit.c +++ b/src/daemon/cpulimit.c @@ -188,15 +188,13 @@ int pa_cpu_limit_init(pa_mainloop_api *m) { last_time = pa_rtclock_now(); /* Prepare the main loop pipe */ - if (pipe(the_pipe) < 0) { + if (pa_pipe_cloexec(the_pipe) < 0) { pa_log("pipe() failed: %s", pa_cstrerror(errno)); return -1; } pa_make_fd_nonblock(the_pipe[0]); pa_make_fd_nonblock(the_pipe[1]); - pa_make_fd_cloexec(the_pipe[0]); - pa_make_fd_cloexec(the_pipe[1]); api = m; io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL); diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c index 516bf413..14a9dd3d 100644 --- a/src/modules/module-mmkbd-evdev.c +++ b/src/modules/module-mmkbd-evdev.c @@ -175,7 +175,7 @@ int pa__init(pa_module*m) { u->fd = -1; u->fd_type = 0; - if ((u->fd = open(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY|O_NOCTTY)) < 0) { + if ((u->fd = pa_open_cloexec(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY, 0)) < 0) { pa_log("Failed to open evdev device: %s", pa_cstrerror(errno)); goto fail; } diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c index 9c169327..10cc3415 100644 --- a/src/modules/module-pipe-sink.c +++ b/src/modules/module-pipe-sink.c @@ -253,12 +253,11 @@ int pa__init(pa_module*m) { u->filename = pa_runtime_path(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME)); mkfifo(u->filename, 0666); - if ((u->fd = open(u->filename, O_RDWR|O_NOCTTY)) < 0) { + if ((u->fd = pa_open_cloexec(u->filename, O_RDWR, 0)) < 0) { pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno)); goto fail; } - pa_make_fd_cloexec(u->fd); pa_make_fd_nonblock(u->fd); if (fstat(u->fd, &st) < 0) { diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c index 49104f8d..de680933 100644 --- a/src/modules/module-pipe-source.c +++ b/src/modules/module-pipe-source.c @@ -238,12 +238,11 @@ int pa__init(pa_module*m) { u->filename = pa_runtime_path(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME)); mkfifo(u->filename, 0666); - if ((u->fd = open(u->filename, O_RDWR|O_NOCTTY)) < 0) { + if ((u->fd = pa_open_cloexec(u->filename, O_RDWR, 0)) < 0) { pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno)); goto fail; } - pa_make_fd_cloexec(u->fd); pa_make_fd_nonblock(u->fd); if (fstat(u->fd, &st) < 0) { diff --git a/src/modules/module-solaris.c b/src/modules/module-solaris.c index b0d4db43..955997ba 100644 --- a/src/modules/module-solaris.c +++ b/src/modules/module-solaris.c @@ -327,7 +327,7 @@ static int open_audio_device(struct userdata *u, pa_sample_spec *ss) { pa_assert(u); pa_assert(ss); - if ((u->fd = open(u->device_name, u->mode | O_NONBLOCK)) < 0) { + if ((u->fd = pa_open_cloexec(u->device_name, u->mode | O_NONBLOCK)) < 0) { pa_log_warn("open %s failed (%s)", u->device_name, pa_cstrerror(errno)); return -1; } diff --git a/src/modules/oss/oss-util.c b/src/modules/oss/oss-util.c index 5a109ae9..41af3bac 100644 --- a/src/modules/oss/oss-util.c +++ b/src/modules/oss/oss-util.c @@ -55,7 +55,7 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) { pcaps = ∩︀ if (*mode == O_RDWR) { - if ((fd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) >= 0) { + if ((fd = pa_open_cloexec(device, O_RDWR|O_NDELAY, 0)) >= 0) { ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0); if (ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps) < 0) { @@ -71,14 +71,14 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) { pa_close(fd); } - if ((fd = open(device, (*mode = O_WRONLY)|O_NDELAY|O_NOCTTY)) < 0) { - if ((fd = open(device, (*mode = O_RDONLY)|O_NDELAY|O_NOCTTY)) < 0) { + if ((fd = pa_open_cloexec(device, (*mode = O_WRONLY)|O_NDELAY, 0)) < 0) { + if ((fd = pa_open_cloexec(device, (*mode = O_RDONLY)|O_NDELAY, 0)) < 0) { pa_log("open('%s'): %s", device, pa_cstrerror(errno)); goto fail; } } } else { - if ((fd = open(device, *mode|O_NDELAY|O_NOCTTY)) < 0) { + if ((fd = pa_open_cloexec(device, *mode|O_NDELAY, 0)) < 0) { pa_log("open('%s'): %s", device, pa_cstrerror(errno)); goto fail; } @@ -145,8 +145,6 @@ success: pa_log_debug("capabilities:%s", t); pa_xfree(t); - pa_make_fd_cloexec(fd); - return fd; fail: @@ -403,7 +401,7 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) { static int open_mixer(const char *mixer) { int fd; - if ((fd = open(mixer, O_RDWR|O_NDELAY|O_NOCTTY)) >= 0) + if ((fd = pa_open_cloexec(mixer, O_RDWR|O_NDELAY, 0)) >= 0) return fd; return -1; diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c index 1a05f57d..7dbb1efa 100644 --- a/src/modules/rtp/module-rtp-recv.c +++ b/src/modules/rtp/module-rtp-recv.c @@ -390,7 +390,7 @@ static int mcast_socket(const struct sockaddr* sa, socklen_t salen) { pa_assert(salen > 0); af = sa->sa_family; - if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) { + if ((fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) { pa_log("Failed to create socket: %s", pa_cstrerror(errno)); goto fail; } diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index 8e1cfe36..ab815223 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -262,7 +262,7 @@ int pa__init(pa_module*m) { goto fail; } - if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) { + if ((fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) { pa_log("socket() failed: %s", pa_cstrerror(errno)); goto fail; } @@ -277,7 +277,7 @@ int pa__init(pa_module*m) { #endif } - if ((sap_fd = socket(af, SOCK_DGRAM, 0)) < 0) { + if ((sap_fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) { pa_log("socket() failed: %s", pa_cstrerror(errno)); goto fail; } @@ -316,8 +316,6 @@ int pa__init(pa_module*m) { /* If the socket queue is full, let's drop packets */ pa_make_fd_nonblock(fd); pa_make_udp_socket_low_delay(fd); - pa_make_fd_cloexec(fd); - pa_make_fd_cloexec(sap_fd); pa_source_output_new_data_init(&data); pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, "RTP Monitor Stream"); diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c index 3dc74398..70c0122c 100644 --- a/src/pulse/mainloop-signal.c +++ b/src/pulse/mainloop-signal.c @@ -124,15 +124,13 @@ int pa_signal_init(pa_mainloop_api *a) { pa_assert(signal_pipe[1] == -1); pa_assert(!io_event); - if (pipe(signal_pipe) < 0) { + if (pa_pipe_cloexec(signal_pipe) < 0) { pa_log("pipe(): %s", pa_cstrerror(errno)); return -1; } pa_make_fd_nonblock(signal_pipe[0]); pa_make_fd_nonblock(signal_pipe[1]); - pa_make_fd_cloexec(signal_pipe[0]); - pa_make_fd_cloexec(signal_pipe[1]); api = a; diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c index 090ac8c2..6cd089ef 100644 --- a/src/pulse/mainloop.c +++ b/src/pulse/mainloop.c @@ -482,7 +482,7 @@ pa_mainloop *pa_mainloop_new(void) { m = pa_xnew0(pa_mainloop, 1); - if (pipe(m->wakeup_pipe) < 0) { + if (pa_pipe_cloexec(m->wakeup_pipe) < 0) { pa_log_error("ERROR: cannot create wakeup pipe"); pa_xfree(m); return NULL; @@ -490,8 +490,6 @@ pa_mainloop *pa_mainloop_new(void) { pa_make_fd_nonblock(m->wakeup_pipe[0]); pa_make_fd_nonblock(m->wakeup_pipe[1]); - pa_make_fd_cloexec(m->wakeup_pipe[0]); - pa_make_fd_cloexec(m->wakeup_pipe[1]); m->rebuild_pollfds = TRUE; diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c index 15613e27..d671e367 100644 --- a/src/pulsecore/authkey.c +++ b/src/pulsecore/authkey.c @@ -70,10 +70,6 @@ static int generate(int fd, void *ret_data, size_t length) { #define O_BINARY 0 #endif -#ifndef O_NOCTTY -#define O_NOCTTY 0 -#endif - /* Load an euthorization cookie from file fn and store it in data. If * the cookie file doesn't exist, create it */ static int load(const char *fn, void *data, size_t length) { @@ -86,9 +82,9 @@ static int load(const char *fn, void *data, size_t length) { pa_assert(data); pa_assert(length > 0); - if ((fd = open(fn, O_RDWR|O_CREAT|O_BINARY|O_NOCTTY, S_IRUSR|S_IWUSR)) < 0) { + if ((fd = pa_open_cloexec(fn, O_RDWR|O_CREAT|O_BINARY, S_IRUSR|S_IWUSR)) < 0) { - if (errno != EACCES || (fd = open(fn, O_RDONLY|O_BINARY|O_NOCTTY)) < 0) { + if (errno != EACCES || (fd = open(fn, O_RDONLY|O_BINARY)) < 0) { pa_log_warn("Failed to open cookie file '%s': %s", fn, pa_cstrerror(errno)); goto finish; } else @@ -204,7 +200,7 @@ int pa_authkey_save(const char *fn, const void *data, size_t length) { if (!(p = normalize_path(fn))) return -2; - if ((fd = open(p, O_RDWR|O_CREAT|O_NOCTTY, S_IRUSR|S_IWUSR)) < 0) { + if ((fd = pa_open_cloexec(p, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR)) < 0) { pa_log_warn("Failed to open cookie file '%s': %s", fn, pa_cstrerror(errno)); goto finish; } diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 34516eea..19e12963 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1200,10 +1200,7 @@ int pa_lock_lockfile(const char *fn) { for (;;) { struct stat st; - if ((fd = open(fn, O_CREAT|O_RDWR -#ifdef O_NOCTTY - |O_NOCTTY -#endif + if ((fd = pa_open_cloexec(fn, O_CREAT|O_RDWR #ifdef O_NOFOLLOW |O_NOFOLLOW #endif diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c index 453b7848..6bb2eadd 100644 --- a/src/pulsecore/cpu-arm.c +++ b/src/pulsecore/cpu-arm.c @@ -62,7 +62,7 @@ static char *get_cpuinfo(void) { cpuinfo = pa_xmalloc(MAX_BUFFER); - if ((fd = open("/proc/cpuinfo", O_RDONLY)) < 0) { + if ((fd = pa_open_cloexec("/proc/cpuinfo", O_RDONLY, 0)) < 0) { pa_xfree(cpuinfo); return NULL; } diff --git a/src/pulsecore/fdsem.c b/src/pulsecore/fdsem.c index 380f34f5..ea14e8a7 100644 --- a/src/pulsecore/fdsem.c +++ b/src/pulsecore/fdsem.c @@ -62,19 +62,15 @@ pa_fdsem *pa_fdsem_new(void) { f = pa_xmalloc(PA_ALIGN(sizeof(pa_fdsem)) + PA_ALIGN(sizeof(pa_fdsem_data))); #ifdef HAVE_SYS_EVENTFD_H - if ((f->efd = eventfd(0, 0)) >= 0) { - pa_make_fd_cloexec(f->efd); + if ((f->efd = eventfd(0, EFD_CLOEXEC)) >= 0) f->fds[0] = f->fds[1] = -1; - } else + else #endif { - if (pipe(f->fds) < 0) { + if (pa_pipe_cloexec(f->fds) < 0) { pa_xfree(f); return NULL; } - - pa_make_fd_cloexec(f->fds[0]); - pa_make_fd_cloexec(f->fds[1]); } f->data = (pa_fdsem_data*) ((uint8_t*) f + PA_ALIGN(sizeof(pa_fdsem))); @@ -114,12 +110,11 @@ pa_fdsem *pa_fdsem_new_shm(pa_fdsem_data *data, int* event_fd) { f = pa_xnew(pa_fdsem, 1); - if ((f->efd = eventfd(0, 0)) < 0) { + if ((f->efd = eventfd(0, EFD_CLOEXEC)) < 0) { pa_xfree(f); return NULL; } - pa_make_fd_cloexec(f->efd); f->fds[0] = f->fds[1] = -1; f->data = data; diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c index c0df7938..65e35634 100644 --- a/src/pulsecore/lock-autospawn.c +++ b/src/pulsecore/lock-autospawn.c @@ -87,12 +87,9 @@ static int ref(void) { pa_assert(pipe_fd[0] < 0); pa_assert(pipe_fd[1] < 0); - if (pipe(pipe_fd) < 0) + if (pa_pipe_cloexec(pipe_fd) < 0) return -1; - pa_make_fd_cloexec(pipe_fd[0]); - pa_make_fd_cloexec(pipe_fd[1]); - pa_make_fd_nonblock(pipe_fd[1]); pa_make_fd_nonblock(pipe_fd[0]); diff --git a/src/pulsecore/pid.c b/src/pulsecore/pid.c index 996946c2..c92e8312 100644 --- a/src/pulsecore/pid.c +++ b/src/pulsecore/pid.c @@ -88,10 +88,7 @@ static int open_pid_file(const char *fn, int mode) { for (;;) { struct stat st; - if ((fd = open(fn, mode -#ifdef O_NOCTTY - |O_NOCTTY -#endif + if ((fd = pa_open_cloexec(fn, mode #ifdef O_NOFOLLOW |O_NOFOLLOW #endif diff --git a/src/pulsecore/random.c b/src/pulsecore/random.c index 518c281a..a87d24e3 100644 --- a/src/pulsecore/random.c +++ b/src/pulsecore/random.c @@ -62,11 +62,7 @@ static int random_proper(void *ret_data, size_t length) { while (*device) { ret = 0; - if ((fd = open(*device, O_RDONLY -#ifdef O_NOCTTY - | O_NOCTTY -#endif - )) >= 0) { + if ((fd = pa_open_cloexec(*device, O_RDONLY, 0)) >= 0) { if ((r = pa_loop_read(fd, ret_data, length, NULL)) < 0 || (size_t) r != length) ret = -1; diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index bda92fcc..221b569f 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1342,7 +1342,7 @@ static void propagate_reference_volume(pa_sink *s) { void pa_sink_set_volume( pa_sink *s, const pa_cvolume *volume, - pa_bool_t sendmsg, + pa_bool_t send_msg, pa_bool_t save) { pa_cvolume old_reference_volume; @@ -1411,7 +1411,7 @@ void pa_sink_set_volume( s->soft_volume = s->real_volume; /* This tells the sink that soft and/or virtual volume changed */ - if (sendmsg) + if (send_msg) pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_VOLUME, NULL, 0, NULL) == 0); if (reference_changed) diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c index b9d69505..ef3c29ee 100644 --- a/src/pulsecore/socket-client.c +++ b/src/pulsecore/socket-client.c @@ -257,13 +257,11 @@ static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size c->local = pa_socket_address_is_local(sa); - if ((c->fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) { + if ((c->fd = pa_socket_cloexec(sa->sa_family, SOCK_STREAM, 0)) < 0) { pa_log("socket(): %s", pa_cstrerror(errno)); return -1; } - pa_make_fd_cloexec(c->fd); - #ifdef HAVE_IPV6 if (sa->sa_family == AF_INET || sa->sa_family == AF_INET6) #else diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c index e660700c..5d55de3e 100644 --- a/src/pulsecore/socket-server.c +++ b/src/pulsecore/socket-server.c @@ -104,13 +104,11 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, pa_io_ev pa_socket_server_ref(s); - if ((nfd = accept(fd, NULL, NULL)) < 0) { + if ((nfd = pa_accept_cloexec(fd, NULL, NULL)) < 0) { pa_log("accept(): %s", pa_cstrerror(errno)); goto finish; } - pa_make_fd_cloexec(nfd); - if (!s->on_connection) { pa_close(nfd); goto finish; @@ -186,13 +184,11 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file pa_assert(m); pa_assert(filename); - if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { + if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) { pa_log("socket(): %s", pa_cstrerror(errno)); goto fail; } - pa_make_fd_cloexec(fd); - memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; pa_strlcpy(sa.sun_path, filename, sizeof(sa.sun_path)); @@ -246,13 +242,11 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address pa_assert(m); pa_assert(port); - if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { + if ((fd = pa_socket_cloexec(PF_INET, SOCK_STREAM, 0)) < 0) { pa_log("socket(PF_INET): %s", pa_cstrerror(errno)); goto fail; } - pa_make_fd_cloexec(fd); - #ifdef SO_REUSEADDR if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) pa_log("setsockopt(): %s", pa_cstrerror(errno)); @@ -299,13 +293,11 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad pa_assert(m); pa_assert(port > 0); - if ((fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) { + if ((fd = pa_socket_cloexec(PF_INET6, SOCK_STREAM, 0)) < 0) { pa_log("socket(PF_INET6): %s", pa_cstrerror(errno)); goto fail; } - pa_make_fd_cloexec(fd); - #ifdef IPV6_V6ONLY on = 1; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c index 5fd5dd67..651779f6 100644 --- a/src/pulsecore/socket-util.c +++ b/src/pulsecore/socket-util.c @@ -239,7 +239,7 @@ int pa_unix_socket_is_stale(const char *fn) { pa_assert(fn); - if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { + if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) { pa_log("socket(): %s", pa_cstrerror(errno)); goto finish; } diff --git a/src/pulsecore/sound-file-stream.c b/src/pulsecore/sound-file-stream.c index 16de4923..53674ba1 100644 --- a/src/pulsecore/sound-file-stream.c +++ b/src/pulsecore/sound-file-stream.c @@ -252,11 +252,7 @@ int pa_play_file( u->readf_function = NULL; u->memblockq = NULL; - if ((fd = open(fname, O_RDONLY -#ifdef O_NOCTTY - |O_NOCTTY -#endif - )) < 0) { + if ((fd = pa_open_cloexec(fname, O_RDONLY, 0)) < 0) { pa_log("Failed to open file %s: %s", fname, pa_cstrerror(errno)); goto fail; } diff --git a/src/pulsecore/sound-file.c b/src/pulsecore/sound-file.c index 2d9b76ad..d8c10b1e 100644 --- a/src/pulsecore/sound-file.c +++ b/src/pulsecore/sound-file.c @@ -62,11 +62,7 @@ int pa_sound_file_load( pa_memchunk_reset(chunk); - if ((fd = open(fname, O_RDONLY -#ifdef O_NOCTTY - |O_NOCTTY -#endif - )) < 0) { + if ((fd = pa_open_cloexec(fname, O_RDONLY, 0)) < 0) { pa_log("Failed to open file %s: %s", fname, pa_cstrerror(errno)); goto finish; } diff --git a/src/utils/pacat.c b/src/utils/pacat.c index 5f29ba39..d348c16a 100644 --- a/src/utils/pacat.c +++ b/src/utils/pacat.c @@ -906,7 +906,7 @@ int main(int argc, char *argv[]) { filename = argv[optind]; - if ((fd = open(argv[optind], mode == PLAYBACK ? O_RDONLY : O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) { + if ((fd = pa_open_cloexec(argv[optind], mode == PLAYBACK ? O_RDONLY : O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) { pa_log(_("open(): %s"), strerror(errno)); goto quit; } diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c index 5ef57e3b..ef58e9ce 100644 --- a/src/utils/pacmd.c +++ b/src/utils/pacmd.c @@ -70,7 +70,7 @@ int main(int argc, char*argv[]) { goto fail; } - if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { + if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) { pa_log(_("socket(PF_UNIX, SOCK_STREAM, 0): %s"), strerror(errno)); goto fail; } -- cgit From a698ee3f52e9d61b378cb0dad2cfb1bcc31c708a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 04:16:59 +0100 Subject: core-util: make sure to enable FD_CLOEXEC unconditionally to cope with kernels that silently accept but ignore O_CLOEXEC --- src/pulsecore/core-util.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 19e12963..a199daa3 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2896,7 +2896,7 @@ int pa_open_cloexec(const char *fn, int flags, mode_t mode) { #ifdef O_CLOEXEC if ((fd = open(fn, flags|O_CLOEXEC, mode)) >= 0) - return fd; + goto finish; if (errno != EINVAL) return fd; @@ -2905,6 +2905,10 @@ int pa_open_cloexec(const char *fn, int flags, mode_t mode) { if ((fd = open(fn, flags, mode)) < 0) return fd; +finish: + /* Some implementations might simply ignore O_CLOEXEC if it is not + * understood, make sure FD_CLOEXEC is enabled anyway */ + pa_make_fd_cloexec(fd); return fd; } @@ -2914,7 +2918,7 @@ int pa_socket_cloexec(int domain, int type, int protocol) { #ifdef SOCK_CLOEXEC if ((fd = socket(domain, type | SOCK_CLOEXEC, protocol)) >= 0) - return fd; + goto finish; if (errno != EINVAL) return fd; @@ -2923,6 +2927,10 @@ int pa_socket_cloexec(int domain, int type, int protocol) { if ((fd = socket(domain, type, protocol)) < 0) return fd; +finish: + /* Some implementations might simply ignore SOCK_CLOEXEC if it is + * not understood, make sure FD_CLOEXEC is enabled anyway */ + pa_make_fd_cloexec(fd); return fd; } @@ -2932,7 +2940,7 @@ int pa_pipe_cloexec(int pipefd[2]) { #ifdef HAVE_PIPE2 if ((r = pipe2(pipefd, O_CLOEXEC)) >= 0) - return r; + goto finish; if (errno != EINVAL && errno != ENOSYS) return r; @@ -2941,6 +2949,7 @@ int pa_pipe_cloexec(int pipefd[2]) { if ((r = pipe(pipefd)) < 0) return r; +finish: pa_make_fd_cloexec(pipefd[0]); pa_make_fd_cloexec(pipefd[1]); -- cgit From 752727a13d2d55439aefe618677f7e932acc9862 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 04:20:24 +0100 Subject: core-util: introduce pa_fopen_cloexec() --- src/pulsecore/core-util.c | 29 +++++++++++++++++++++++++++-- src/pulsecore/core-util.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index a199daa3..40da8f42 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2961,7 +2961,7 @@ int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { #ifdef HAVE_ACCEPT4 if ((fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC)) >= 0) - return fd; + goto finish; if (errno != EINVAL && errno != ENOSYS) return fd; @@ -2970,7 +2970,32 @@ int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { if ((fd = accept(sockfd, addr, addrlen)) < 0) return fd; +finish: pa_make_fd_cloexec(fd); + return fd; +} - return 0; +FILE* pa_fopen_cloexec(const char *path, const char *mode) { + FILE *f; + char *m; + + m = pa_sprintf_malloc("%se", mode); + + errno = 0; + if ((f = fopen(path, m))) { + pa_xfree(m); + goto finish; + } + + pa_xfree(m); + + if (errno != EINVAL) + return NULL; + + if (!(f = fopen(path, mode))) + return NULL; + +finish: + pa_make_fd_cloexec(fileno(f)); + return f; } diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 323fdcb4..d50f79a2 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -263,5 +263,6 @@ int pa_open_cloexec(const char *fn, int flags, mode_t mode); int pa_socket_cloexec(int domain, int type, int protocol); int pa_pipe_cloexec(int pipefd[2]); int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen); +FILE* pa_fopen_cloexec(const char *path, const char *mode); #endif -- cgit From 88b72958bebd1770e45a4af2dc9fec75aaf1f2de Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 04:53:15 +0100 Subject: tdb: use O_CLOEXEC if available --- src/pulsecore/database-tdb.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/pulsecore/database-tdb.c b/src/pulsecore/database-tdb.c index b79d2837..4e782d65 100644 --- a/src/pulsecore/database-tdb.c +++ b/src/pulsecore/database-tdb.c @@ -66,6 +66,39 @@ void pa_datum_free(pa_datum *d) { pa_zero(d); } +static struct tdb_context *tdb_open_cloexec( + const char *name, + int hash_size, + int tdb_flags, + int open_flags, + mode_t mode) { + + /* Mimics pa_open_cloexec() */ + + struct tdb_context *c; + +#ifdef O_NOCTTY + open_flags |= O_NOCTTY; +#endif + +#ifdef O_CLOEXEC + errno = 0; + if ((c = tdb_open(name, hash_size, tdb_flags, open_flags | O_CLOEXEC, mode))) + goto finish; + + if (errno != EINVAL) + return NULL; +#endif + + errno = 0; + if (!(c = tdb_open(name, hash_size, tdb_flags, open_flags, mode))) + return NULL; + +finish: + pa_make_fd_cloexec(tdb_fd(c)); + return c; +} + pa_database* pa_database_open(const char *fn, pa_bool_t for_write) { struct tdb_context *c; char *path; @@ -73,15 +106,7 @@ pa_database* pa_database_open(const char *fn, pa_bool_t for_write) { pa_assert(fn); path = pa_sprintf_malloc("%s.tdb", fn); - errno = 0; - c = tdb_open(path, 0, TDB_NOSYNC|TDB_NOLOCK, - (for_write ? O_RDWR|O_CREAT : O_RDONLY)|O_NOCTTY -#ifdef O_CLOEXEC - |O_CLOEXEC -#endif - , 0644); - - if (c) + if ((c = tdb_open_cloexec(path, 0, TDB_NOSYNC|TDB_NOLOCK, (for_write ? O_RDWR|O_CREAT : O_RDONLY), 0644))) pa_log_debug("Opened TDB database '%s'", path); pa_xfree(path); -- cgit From 168be3830ae291dd819abebec813f76151487bb3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 04:54:19 +0100 Subject: use pa_fopen_cloexec() where applicable --- src/daemon/daemon-conf.c | 4 ++-- src/modules/module-cli.c | 2 +- src/modules/module-default-device-restore.c | 8 ++++---- src/modules/module-detect.c | 8 ++++---- src/modules/module-match.c | 2 +- src/modules/module-udev-detect.c | 2 +- src/modules/oss/oss-util.c | 6 +++--- src/pulse/client-conf.c | 2 +- src/pulsecore/cli-command.c | 2 +- src/pulsecore/conf-parser.c | 2 +- src/pulsecore/core-util.c | 8 ++++---- src/pulsecore/database-simple.c | 4 ++-- src/pulsecore/pid.c | 2 +- src/pulsecore/sample-util.c | 2 +- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 571faae4..bfd5c118 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -577,7 +577,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { c->config_file = NULL; f = filename ? - fopen(c->config_file = pa_xstrdup(filename), "r") : + pa_fopen_cloexec(c->config_file = pa_xstrdup(filename), "r") : pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file); if (!f && errno != ENOENT) { @@ -652,7 +652,7 @@ FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c) { else f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file); } else - f = fopen(c->default_script_file, "r"); + f = pa_fopen_cloexec(c->default_script_file, "r"); return f; } diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c index 6bd0f4fc..c5ff4564 100644 --- a/src/modules/module-cli.c +++ b/src/modules/module-cli.c @@ -105,7 +105,7 @@ int pa__init(pa_module*m) { * of log messages, particularly because if stdout and stderr are * dup'ed they share the same O_NDELAY, too. */ - if ((fd = open("/dev/tty", O_RDWR|O_CLOEXEC|O_NONBLOCK)) >= 0) { + if ((fd = pa_open_cloexec("/dev/tty", O_RDWR|O_NONBLOCK, 0)) >= 0) { io = pa_iochannel_new(m->core->mainloop, fd, fd); pa_log_debug("Managed to open /dev/tty."); } else { diff --git a/src/modules/module-default-device-restore.c b/src/modules/module-default-device-restore.c index 27ae60e5..94f589e9 100644 --- a/src/modules/module-default-device-restore.c +++ b/src/modules/module-default-device-restore.c @@ -60,7 +60,7 @@ static void load(struct userdata *u) { if (u->core->default_sink) pa_log_info("Manually configured default sink, not overwriting."); - else if ((f = fopen(u->sink_filename, "r"))) { + else if ((f = pa_fopen_cloexec(u->sink_filename, "r"))) { char ln[256] = ""; pa_sink *s; @@ -81,7 +81,7 @@ static void load(struct userdata *u) { if (u->core->default_source) pa_log_info("Manually configured default source, not overwriting."); - else if ((f = fopen(u->source_filename, "r"))) { + else if ((f = pa_fopen_cloexec(u->source_filename, "r"))) { char ln[256] = ""; pa_source *s; @@ -108,7 +108,7 @@ static void save(struct userdata *u) { return; if (u->sink_filename) { - if ((f = fopen(u->sink_filename, "w"))) { + if ((f = pa_fopen_cloexec(u->sink_filename, "w"))) { pa_sink *s = pa_namereg_get_default_sink(u->core); fprintf(f, "%s\n", s ? s->name : ""); fclose(f); @@ -117,7 +117,7 @@ static void save(struct userdata *u) { } if (u->source_filename) { - if ((f = fopen(u->source_filename, "w"))) { + if ((f = pa_fopen_cloexec(u->source_filename, "w"))) { pa_source *s = pa_namereg_get_default_source(u->core); fprintf(f, "%s\n", s ? s->name : ""); fclose(f); diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c index b1f24e15..1fe8eb8b 100644 --- a/src/modules/module-detect.c +++ b/src/modules/module-detect.c @@ -63,7 +63,7 @@ static int detect_alsa(pa_core *c, int just_one) { FILE *f; int n = 0, n_sink = 0, n_source = 0; - if (!(f = fopen("/proc/asound/devices", "r"))) { + if (!(f = pa_fopen_cloexec("/proc/asound/devices", "r"))) { if (errno != ENOENT) pa_log_error("open(\"/proc/asound/devices\") failed: %s", pa_cstrerror(errno)); @@ -124,9 +124,9 @@ static int detect_oss(pa_core *c, int just_one) { FILE *f; int n = 0, b = 0; - if (!(f = fopen("/dev/sndstat", "r")) && - !(f = fopen("/proc/sndstat", "r")) && - !(f = fopen("/proc/asound/oss/sndstat", "r"))) { + if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) && + !(f = pa_fopen_cloexec("/proc/sndstat", "r")) && + !(f = pa_fopen_cloexec("/proc/asound/oss/sndstat", "r"))) { if (errno != ENOENT) pa_log_error("failed to open OSS sndstat device: %s", pa_cstrerror(errno)); diff --git a/src/modules/module-match.c b/src/modules/module-match.c index 0bd781d2..b1693f18 100644 --- a/src/modules/module-match.c +++ b/src/modules/module-match.c @@ -85,7 +85,7 @@ static int load_rules(struct userdata *u, const char *filename) { pa_assert(u); if (filename) - f = fopen(fn = pa_xstrdup(filename), "r"); + f = pa_fopen_cloexec(fn = pa_xstrdup(filename), "r"); else f = pa_open_config_file(DEFAULT_MATCH_TABLE_FILE, DEFAULT_MATCH_TABLE_FILE_USER, NULL, &fn); diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c index 1b1e9c1a..a12f7c93 100644 --- a/src/modules/module-udev-detect.c +++ b/src/modules/module-udev-detect.c @@ -172,7 +172,7 @@ static pa_bool_t is_card_busy(const char *id) { if (status_file) fclose(status_file); - if (!(status_file = fopen(sub_status, "r"))) { + if (!(status_file = pa_fopen_cloexec(sub_status, "r"))) { pa_log_warn("Failed to open %s: %s", sub_status, pa_cstrerror(errno)); continue; } diff --git a/src/modules/oss/oss-util.c b/src/modules/oss/oss-util.c index 41af3bac..b95023c3 100644 --- a/src/modules/oss/oss-util.c +++ b/src/modules/oss/oss-util.c @@ -349,9 +349,9 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) { if ((n = get_device_number(dev)) < 0) return -1; - if (!(f = fopen("/dev/sndstat", "r")) && - !(f = fopen("/proc/sndstat", "r")) && - !(f = fopen("/proc/asound/oss/sndstat", "r"))) { + if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) && + !(f = pa_fopen_cloexec("/proc/sndstat", "r")) && + !(f = pa_fopen_cloexec("/proc/asound/oss/sndstat", "r"))) { if (errno != ENOENT) pa_log_warn("failed to open OSS sndstat device: %s", pa_cstrerror(errno)); diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c index 62c06f6a..3eaca4d9 100644 --- a/src/pulse/client-conf.c +++ b/src/pulse/client-conf.c @@ -110,7 +110,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) { if (filename) { - if (!(f = fopen(filename, "r"))) { + if (!(f = pa_fopen_cloexec(filename, "r"))) { pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno)); goto finish; } diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index b57919a4..82a44d84 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -1804,7 +1804,7 @@ int pa_cli_command_execute_file(pa_core *c, const char *fn, pa_strbuf *buf, pa_b if (!fail) fail = &_fail; - if (!(f = fopen(fn, "r"))) { + if (!(f = pa_fopen_cloexec(fn, "r"))) { pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, pa_cstrerror(errno)); if (!*fail) ret = 0; diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c index dd4a99ee..34b4d6fe 100644 --- a/src/pulsecore/conf-parser.c +++ b/src/pulsecore/conf-parser.c @@ -168,7 +168,7 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void pa_assert(filename); pa_assert(t); - if (!f && !(f = fopen(filename, "r"))) { + if (!f && !(f = pa_fopen_cloexec(filename, "r"))) { if (errno == ENOENT) { pa_log_debug("Failed to open configuration file '%s': %s", filename, pa_cstrerror(errno)); r = 0; diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 40da8f42..738bf065 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1600,7 +1600,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env fn = buf; #endif - if ((f = fopen(fn, "r"))) { + if ((f = pa_fopen_cloexec(fn, "r"))) { if (result) *result = pa_xstrdup(fn); @@ -1634,7 +1634,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env fn = buf; #endif - if ((f = fopen(fn, "r"))) { + if ((f = pa_fopen_cloexec(fn, "r"))) { if (result) *result = pa_xstrdup(fn); @@ -1661,7 +1661,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env global = buf; #endif - if ((f = fopen(global, "r"))) { + if ((f = pa_fopen_cloexec(global, "r"))) { if (result) *result = pa_xstrdup(global); @@ -2560,7 +2560,7 @@ char *pa_machine_id(void) { * since it fits perfectly our needs and is not as volatile as the * hostname which might be set from dhcp. */ - if ((f = fopen(PA_MACHINE_ID, "r"))) { + if ((f = pa_fopen_cloexec(PA_MACHINE_ID, "r"))) { char ln[34] = "", *r; r = fgets(ln, sizeof(ln)-1, f); diff --git a/src/pulsecore/database-simple.c b/src/pulsecore/database-simple.c index 1f4caf71..754930db 100644 --- a/src/pulsecore/database-simple.c +++ b/src/pulsecore/database-simple.c @@ -237,7 +237,7 @@ pa_database* pa_database_open(const char *fn, pa_bool_t for_write) { path = pa_sprintf_malloc("%s."CANONICAL_HOST".simple", fn); errno = 0; - f = fopen(path, "r"); + f = pa_fopen_cloexec(path, "r"); if (f || errno == ENOENT) { /* file not found is ok */ db = pa_xnew0(simple_data, 1); @@ -480,7 +480,7 @@ int pa_database_sync(pa_database *database) { errno = 0; - f = fopen(db->tmp_filename, "w"); + f = pa_fopen_cloexec(db->tmp_filename, "w"); if (!f) goto fail; diff --git a/src/pulsecore/pid.c b/src/pulsecore/pid.c index c92e8312..213e7983 100644 --- a/src/pulsecore/pid.c +++ b/src/pulsecore/pid.c @@ -143,7 +143,7 @@ static int proc_name_ours(pid_t pid, const char *procname) { pa_snprintf(bn, sizeof(bn), "/proc/%lu/stat", (unsigned long) pid); - if (!(f = fopen(bn, "r"))) { + if (!(f = pa_fopen_cloexec(bn, "r"))) { pa_log_info("Failed to open %s: %s", bn, pa_cstrerror(errno)); return -1; } else { diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c index a26dc876..74600dec 100644 --- a/src/pulsecore/sample-util.c +++ b/src/pulsecore/sample-util.c @@ -1007,7 +1007,7 @@ void pa_memchunk_dump_to_file(pa_memchunk *c, const char *fn) { /* Only for debugging purposes */ - f = fopen(fn, "a"); + f = pa_fopen_cloexec(fn, "a"); if (!f) { pa_log_warn("Failed to open '%s': %s", fn, pa_cstrerror(errno)); -- cgit From 75f7a971db587d554fffc15801a2d8f7497a2124 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 04:54:55 +0100 Subject: socket-util: allocate at least sizeof(sockaddr_storage) space --- src/pulsecore/socket-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c index 651779f6..0d0762dc 100644 --- a/src/pulsecore/socket-util.c +++ b/src/pulsecore/socket-util.c @@ -85,12 +85,11 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) { #ifndef OS_IS_WIN32 pa_assert_se(fstat(fd, &st) == 0); -#endif -#ifndef OS_IS_WIN32 if (S_ISSOCK(st.st_mode)) { #endif union { + struct sockaddr_storage storage; struct sockaddr sa; struct sockaddr_in in; #ifdef HAVE_IPV6 @@ -315,6 +314,7 @@ pa_bool_t pa_socket_address_is_local(const struct sockaddr *sa) { pa_bool_t pa_socket_is_local(int fd) { union { + struct sockaddr_storage storage; struct sockaddr sa; struct sockaddr_in in; #ifdef HAVE_IPV6 -- cgit From a82c6b0cd5fa075b5a750e6416b7a7f0cd2508c7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 04:55:13 +0100 Subject: socket-util: drop redundant casts --- src/pulsecore/socket-util.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c index 0d0762dc..2cc9882a 100644 --- a/src/pulsecore/socket-util.c +++ b/src/pulsecore/socket-util.c @@ -151,7 +151,7 @@ void pa_make_socket_low_delay(int fd) { pa_assert(fd >= 0); priority = 6; - if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (void*)&priority, sizeof(priority)) < 0) + if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority)) < 0) pa_log_warn("SO_PRIORITY failed: %s", pa_cstrerror(errno)); #endif } @@ -165,9 +165,9 @@ void pa_make_tcp_socket_low_delay(int fd) { { int on = 1; #if defined(SOL_TCP) - if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0) + if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) #else - if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0) + if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) #endif pa_log_warn("TCP_NODELAY failed: %s", pa_cstrerror(errno)); } @@ -177,9 +177,9 @@ void pa_make_tcp_socket_low_delay(int fd) { { int tos = IPTOS_LOWDELAY; #ifdef SOL_IP - if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0) + if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0) #else - if (setsockopt(fd, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0) + if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) #endif pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno)); } @@ -195,9 +195,9 @@ void pa_make_udp_socket_low_delay(int fd) { { int tos = IPTOS_LOWDELAY; #ifdef SOL_IP - if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0) + if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0) #else - if (setsockopt(fd, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0) + if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) #endif pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno)); } @@ -205,11 +205,11 @@ void pa_make_udp_socket_low_delay(int fd) { } int pa_socket_set_rcvbuf(int fd, size_t l) { - int bufsz = (int)l; + int bufsz = (int) l; pa_assert(fd >= 0); - if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&bufsz, sizeof(bufsz)) < 0) { + if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsz, sizeof(bufsz)) < 0) { pa_log_warn("SO_RCVBUF: %s", pa_cstrerror(errno)); return -1; } @@ -218,12 +218,12 @@ int pa_socket_set_rcvbuf(int fd, size_t l) { } int pa_socket_set_sndbuf(int fd, size_t l) { - int bufsz = (int)l; + int bufsz = (int) l; pa_assert(fd >= 0); - if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&bufsz, sizeof(bufsz)) < 0) { - pa_log("SO_SNDBUF: %s", pa_cstrerror(errno)); + if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &bufsz, sizeof(bufsz)) < 0) { + pa_log_warn("SO_SNDBUF: %s", pa_cstrerror(errno)); return -1; } -- cgit From aa8ce5bb9b159abb2ffb0f43996340566fc2e9c6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 05:08:48 +0100 Subject: daemon: don't crash if pa_realpath() fails --- src/daemon/main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/daemon/main.c b/src/daemon/main.c index 9e5647a8..576fc3e6 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -425,21 +425,24 @@ int main(int argc, char *argv[]) { pa_set_env("LD_BIND_NOW", "1"); - canonical_rp = pa_realpath(PA_BINARY); + if (!(canonical_rp = pa_realpath(PA_BINARY))) { - if ((rp = pa_readlink("/proc/self/exe"))) { + if ((rp = pa_readlink("/proc/self/exe"))) { - if (pa_streq(rp, canonical_rp)) - pa_assert_se(execv(rp, argv) == 0); - else - pa_log_warn("/proc/self/exe does not point to %s, cannot self execute. Are you playing games?", canonical_rp); + if (pa_streq(rp, canonical_rp)) + pa_assert_se(execv(rp, argv) == 0); + else + pa_log_warn("/proc/self/exe does not point to %s, cannot self execute. Are you playing games?", canonical_rp); - pa_xfree(rp); + pa_xfree(rp); - } else - pa_log_warn("Couldn't read /proc/self/exe, cannot self execute. Running in a chroot()?"); + } else + pa_log_warn("Couldn't read /proc/self/exe, cannot self execute. Running in a chroot()?"); - pa_xfree(canonical_rp); + pa_xfree(canonical_rp); + + } else + pa_log_warn("Couldn't canonicalize binary path, cannot self execute."); } #endif -- cgit From 8a49514f74cacd523117aabcd4514543db63a4ed Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 29 Oct 2009 12:47:42 +0100 Subject: sink: simplify silence checks --- src/pulsecore/sink.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 221b569f..971436d3 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -926,18 +926,16 @@ void pa_sink_render(pa_sink*s, size_t length, pa_memchunk *result) { pa_sw_cvolume_multiply(&volume, &s->thread_info.soft_volume, &info[0].volume); - if (s->thread_info.soft_muted || !pa_cvolume_is_norm(&volume)) { - if (s->thread_info.soft_muted || pa_cvolume_is_muted(&volume)) { - pa_memblock_unref(result->memblock); - pa_silence_memchunk_get(&s->core->silence_cache, - s->core->mempool, - result, - &s->sample_spec, - result->length); - } else { - pa_memchunk_make_writable(result, 0); - pa_volume_memchunk(result, &s->sample_spec, &volume); - } + if (s->thread_info.soft_muted || pa_cvolume_is_muted(&volume)) { + pa_memblock_unref(result->memblock); + pa_silence_memchunk_get(&s->core->silence_cache, + s->core->mempool, + result, + &s->sample_spec, + result->length); + } else if (!pa_cvolume_is_norm(&volume)) { + pa_memchunk_make_writable(result, 0); + pa_volume_memchunk(result, &s->sample_spec, &volume); } } else { void *ptr; -- cgit From 056930cbcde117036cdb707ed3e111b7833724ea Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 29 Oct 2009 14:49:52 +0100 Subject: svolume: fix MMX error We need to sign extend the lower part of the multiplication before adding it to the higher part. Makes -1 * 0xffff work again. --- src/pulsecore/svolume_mmx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 5bf72ed0..a011789c 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -62,7 +62,9 @@ " movq "#s", %%mm5 \n\t" \ " pmulhw "#v", "#s" \n\t" /* .. | 0 | vl*p0 | */ \ " paddw %%mm4, "#s" \n\t" /* .. | 0 | vl*p0 | + sign correct */ \ + " pslld $16, "#s" \n\t" /* .. | vl*p0 | 0 | */ \ " psrld $16, "#v" \n\t" /* .. | 0 | vh | */ \ + " psrad $16, "#s" \n\t" /* .. | vl*p0 | sign extend */ \ " pmaddwd %%mm5, "#v" \n\t" /* .. | p0 * vh | */ \ " paddd "#s", "#v" \n\t" /* .. | p0 * v0 | */ \ " packssdw "#v", "#v" \n\t" /* .. | p1*v1 | p0*v0 | */ @@ -257,11 +259,14 @@ static void run_test (void) { printf ("checking MMX %zd\n", sizeof (samples)); pa_random (samples, sizeof (samples)); + /* for (i = 0; i < SAMPLES; i++) + samples[i] = -1; */ memcpy (samples_ref, samples, sizeof (samples)); memcpy (samples_orig, samples, sizeof (samples)); for (i = 0; i < CHANNELS; i++) volumes[i] = rand() >> 1; + /* volumes[i] = 0x0000ffff; */ for (padding = 0; padding < PADDING; padding++, i++) volumes[i] = volumes[padding]; @@ -269,7 +274,7 @@ static void run_test (void) { pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); for (i = 0; i < SAMPLES; i++) { if (samples[i] != samples_ref[i]) { - printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], + printf ("%d: %04x != %04x (%04x * %08x)\n", i, samples[i], samples_ref[i], samples_orig[i], volumes[i % CHANNELS]); } } -- cgit From 366ab9633be76c920738dc806607d7656dda5191 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Oct 2009 05:20:00 +0100 Subject: git: ignore kde related files --- src/.gitignore | 1 + src/daemon/.gitignore | 1 + 2 files changed, 2 insertions(+) diff --git a/src/.gitignore b/src/.gitignore index 6cd173c0..64ab2973 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -63,4 +63,5 @@ thread-test utf8-test voltest start-pulseaudio-x11 +start-pulseaudio-kde vector-test diff --git a/src/daemon/.gitignore b/src/daemon/.gitignore index 0efa55ba..54e4299b 100644 --- a/src/daemon/.gitignore +++ b/src/daemon/.gitignore @@ -1,2 +1,3 @@ org.pulseaudio.policy pulseaudio.desktop +pulseaudio-kde.desktop -- cgit From 65e8078a3bba6360f7918b2a721510d78826eece Mon Sep 17 00:00:00 2001 From: Leszek Koltunski Date: Tue, 27 Oct 2009 19:57:43 +0800 Subject: X11: attach X11 properties to Screen, not Display --- src/pulsecore/x11prop.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pulsecore/x11prop.c b/src/pulsecore/x11prop.c index 873a76e7..dc8ec294 100644 --- a/src/pulsecore/x11prop.c +++ b/src/pulsecore/x11prop.c @@ -32,12 +32,12 @@ void pa_x11_set_prop(Display *d, const char *name, const char *data) { Atom a = XInternAtom(d, name, False); - XChangeProperty(d, RootWindow(d, 0), a, XA_STRING, 8, PropModeReplace, (const unsigned char*) data, (int) (strlen(data)+1)); + XChangeProperty(d, DefaultRootWindow(d), a, XA_STRING, 8, PropModeReplace, (const unsigned char*) data, (int) (strlen(data)+1)); } void pa_x11_del_prop(Display *d, const char *name) { Atom a = XInternAtom(d, name, False); - XDeleteProperty(d, RootWindow(d, 0), a); + XDeleteProperty(d, DefaultRootWindow(d), a); } char* pa_x11_get_prop(Display *d, const char *name, char *p, size_t l) { @@ -47,13 +47,21 @@ char* pa_x11_get_prop(Display *d, const char *name, char *p, size_t l) { unsigned long nbytes_after; unsigned char *prop = NULL; char *ret = NULL; + int window_ret; Atom a = XInternAtom(d, name, False); - if (XGetWindowProperty(d, RootWindow(d, 0), a, 0, (long) ((l+2)/4), False, XA_STRING, &actual_type, &actual_format, &nitems, &nbytes_after, &prop) != Success) - goto finish; - if (actual_type != XA_STRING) - goto finish; + window_ret = XGetWindowProperty(d, DefaultRootWindow(d), a, 0, (long) ((l+2)/4), False, XA_STRING, &actual_type, &actual_format, &nitems, &nbytes_after, &prop); + + if (window_ret != Success || actual_type != XA_STRING) { + if (DefaultScreen(d) != 0) { + window_ret = XGetWindowProperty(d, RootWindow(d, 0), a, 0, (long) ((l+2)/4), False, XA_STRING, &actual_type, &actual_format, &nitems, &nbytes_after, &prop); + + if (window_ret != Success || actual_type != XA_STRING) + goto finish; + } else + goto finish; + } memcpy(p, prop, nitems); p[nitems] = 0; -- cgit From b04fe9b516160f92d016a8bb81a431c74cac2ecd Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Mon, 19 Oct 2009 12:45:30 +0200 Subject: Wrap clock_gettime and friends On Wed, Sep 16, 2009 at 11:48:58PM +0200, Lennart Poettering wrote: > On Wed, 16.09.09 15:15, Daniel Mack (daniel@caiaq.de) wrote: > > > From: Kim Lester > > > > OS X does not define clockid_t or clock_gettime() and friends. > > Add a wrapper to fix this. > > Hmpf. I am not particularly happy with this. This adds a lot of > unnecessary compat code. We don't actually need implementations of > clock_getres(). All we need is some kind of check whether system > timers are accurate or whether they are rounded up to scheduling > slices. On Linux we do that check with clock_getres(), but all the > information it returns is actually not intertesting at all. We just > check if this is below some trheshold, that's all. > > clock_settime() we don't use at all! We shouldn't carry compat code > for that. > > And clock_gettime we don't really need either. We need some kind of > accurate system timers (preferably monotonic), and on Linux we use > clock_gettime() for that. But we already have a fallback there for > gettimeofday(). > > Or in other words, the current APIs pa_rtclock_get(), > pa_rtclock_hrtimer() is supposed to be the abstract API that has > different backends on different systems. I'd very much prefer if any > MacOS specific code would simply be plugged in there instead of > creating various new abstraction interfaces! Ok - what about the version below? I don't particularily like the Daniel >From 9f0a051953ec354ccdb8aa44a9845c408b26ae0b Mon Sep 17 00:00:00 2001 From: Kim Lester Date: Wed, 16 Sep 2009 14:40:01 +0800 Subject: [PATCH] Implement pa_rtclock_get() and pa_rtclock_hrtimer() for Darwin OS X does not define clockid_t or clock_gettime() and friends. Add wrappers to fix this. Based on a patch from Kim Lester . --- src/pulsecore/core-rtclock.c | 54 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c index 1420470a..4fe0a47b 100644 --- a/src/pulsecore/core-rtclock.c +++ b/src/pulsecore/core-rtclock.c @@ -33,6 +33,12 @@ #include #endif +#ifdef OS_IS_DARWIN +#include +#include +#include +#endif + #include #include #include @@ -47,7 +53,8 @@ pa_usec_t pa_rtclock_age(const struct timeval *tv) { } struct timeval *pa_rtclock_get(struct timeval *tv) { -#ifdef HAVE_CLOCK_GETTIME + +#if defined(HAVE_CLOCK_GETTIME) struct timespec ts; #ifdef CLOCK_MONOTONIC @@ -59,7 +66,7 @@ struct timeval *pa_rtclock_get(struct timeval *tv) { no_monotonic = TRUE; if (no_monotonic) -#endif +#endif /* CLOCK_MONOTONIC */ pa_assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0); pa_assert(tv); @@ -69,7 +76,30 @@ struct timeval *pa_rtclock_get(struct timeval *tv) { return tv; -#else /* HAVE_CLOCK_GETTIME */ +#elif defined(OS_IS_DARWIN) + static mach_timebase_info_data_t tbi; + uint64_t nticks; + uint64_t time_nsec; + + /* Refer Apple ADC QA1398 + Also: http://devworld.apple.com/documentation/Darwin/Conceptual/KernelProgramming/services/services.html + + Note: argument is timespec NOT timeval (timespec uses nsec, timeval uses usec) + */ + + /* try and be a mite efficient - maybe I should keep the N/D as a float !? */ + if (tbi.denom == 0) + mach_timebase_info(&tbi); + + nticks = mach_absolute_time(); + time_nsec = nticks * tbi.numer / tbi.denom; // see above + + tv->tv_sec = time_nsec / PA_NSEC_PER_SEC; + tv->tv_usec = time_nsec / PA_NSEC_PER_USEC; + + return tv; + +#else /* OS_IS_DARWIN */ return pa_gettimeofday(tv); @@ -77,19 +107,30 @@ struct timeval *pa_rtclock_get(struct timeval *tv) { } pa_bool_t pa_rtclock_hrtimer(void) { -#ifdef HAVE_CLOCK_GETTIME + +#if defined(HAVE_CLOCK_GETTIME) struct timespec ts; #ifdef CLOCK_MONOTONIC + if (clock_getres(CLOCK_MONOTONIC, &ts) >= 0) return ts.tv_sec == 0 && ts.tv_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC); -#endif +#endif /* CLOCK_MONOTONIC */ pa_assert_se(clock_getres(CLOCK_REALTIME, &ts) == 0); return ts.tv_sec == 0 && ts.tv_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC); -#else /* HAVE_CLOCK_GETTIME */ +#elif defined (OS_IS_DARWIN) + mach_timebase_info_data_t tbi; + uint64_t time_nsec; + + mach_timebase_info(&tbi); + /* nsec = nticks * (N/D) - we want 1 tick == resolution !? */ + time_nsec = tbi.numer / tbi.denom; + return time_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC); + +#else /* OS_IS_DARWIN */ return FALSE; #endif @@ -98,6 +139,7 @@ pa_bool_t pa_rtclock_hrtimer(void) { #define TIMER_SLACK_NS (int) ((500 * PA_NSEC_PER_USEC)) void pa_rtclock_hrtimer_enable(void) { + #ifdef PR_SET_TIMERSLACK int slack_ns; -- cgit From 542fa468c26c5035485dc73392c57c222183b510 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Mon, 19 Oct 2009 12:48:00 +0200 Subject: Mac OS X: add semaphore implementation On Wed, Sep 16, 2009 at 11:57:04PM +0200, Lennart Poettering wrote: > On Wed, 16.09.09 15:15, Daniel Mack (daniel@caiaq.de) wrote: > > > + s = pa_xnew(pa_semaphore, 1); > > + MPCreateSemaphore(UINT_MAX, value, &(s->sema)); > > + pa_assert(s->sema != 0); > > Hmm, I'd prefer if the ret val of MPCreateSemaphore() would be checked > here. > > Also I find it a bit weird checking for s->sema, though not > initializing it to 0 in the beginning. If the call actually failed, > then the assert will check uninitialized memory. Also, comparing > pointers with 0 sucks. That should be NULL. > > Given that this can not realisitically fail, only in OOM or OOM-like > situations in which case we abort anyway it mght be enough just writing: > > pa_assert_se(MPCreateSemaphore(UINT_MAX, value, &s->sema) == 0); > > (Assuming that success is signalled by retval == 0 on MacOSX) > > > +void pa_semaphore_free(pa_semaphore *s) { > > + pa_assert(s); > > + MPDeleteSemaphore(s->sema); > > Same here. > > > + pa_xfree(s); > > +} > > + > > +void pa_semaphore_post(pa_semaphore *s) { > > + pa_assert(s); > > + MPSignalSemaphore(s->sema); > > And here. > > > +} > > + > > +void pa_semaphore_wait(pa_semaphore *s) { > > + pa_assert(s); > > + /* should probably check return value (-ve is error), noErr is ok. */ > > + MPWaitOnSemaphore(s->sema, kDurationForever); > > And here. Ok, done. See the patch below. Daniel >From 26df2fbae6d9215a3ae084876fb5f79e4d9cf4f0 Mon Sep 17 00:00:00 2001 From: Kim Lester Date: Wed, 16 Sep 2009 09:23:39 +0800 Subject: [PATCH] Mac OS X: add semaphore implementation --- src/pulsecore/semaphore-osx.c | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/pulsecore/semaphore-osx.c diff --git a/src/pulsecore/semaphore-osx.c b/src/pulsecore/semaphore-osx.c new file mode 100644 index 00000000..73f43559 --- /dev/null +++ b/src/pulsecore/semaphore-osx.c @@ -0,0 +1,63 @@ +/*** + This file is part of PulseAudio. + + Copyright 2009 Kim Lester + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include + +#include "semaphore.h" + +struct pa_semaphore +{ + MPSemaphoreID sema; +}; + +pa_semaphore* pa_semaphore_new(unsigned int value) { + /* NOTE: Can't assume boolean - ie value = 0,1, so use UINT_MAX (boolean more efficient ?) */ + pa_semaphore *s; + + s = pa_xnew(pa_semaphore, 1); + pa_assert_se(MPCreateSemaphore(UINT_MAX, value, &s->sema) == 0); + + return s; +} + +void pa_semaphore_free(pa_semaphore *s) { + pa_assert(s); + pa_assert_se(MPDeleteSemaphore(s->sema) == 0); + pa_xfree(s); +} + +void pa_semaphore_post(pa_semaphore *s) { + pa_assert(s); + pa_assert_se(MPSignalSemaphore(s->sema) == 0); +} + +void pa_semaphore_wait(pa_semaphore *s) { + pa_assert(s); + /* should probably check return value (-ve is error), noErr is ok. */ + pa_assert_se(MPWaitOnSemaphore(s->sema, kDurationForever) == 0); +} -- cgit From 5c576507693c1d7c4aa8c51656b37c91bcf1289b Mon Sep 17 00:00:00 2001 From: David Yoder Date: Fri, 30 Oct 2009 09:54:08 -0500 Subject: daemon: realpath segfault fix Lennart, Apparently I was debugging this at the same time as you. I can't figure out why my Fedora 11 install with glibc-2.10 has a glibc realpath that doesn't match the gnu documentation and returns null. But it does. Your commit aa8ce5bb9b159abb2ffb0f43996340566fc2e9c6 almost fixed my problem, but it needs a tweak. Thanks, David Yoder --- src/daemon/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/daemon/main.c b/src/daemon/main.c index 576fc3e6..c73e9afc 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -425,7 +425,7 @@ int main(int argc, char *argv[]) { pa_set_env("LD_BIND_NOW", "1"); - if (!(canonical_rp = pa_realpath(PA_BINARY))) { + if ((canonical_rp = pa_realpath(PA_BINARY))) { if ((rp = pa_readlink("/proc/self/exe"))) { -- cgit From b83d7a27cee4a436e4d692a9bba1b426090f4d12 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Sat, 31 Oct 2009 01:58:26 +0100 Subject: configure.ac: enable check for CoreAudio --- configure.ac | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/configure.ac b/configure.ac index 1022a6ea..2bc068e6 100644 --- a/configure.ac +++ b/configure.ac @@ -742,6 +742,28 @@ AC_SUBST(HAVE_OSS) AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS" = x1 && test "x${oss_output}" != "xno"]) AM_CONDITIONAL([HAVE_OSS_WRAPPER], [test "x$HAVE_OSS" = x1 && test "x${oss_wrapper}" != "xno"]) +#### CoreAudio support (optional) #### + +AC_ARG_ENABLE([coreaudio-output], + AS_HELP_STRING([--disable-coreaudio-output],[Disable optional CoreAudio output support]), + [ + case "${enableval}" in + yes) coreaudio_enabled=yes ;; + no) coreaudio_enabled=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --disable-coreaudio-output) ;; + esac + ], + [coreaudio_enabled=auto]) + +if test "x${coreaudio_enabled}" != xno ; then + AC_CHECK_HEADERS([CoreAudio/CoreAudio.h], HAVE_COREAUDIO=1) +else + HAVE_COREAUDIO=0 +fi + +AC_SUBST(HAVE_COREAUDIO) +AM_CONDITIONAL([HAVE_COREAUDIO], [test "x$HAVE_COREAUDIO" = x1 && test "x${coreaudio_enabled}" != "xno"]) + #### ALSA support (optional) #### AC_ARG_ENABLE([alsa], @@ -1423,6 +1445,11 @@ if test "x$HAVE_OSS" = "x1" ; then fi fi +ENABLE_COREAUDIO=no +if test "x$HAVE_COREAUDIO" = "x1" ; then + ENABLE_COREAUDIO=yes +fi + ENABLE_ALSA=no if test "x$HAVE_ALSA" = "x1" ; then ENABLE_ALSA=yes @@ -1548,6 +1575,7 @@ echo " Have X11: ${ENABLE_X11} Enable OSS Output: ${ENABLE_OSS_OUTPUT} Enable OSS Wrapper: ${ENABLE_OSS_WRAPPER} + Enable CoreAudio: ${ENABLE_COREAUDIO} Enable Alsa: ${ENABLE_ALSA} Enable Solaris: ${ENABLE_SOLARIS} Enable GLib 2.0: ${ENABLE_GLIB20} -- cgit From 2dc37e1214f20aab528ae680e9a85fc8ea143313 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 31 Oct 2009 02:05:54 +0100 Subject: bluetooth: do not hand out access to devices that are not fully configured yet --- src/modules/bluetooth/bluetooth-util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index f8c5b778..47d62005 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -723,12 +723,14 @@ const pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_di while ((d = pa_hashmap_iterate(y->devices, &state, NULL))) if (pa_streq(d->address, address)) - return d; + return device_is_audio(d) ? d : NULL; return NULL; } const pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery *y, const char* path) { + pa_bluetooth_device *d; + pa_assert(y); pa_assert(PA_REFCNT_VALUE(y) > 0); pa_assert(path); @@ -736,7 +738,11 @@ const pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_disco if (!pa_hook_is_firing(&y->hook)) pa_bluetooth_discovery_sync(y); - return pa_hashmap_get(y->devices, path); + if ((d = pa_hashmap_get(y->devices, path))) + if (device_is_audio(d)) + return d; + + return NULL; } static int setup_dbus(pa_bluetooth_discovery *y) { -- cgit