From: Andre Noll Date: Sat, 29 Oct 2011 09:08:26 +0000 (+0200) Subject: Merge branch 't/afs_argv0' X-Git-Tag: v0.4.9~14 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=fddf60223e26c1dc1e02b432652c4ca6a237c278;hp=96dc6e5b66b37d3bd0e0e4d35e39825f374b8b40 Merge branch 't/afs_argv0' --- diff --git a/NEWS b/NEWS index 6db72253..3a702729 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ - Shared memory areas are no longer restricted to 64K. We now detect the maximal size of a shared memory area at runtime. - cleanup of the internal uptime API. + - para_server prefaults the mmapped audio file to avoid + delays on slow media. -------------------------------------- 0.4.8 (2011-08-19) "nested assignment" diff --git a/aac_afh.c b/aac_afh.c index a53a757f..7acb011d 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -191,8 +191,7 @@ static int aac_set_chunk_tv(struct afh_info *afhi, { float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023; struct timeval total; - long unsigned ms = 1000.0 * afhi->chunks_total * tmp - / mp4ASC->samplingFrequency; + long unsigned ms; if (!mp4ASC->samplingFrequency) return -E_MP4ASC; diff --git a/afs.c b/afs.c index 955b8f20..3f378051 100644 --- a/afs.c +++ b/afs.c @@ -286,6 +286,9 @@ out: * command. This function allows to pass such a structure together with a list * of further arguments (often a list of audio files) to the parent process. * + * \return The return value of the underlying call to \ref + * send_callback_request(). + * * \sa send_standard_callback_request(), send_callback_request(). */ int send_option_arg_callback_request(struct osl_object *options, @@ -1146,7 +1149,8 @@ void afs_event(enum afs_events event, struct para_buffer *pb, * \param pb Unused. * \param data Unused. * - * This table does not honor events. + * \return The images table does not honor events, so this handler always + * returns success. */ __a_const int images_event_handler(__a_unused enum afs_events event, __a_unused struct para_buffer *pb, __a_unused void *data) @@ -1161,7 +1165,8 @@ __a_const int images_event_handler(__a_unused enum afs_events event, * \param pb Unused. * \param data Unused. * - * This table does not honor events. + * \return The lyrics table does not honor events, so this handler always + * returns success. */ __a_const int lyrics_event_handler(__a_unused enum afs_events event, __a_unused struct para_buffer *pb, __a_unused void *data) diff --git a/aft.c b/aft.c index e91d734f..3d22e242 100644 --- a/aft.c +++ b/aft.c @@ -2481,6 +2481,8 @@ static void afs_stat_callback(int fd, const struct osl_object *query) * up-to-date afs status items directly. Therefore the usual callback mechanism * is used to pass the status items from the afs process to the command handler * via a shared memory area and a pipe. + * + * \return The return value of the underyling call to \ref send_callback_request(). */ int send_afs_status(struct stream_cipher_context *scc, int parser_friendly) { diff --git a/command.c b/command.c index 3ba43105..b6861b88 100644 --- a/command.c +++ b/command.c @@ -763,13 +763,11 @@ __noreturn void handle_connect(int fd, const char *peername) ret = -E_AUTH_REQUEST; goto net_err; } - numbytes = ret; ret = -E_AUTH_REQUEST; if (strncmp(buf, AUTH_REQUEST_MSG, strlen(AUTH_REQUEST_MSG))) goto net_err; p = buf + strlen(AUTH_REQUEST_MSG); PARA_DEBUG_LOG("received auth request for user %s\n", p); - ret = -E_BAD_USER; u = lookup_user(p); if (u) { get_random_bytes_or_die(rand_buf, sizeof(rand_buf)); diff --git a/crypt.c b/crypt.c index 7b7c16d3..431de6fe 100644 --- a/crypt.c +++ b/crypt.c @@ -184,24 +184,25 @@ int get_asymmetric_key(const char *key_file, int private, PARA_INFO_LOG("decoding public rsa-ssh key %s\n", key_file); ret = -ERRNO_TO_PARA_ERROR(EOVERFLOW); if (map_size > INT_MAX / 4) - goto out; + goto out_unmap; blob_size = 2 * map_size; blob = para_malloc(blob_size); ret = uudecode(cp, blob, blob_size); if (ret < 0) - goto out; + goto out_unmap; decoded_size = ret; ret = check_ssh_key_header(blob, decoded_size); if (ret < 0) - goto out; + goto out_unmap; ret = read_rsa_bignums(blob + ret, decoded_size - ret, &key->rsa); if (ret < 0) - goto out; + goto out_unmap; ret = RSA_size(key->rsa); -out: +out_unmap: ret2 = para_munmap(map, map_size); if (ret >= 0 && ret2 < 0) ret = ret2; +out: if (ret < 0) { free(key); *result = NULL; diff --git a/dccp_recv.c b/dccp_recv.c index af8e6b16..a9eab006 100644 --- a/dccp_recv.c +++ b/dccp_recv.c @@ -40,13 +40,14 @@ struct private_dccp_recv_data { static void dccp_recv_close(struct receiver_node *rn) { - struct private_dccp_recv_data *pdd = rn->private_data; - if (pdd && pdd->fd > 0) + if (!pdd) + return; + if (pdd->fd > 0) close(pdd->fd); btr_pool_free(pdd->btrp); - free(rn->private_data); + free(pdd); rn->private_data = NULL; } diff --git a/imdct.c b/imdct.c index 32928487..aab498a3 100644 --- a/imdct.c +++ b/imdct.c @@ -293,7 +293,6 @@ static void imdct_half(struct mdct_context *s, fftsample_t *output, fft(&s->fft, z); /* post rotation + reordering */ - output += n4; for (k = 0; k < n8; k++) { fftsample_t r0, i0, r1, i1; CMUL(r0, i1, z[n8 - k - 1].im, z[n8 - k - 1].re, diff --git a/ipc.c b/ipc.c index 674d1cb0..576bfe5b 100644 --- a/ipc.c +++ b/ipc.c @@ -184,6 +184,15 @@ int shm_detach(void *addr) # undef SYSCTL_SHMMAX_VARIABLE # endif +/** + * Get the maximal size of a shared memory area. + * + * The value is only computed once when the function is called for the first + * time. Subsequent calls return the number which was computed during the + * first call. + * + * \return A number suitable as an argument to \ref shm_new(). + */ size_t shm_get_shmmax(void) { static size_t shmmax; diff --git a/net.c b/net.c index 9b58e225..49026db0 100644 --- a/net.c +++ b/net.c @@ -578,10 +578,12 @@ static inline int estimated_header_overhead(const int af_type) /** * Get the maximum transport-layer message size (MMS_S). * - * The socket must be connected. See RFC 1122, 3.3.3. + * \param sockfd The socket file descriptor. * - * \return If the protocol familiy could not be determined, \p AF_INET is - * assumed. + * The socket must be connected. See RFC 1122, 3.3.3. If the protocol familiy + * could not be determined, \p AF_INET is assumed. + * + * \return The maximum message size of the address family type. */ int generic_max_transport_msg_size(int sockfd) { diff --git a/net.h b/net.h index 80f57944..79c5994c 100644 --- a/net.h +++ b/net.h @@ -8,13 +8,15 @@ /** \file net.h exported symbols from net.c */ /** - * the buffer size of the sun_path component of struct sockaddr_un + * The buffer size of the sun_path component of struct sockaddr_un. * - * While glibc doesn't define \p UNIX_PATH_MAX, it - * documents it has being limited to 108 bytes. + * While glibc doesn't define \p UNIX_PATH_MAX, it documents it has being + * limited to 108 bytes. On NetBSD it is only 104 bytes though. We trust \p + * UNIX_PATH_MAX if it is defined and use the size of the ->sun_path member + * otherwise. This should be safe everywhere. */ #ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 +#define UNIX_PATH_MAX (sizeof(((struct sockaddr_un *)0)->sun_path)) #endif /* Userland defines for Linux DCCP support. */ diff --git a/ogg_afh.c b/ogg_afh.c index 46c7b084..08023458 100644 --- a/ogg_afh.c +++ b/ogg_afh.c @@ -105,7 +105,6 @@ static int vorbis_get_header_callback(ogg_packet *packet, int packet_num, return 0; if (packet_num == 0) { ogg_stream_init(&vghd->os, serial); - ret = -E_OGG_PACKET_IN; ret = ogg_stream_packetin(&vghd->os, packet); if (ret < 0) goto out; diff --git a/oggdec_filter.c b/oggdec_filter.c index 32ffdef9..07e4cec1 100644 --- a/oggdec_filter.c +++ b/oggdec_filter.c @@ -175,6 +175,7 @@ out: pod->converted = 0; fn->min_iqs = 0; pod->vf = vf; + pod->have_more = true; } return ret; } diff --git a/sched.c b/sched.c index 06aabe02..66a17418 100644 --- a/sched.c +++ b/sched.c @@ -335,8 +335,8 @@ int sched_request_barrier(struct timeval *barrier, struct sched *s) * \param barrier Absolute time before select() should return. * \param s Pointer to the scheduler struct. * - * If \a barrier is in the past, this function requests a minimal timeout and - * returns zero. Otherwise it returns one. + * \return If \a barrier is in the past, this function requests a minimal + * timeout and returns zero. Otherwise it returns one. * * \sa sched_min_delay(), sched_request_barrier(). */ diff --git a/vss.c b/vss.c index b9afc8ed..e336a9e7 100644 --- a/vss.c +++ b/vss.c @@ -132,6 +132,7 @@ struct fec_group { uint16_t slice_bytes; }; +/** A FEC client is always in one of these states. */ enum fec_client_state { FEC_STATE_NONE = 0, /**< not initialized and not enabled */ FEC_STATE_DISABLED, /**< temporarily disabled */ @@ -952,6 +953,10 @@ static int recv_afs_msg(int afs_socket, int *fd, uint32_t *code, uint32_t *data) return 1; } +#ifndef MAP_POPULATE +#define MAP_POPULATE 0 +#endif + static void recv_afs_result(struct vss_task *vsst, fd_set *rfds) { int ret, passed_fd, shmid; @@ -986,8 +991,8 @@ static void recv_afs_result(struct vss_task *vsst, fd_set *rfds) } mmd->size = statbuf.st_size; mmd->mtime = statbuf.st_mtime; - ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE, passed_fd, - 0, &vsst->map); + ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, + passed_fd, 0, &vsst->map); if (ret < 0) goto err; close(passed_fd); @@ -1076,6 +1081,23 @@ static void vss_send(struct vss_task *vsst) } mmd->chunks_sent++; mmd->current_chunk++; + /* + * Prefault next chunk(s) + * + * If the backing device of the memory-mapped audio file is + * slow and read-ahead is turned off or prevented for some + * reason, e.g. due to memory pressure, it may take much longer + * than the chunk interval to get the next chunk on the wire, + * causing buffer underruns on the client side. Mapping the + * file with MAP_POPULATE seems to help a bit, but it does not + * eliminate the delays completely. Moreover, it is supported + * only on Linux. So we do our own read-ahead here. + */ + buf += len; + for (i = 0; i < 5 && buf < vsst->map + mmd->size; i++) { + __a_unused volatile char x = *buf; + buf += 4096; + } } } diff --git a/wma_common.c b/wma_common.c index 1dde8350..519be89c 100644 --- a/wma_common.c +++ b/wma_common.c @@ -28,6 +28,8 @@ * \param pattern_len The length of the pattern in bytes. * \param buf The buffer to search for the pattern. * \param buf_size The number of bytes in \a buf. + * + * \return A pointer into \a buf or \p NULL if the pattern was not found. */ const char *search_pattern(const char *pattern, int pattern_len, const char *buf, int buf_size) diff --git a/wmadec_filter.c b/wmadec_filter.c index 0b381c5d..c6eb0b1c 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -769,7 +769,6 @@ static void compute_mdct_coefficients(struct private_wmadec_data *pwd, *coefs++ = 0.0; continue; } - mult1 = mult; n1 = pwd->exponent_high_sizes[bsize]; /* compute power of high bands */ exponents = pwd->exponents[ch] + @@ -803,8 +802,7 @@ static void compute_mdct_coefficients(struct private_wmadec_data *pwd, mult1 = sqrt(exp_power[j] / exp_power[last_high_band]); /* XXX: use a table */ - mult1 = mult1 * pow(10, - pwd->high_band_values[ch][j] * 0.05); + mult1 *= pow(10, pwd->high_band_values[ch][j] * 0.05); mult1 /= (pwd->max_exponent[ch] * pwd->noise_mult); mult1 *= mdct_norm; for (i = 0; i < n; i++) { @@ -1012,7 +1010,6 @@ next: for (ch = 0; ch < pwd->ahi.channels; ch++) { int n4, idx; - n = pwd->block_len; n4 = pwd->block_len / 2; if (pwd->channel_coded[ch]) imdct(pwd->mdct_ctx[bsize], pwd->output, pwd->coefs[ch]);