fd: Improve read_pattern(), rename it to read_and_compare(). The old name was a poor choice because the pattern argument actually is neither a regular expression nor a filename pattern. More importantly, the function receives a buffer size and tries to read this many bytes but then compares only the first part of the received buffer to the expected string. This is a rather weird calling convention. The only two callers are the http sender and receiver which both call the function during the initial handshake where no other data is available. Thus we can change the function to read only the minimal amount of data (length of the expected string), and drop the bufsize parameter. Remove the unnecessary log message in the error case and streamline the documentation while at it.
Merge topic branch t/overflow into master This series implements a new memory allocation API which checks for overflows. The first part of the series just renames the main allocation functions. Later patches in the series implement allocators which take two size_t arguments (like calloc(3)) and check whether the multiplication overflows by employing the __builtin_mul_overflow() primitive supported by gcc and clang. This requires us to bump the lowest supported gcc and clang version. * refs/heads/t/overflow: build: Compile with -ftrapv. string: Introduce arr_zalloc(). string: Introduce arr_alloc(). string: Introduce arr_realloc() and check for integer overflow. string: Rename para_calloc() -> zalloc(). string: Rename para_malloc() -> alloc(). string: Overhaul para_strdup().
Rename ->{pre,post}_select methods to ->{pre,post}_monitor. The word "monitor" is neutral and continues to be correct after the switch from select(2) to poll(2). Pure rename, nothing to see here.
Hide implementation of para_fd_set(). This preparatory patch for replacing select() renames para_fd_set() to sched_fd_set(), moves it to sched.c and makes it static. All users are modified to call either of the two new public functions sched_monitor_{read,write}fd() which take a pointer to struct sched rather than an fd set pointer.
send: Avoid select-specific arguments in {pre,post}_select(). Just pass a pointer to struct sched instead of the fd sets. Since two of the prototypes declared in send.h now refer to this structure, sched.h must be included before send.h. The udp sender implements neither ->pre_select() nor ->post_select(), so we only need to fix the order in which send.h and sched.h are included.
net: Drop fd_set parameter from para_accept(). As for read_nonblock(), the parameter is dispensable because it is only used for an optimization to avoid a system call. Get rid of it because it hinders the conversion from select(2) to poll(2).
fd: Drop fd_set parameter from read_nonblock() and friends. This parameter is not necessary because its only purpose is to avoid the readv(2) system call in case it would likely return EAGAIN because we just called select(2) which reported that there is no data to read. Since the parameter is an obstacle for the conversion of the code base from select(2) to poll(2), get rid of it for the time being. If needed we can add back an equivalent optimization which checks for POLLIN after the conversion.
string: Rename para_malloc() -> alloc(). Just because it's shorter and matches the naming of the new allocators we are about to introduce. The bulk of this patch was created with sed -i 's/para_malloc/alloc/g' *.c *.h yy/mp.y
vss: Fix harmless memory leaks at exit. The leaks were introduced in commit 4fbe16430b47 (server: Add --http-listen-address and --dccp-listen-address) from last year. Found by valgrind.
Merge branch 'refs/heads/t/listen-address' A short series which adds options for para_server that allow the user to specify the listening addresses of the passive sockets. The resolution of the conflicts in server.c and send_common.c have been well tested and were cooking for a couple of weeks. * refs/heads/t/listen-address: server: Add --http-listen-address and --dccp-listen-address. server: Implement --listen-address for control service.
Merge branch 'refs/heads/t/clean_server_exit' This series removes many memory leaks of para_server by refactoring the shutdown and signal handling code. Most of the leaks happen only at shutdown and are hence harmless. But it is still good to plug the leaks because this puts more focus on real memory leaks in the valgrind output. The merge conflicted rather badly due to the changes introduced with the crypt branch that was merged last week. The resolution has been thoroughly tested, though. * refs/heads/t/clean_server_exit: (32 commits) command.c: Document return value of handle_connect(). user_list: Make list head static. afs: Allow database switching on sighup. afs: Free current mood or playlist on exit. afs: Free status items on exit. afs: Shutdown signals on exit. server: Free parse result also in afs. afs: Deplete user list at startup. server: Free audio file header on exit. sender: Deplete ACLs on exit. Remove some unused includes from {dccp,http}_send.c. server: Make argument of user_list_init() constant. server: Deplete user list on exit. server: Combine user_list_init() and populate(). server: Move para_fgets() to user_list.c. server: Initialize user list at compile time. server: Rename functions related to user lists. server: Constify return value of lookup_user(). server: Let stat command handler perform cleanup on signals. server: Have afs process close the current mood on exit(). ...
server: Add --http-listen-address and --dccp-listen-address. Currently the http and the dccp sender accept connections on all IP addresses. This commit makes it possible to configure the senders to listen only on the specified subset of addresses. To make this work, the sender_status structure has to be extended to store an array of file descriptors rather than just a single one. Several places need to iterate over all listening sockets of the sender. The new FOR_EACH_LISTEN_FD macro helps to avoid duplicating the corresponding loop. The status part of the sender command now prints the listening addresses instead of just on/off. This is why we also maintain the ascii representation of the listening addresses in the sender_status structure and introduce the format_url() helper to format host/port pairs.
Move MAX_HOSTLEN from server.h to net.h. This generic networking-related constant does not belong to server.h. However, since server.h uses the constant, we have to make sure that net.h is included before server.h.
send_common: Improve error diagnostics of generic_com_on(). Currently the function returns an error code but does not log a message on errors. The callers, http_send_init() and dccp_send_init(), print the strerror text with no indication that it is was generic_com_on() which caused the error. This commit moves the log messages from the callers to generic_com_on() and changes the return type of generic_com_on() to void because both callers now ignore the return value. The new log messages include a text which tells the user what went wrong.
sender: Deplete ACLs on exit. This teaches the dccp and the http sender to empty their access control lists during shutdown, avoiding some (harmless) memory leaks at exit.
Remove some unused includes from {dccp,http}_send.c. The access control and close on fork lists are handled in send_common.c, so the two senders do not need to know anything about them. The dccp sender does not perform chunk queuing, so it does not need to include chunk_queue.h.
server: Cleanly shut down senders on exit. This introduces ->shutdown for struct sender. Each of the three senders implements the new method to close file descriptors and to deallocate the resources occupied by the sender. The method is only called on exit via the new vss_shutdown() from both server and command handler context after schedule() returns. We need to introduce another helper, process_is_command_handler(), to distinguish between the two callers.
server: Make array of senders constant. Currently we define an array of static non-constant sender structures in vss.c with only ->init being initialized at compile time. At startup the ->init method of each sender must fill out the other function pointers of the structure. This approach is kind of pointless, as these pointers are known at compile time and never change. This patch changes the three senders to define a non-static constant sender structure instead. The vss maintains an array of pointers to these structures. Since the new sender structures are non-static, they need to be doxified. We use the opportunity to provide an overview of each sender. The patch also introduces FOR_EACH_SENDER(), a macro which is used several times to replace the open-coded loops we had before.
Shorten copyright notice. The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
Convert para_server to lopsub. This is the last executable to be converted to lopsub. acl_init() is removed from acl.c, and the initialization of the access control list is moved to init_sender_status() of send_common.c. It now takes an lls_opt_result argument and calls acl_add_entry() for each argument given. The latter function needs to be made public. In dccp_send.c we check the FEC parameters and change the gengetopt config structure to contain the default values if invalid FEC parameters were given. With lopsub this is no longer possible as the lls_parse_result structure is opaque. We copy the FEC parameters to a dccp_fec_client structure anyway, so is it easiest to move the check there. The patch removes the unused gengetopt option files but leaves the gengetopt infrastructure of the build system in place. The build system will be cleaned up in subsequent patches.