summaryrefslogtreecommitdiff
path: root/server.c (follow)
Commit message (Collapse)AuthorAge
* server.c: Drop return statement of parse_config_or_die().Andre Noll2026-07-06
| | | | The function returns void, so the statement has no effect.
* Move xrename() from fd.c to afh.c and make it static.Andre Noll2026-07-04
| | | | It's only used there.
* server: Don't include config.h twice.Andre Noll2026-07-03
| | | | It gets already included from para.h.
* Merge topic branch t/vss into masterAndre Noll2026-06-15
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improvements for the virtual streaming system --------------------------------------------- This brings in a bunch of small improvements and a fix for a SIGHUP related bug. * t/vss: vss: Streamline vss_post_monitor(). vss: Run sender commands first in vss_post_monitor(). vss: Set mmd->offset early when paused. vss: Don't set data send barrier unnecessarily. vss: Improve documentation of --autoplay-delay. vss: Open-code fc_num_redundant_slices(). vss: Check return value of compute_slice_size(). vss: Clarify afs socket handling. vss: Handle EOF *after* sending chunks. vss: Merge vss_compute_timeout() into its caller. vss: Kill magic 100ms timeout. vss: Remove vss_chunk_time(). vss: Simplify and rename recv_afs_msg(). vss: Recompute announce timeval on SIGHUP.
| * vss: Recompute announce timeval on SIGHUP.Andre Noll2026-05-28
| | | | | | | | | | | | | | | | | | | | | | The hup subcommand does not work as expected when the argument to the --announce-time has changed in the configuration file. The problem is that we convert the argument once to a struct timeval in vss_init() and only use that for everything, but miss to update the struct on SIGHUP. Fix that by adding a ms2tv() call to handle_sighup(). To give this function access to the struct, we need to move it from struct vss_task to server.c, make it non-static and declare it in server.h.
* | Merge topic branch t/socket-cookie into masterAndre Noll2026-05-30
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | AFS socket cookie replacement ----------------------------- A small but rather intrusive patch set which touches the guts of the afs callback mechanism. * t/socket-cookie: afs: Avoid the void * argument of send_lls_callback_request(). Kill afs socket cookie and afs_client_list. afs: Improve error handling of afs_signal_post_monitor().
| * Kill afs socket cookie and afs_client_list.Andre Noll2026-04-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We now create a per-command socket pair in the command handler and use the permanent server-afs socket to pass one end of the pair from the command handler to the afs process. With this approach only the command handlers can possibly talk to the afs process, so we don't need to worry about malicious or bogus connections arriving at the local socket. Consequently, we may remove the socket cookie and employ blocking I/O for the shared memory identifiers that are transferred through the per-command socket. Connections are now dispatched in one go, obviating the need to keep track of connected clients. So remove struct afs_client and the client list.
* | server: Simplify status_refresh() and merge into server_poll().Andre Noll2026-05-08
| | | | | | | | Drop the silly uptime update code while at it.
* | server: Move alarm(2) call into handle_connect() of command.c.Andre Noll2026-05-08
|/ | | | | Since the alarm clock is cancelled in handle_connect(), let's also set it there. Remove the pointless ALARM_TIMEOUT macro while at it.
* server: Rename child_fd -> client_fd.Andre Noll2026-04-08
| | | | It's the fd to communicate with the client, after all.
* server: Rename functions to register tasks.Andre Noll2026-04-08
| | | | The new names convey better the purpose of the functions.
* Kill signal_shutdown().Andre Noll2026-04-06
| | | | | | | | | | Currently the function (a) closes the write end of the signal pipe and (b) frees the signal task structure. (a) is not really needed because the function is only called just before the process terminates anyway, and (b) can easily be avoided by having the callers allocate the structure on the stack. With signal_shutdown() gone, all signal task structures can be made local, although some need to remain static.
* Move para_reap_child() into server.c and make it static.Andre Noll2026-04-06
| | | | | Because it is only called from there. Rig it up to return negative and log with higher severity if the terminated child was the afs process.
* Switch to SPDX identifiers.Andre Noll2026-03-17
| | | | | | | | Generated with sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h followed by manually tweaking the result a bit. No license change intended.
* Move user_list.[ch] into server.[ch].Andre Noll2026-03-01
| | | | | | This works because only the server links with user_list.o. Since struct user contains a list head, list.h must now be included *before* server.h, which requires some trivial header shuffling in the .c files that include server.h.
* Move send_common.c into http_send.c.Andre Noll2026-01-26
| | | | | | | | | | | | With dccp gone, almost everything of send_common.c is specific to the http sender. The only exception is parse_fec_url(), which is called from com_sender() of command.c and from udp_send.c. Move this function to server.c and the rest to http_send.c. Make the latter static and dedoxify them. The generic_ function prefix indicates that the function works for both the http and the dccp transport. With dccp gone, this has become meaningless. We keep the prefix, though, to keep the patch small.
* Move close_on_fork.c into server.c.Andre Noll2025-12-09
| | | | | | | | Two of the four functions exposed in close_on_fork.h are only called from server.c, the other two from the senders. The former two can now be made static. Since both were implemented as one-line wrappers of the static deplete_cof_list(), we keep only that, remove the wrappers and adjust the two callers.
* Improve server documentation.Andre Noll2025-10-08
| | | | | | This touches just server.c and command.c since the sender, afs and virtual streaming system documentation has already been cleaned up in earlier commits of this series.
* server: Allocate the scheduler structure after calling afs_init().Andre Noll2025-07-13
| | | | | | | | | | | Since the audio file selector allocates its own scheduler instance, we currently allocate two instances and free only one. Avoid this memory leak by delaying the allocation until after the afs process is born. The latest possible point to allocate the scheduler instance is in server_init(), just before the signal task is initialized, so move the call to sched_new() there. Since that passes a pointer to server_poll() and this function calls status_refresh() we have to move those two functions up.
* server: Kill global variable sched.Andre Noll2025-07-13
| | | | Make it local to main() and pass the pointer to the few functions that need it.
* Make struct sched private, introduce sched_new().Andre Noll2025-07-13
| | | | | | | | | | | | | | | | This moves the declaration of the structure from sched.h to sched.c because the information stored in this structure has almost no users outside of the scheduler core. As a result, the size of the structure is no longer known outside of sched.c. To initialize a scheduler instance, users now must call the new sched_new(), passing an alternative poll function if needed, We don't let applications set the default timeout anymore because the value is kind of arbitrary anyway and most users specified one second. So hardcode this as the default. Besides allocating the scheduler structure, sched_new() also initializes the task list and the poll function pointer. Thanks to these initializations, the two conditions of sched.c removed in this patch are never true.
* server: Delay vss shutdown in command handler context.Andre Noll2025-06-13
| | | | | | | | | The sender status subcommand invoked via ->handle_connect() accesses memory that has been freed in vss_shutdown(), resulting in garbage output. This use-after-free bug is correctly reported by valgrind. It can easily be fixed by moving the vss_shutdown() call down. Fixes: 018a7b7927b76044b28eece39039cb2f5ea9c192
* server.c: Remove unused server_get_tasks().Andre Noll2025-05-28
| | | | | | | The last caller was removed when the tasks server subcommand was disabled eight years ago. Fixes: bb91597b9ecf650a63a40753f7f7c771576d252e
* Merge topic branch t/build into masterAndre Noll2025-05-20
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A medium sized series for the build system which improves the way the git version string is stored in the executables and man pages. Subsequent patches of the series remove some warts from the makefile: we no longer use order-only dependencies and the .PRECIOUS target. The merge results in a conflict against the "remove regex include" commit 67388cd4fae0. This is trivial to resolve, though. * refs/heads/t/build: Doxify version functions. Doxify OV_EXCLUDE_STATIC_CALLBACKS #define. Makefile: Fix braino in tarball target. build: Remove superfluous dependency in Makefile.real. build: Remove the .PRECIOUS target. build: Improve clean targets. build: Get rid of directory order-only dependencies. build: Compile with -Wunused -Wall also on BSD. build: Revamp git versioning. build: Merge version.{c,h} into string.{c,h}.
| * build: Merge version.{c,h} into string.{c,h}.Andre Noll2025-03-25
| | | | | | | | | | | | | | | | | | This is a preparatory patch for the upcoming revamp of the git version script. The revamped script generates version.c, a file which is currently tracked by git. We can easily get rid of it (and of version.h) since all paraslash executables link in both string.o and version.o. So let's move the three small functions of version.c to string.c and their declarations from version.h to string.h.
* | Include regex.h from para.h.Andre Noll2025-05-19
|/ | | | Every .c file includes it anyway.
* Merge topic branch t/overflow into masterAndre Noll2022-10-03
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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().
| * string: Rename para_malloc() -> alloc().Andre Noll2022-07-29
| | | | | | | | | | | | | | 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
* | Merge branch 'refs/heads/t/ll'Andre Noll2022-09-18
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two little cleanups related to the logging facility and two commits which add the ll command to para_server and para_audiod. The merge resulted in a conflict in afs.c due to the earlier merge of the poll topic branch which replaced all calls to select() by calls to poll(). The implementation of the ll server command introduced a new caller of select(), afs_select(), which needs to be replaced by afs_poll() to resolve the conflict. * refs/heads/t/ll: New server command: ll to change the log level at runtime. New audiod command: ll to change the log level at runtime. daemon: Kill get_loglevel_by_name(). server/audiod: Don't parse loglevel argument unnecessarily.
| * | New server command: ll to change the log level at runtime.Andre Noll2022-07-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes use of the infrastructure introduced in the previous patch. However, the implementation of the ll command for para_server is more involved than its audiod counterpart because in the server case we have to tell two different processes (server and afs) to change their log level while the calling process, the command handler, does not need to set the loglevel because it is about to exit anyway. For the inter-process communication we introduce a new field in the mmd shared memory area so that command handlers can read the current value or set a new value. The log level propagates from there via daemon_set_loglevel() to the server and afs processes during each iteration of the scheduler loop where para_log() will pick it up to set the log level threshold for subsequent log events. The si command handler currently refers to the argument of the --loglevel server option to include the log level in its output. With dynamic log levels this no longer works because it always prints the value from the command line or the config file rather than the run time log level. Since the new ll command also prints the loglevel when it is executed with no arguments, we simply remove this line from the si output and hope that nobody cares. The si command handler was the last user of the ENUM_STRING_VAL macro in command.c. Removing the macro also allows us to make CMD_PTR local to server.c and to remove the lopsub definitions of the server suite from command.c. However, we still include the lopsub definitions of the server *command* suite (server_cmd.lsg.h) of course. We let any authenticated user run the command with no arguments to report the current loglevel but require full privileges to change the loglevel. Thus, the check for sufficient privileges needs to be performed in the command handler.
| * | server/audiod: Don't parse loglevel argument unnecessarily.Andre Noll2022-07-02
| |/ | | | | | | | | | | | | | | | | | | | | | | | | Currently the severity string (debug, info, etc.) given to --loglevel is parsed twice: Once by lopsub, which returns the loglevel as the index into the array of severity strings. We turn this index into a string and pass the string to daemon_set_loglevel() which parses the string again to turn it back into a log level value (which happens to coincide with the index value). Clean this up by letting daemon_set_loglevel() receive a log level value rather than a severity string. This also allows us to remove the now unused ENUM_STRING_VAL() macro from audiod.c.
* | Switch from select(2) to poll(2).Andre Noll2022-08-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The select(2) API is kind of obsolete because it does not work for file descriptors greater or equal than 1024, The general advice is to switch to poll(2), which offers equivalent functionality and does not suffer from this restriction. This patch implements this switch. The fd sets of select(2) have one nice feature: One can determine in O(1) time whether the bit for a given fd is turned on in an fd set. For poll(2), the monitored file descriptors are organized in an array of struct pollfd. Without information about the given fd's index in the pollfd array, one can only perform a linear search which requires O(n) time, with n being the number of fds being watched. Since this would have to be done for each fd, the running time becomes quadratic in the number of monitored fds, which is bad. Keeping the pollfd array sorted would reduce that to n * log(n) at the cost of additional work at insert time. This patch implements a different approach. The scheduler now maintains an additional array of unsigned integers which map fds to indices into the pollfd array. This new index array is transparent to the individual tasks, which still simply pass one or more fds from their ->pre_monitor() method to the scheduler. The length of the index array equals the highest fd given. This might become prohibitive in theory, but should not be an issue for the time being. Care needs to be taken in order to deal with callers which ask for the readiness of an fd without having called sched_monitor_readfd() or sched_monitor_writefd() in the ->pre_monitor() step. Before the patch, thanks to the FD_ZERO() call at the beginning of each iteration of the scheduler's main loop, both sched_read_ok() and sched_write_ok() returned false for fds which were not asked to be watched. We need to keep it this way for a seamless transition. We achieve this by replacing the FD_ZERO() call by a memset(3) call which fills the index array with 0xff bytes. Both sched_read_ok() and sched_write_ok() call the new get_revents() helper, where we check the fd argument against the allocation sizes of the two arrays. If either function is called with an fd that was not asked to be monitored in the ->pre_monitor() step, the checks notice that the index of this fd, 0xffffffff, is larger than the highest open fd and we return "not ready for I/O". Another issue is the case where the same file descriptor is submitted twice in ->pre_monitor() to check for readiness with respect to both reading and writing. The code in client_comon.c currently does that. To keep it working, the scheduler needs to detect this case and re-use the existing slot in both arrays.
* | Rename ->{pre,post}_select methods to ->{pre,post}_monitor.Andre Noll2022-08-25
| | | | | | | | | | | | | | 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().Andre Noll2022-08-25
| | | | | | | | | | | | | | | | 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().Andre Noll2022-08-25
| | | | | | | | | | | | | | | | | | | | 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().Andre Noll2022-08-25
| | | | | | | | | | | | 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.Andre Noll2022-08-25
| | | | | | | | | | | | | | | | | | | | 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.
* | sched: Use integer value for select timeout.Andre Noll2022-08-25
|/ | | | | | | | | | | | | This modifies the public struct sched so that users pass in the default timeout as an integer value in milliseconds rather than a struct timeval. This simplifies the code a little and eases the transition from select(2) to poll(2) because poll(2) also takes a plain integer for the timeout. Since para_select() of fd.c now calls ms2tv() to convert the timeout back to a struct timeval, all executables which link with fd.o must also link with time.o. This was not the case for para_mixer and para_audioc, so configure.ac needs to be adjusted accordingly.
* server: Early vss shutdown for command handlers.Andre Noll2022-05-16
| | | | | | Command must communicate with the vss through the shared memory area (mmd). Deallocating all resources early in the command handler makes the code more robust and saves some memory.
* Merge branch 'maint'Andre Noll2022-05-14
|\ | | | | | | | | | | | | To get the single fix that was just merged to maint. * maint: server: Fix memory leak at exit.
| * server: Fix memory leak at exit.Andre Noll2022-03-27
| | | | | | | | | | If command_post_select() returns failure because of a notification we leak the array of listening fds. No big deal, but worth to fix anyway.
* | web: Remove selected APIs page.Andre Noll2022-02-10
|/ | | | | This list was outdated and not well maintained. Change the link on the documentation page to point to the list of files instead.
* server: Wait for command handler exit also when afs dies.Andre Noll2021-09-29
| | | | | | | | | | | | | | | | | | | | | | | | When para_server is running in foreground mode in a terminal session, and gets signalled by hitting CTRL+C, it is unspecified whether the server or the afs process receive the resulting SIGINT first. It may even happen that the afs process dies first, and that the server sees the resulting SIGCHLD *before* the SIGINT. In this case we currently don't wait for the command handlers to exit but proceed right away with the shutdown, closing the signal pipe and destroying the shared memory area which contains the mmd structure. This leads to error messages on shutdown such as Sep 21 12:38:18 (5) (29166) para_semop: semaphore set 12648470 was removed Sep 21 12:38:18 (6) (29166) para_semop: fatal semop error Invalid argument: pid 29166 Sep 21 12:38:18 (6) (29161) generic_signal_handler: Bad file descriptor Sep 21 12:38:18 (6) (29164) para_semop: fatal semop error Invalid argument: pid 29164 Sep 21 12:38:18 (6) (29165) command_handler_sighandler: terminating on signal 15 Sep 21 12:38:18 (6) (29165) para_semop: fatal semop error Invalid argument: pid 29165 This commit avoids the issue by letting the server wait for all its children also in the SIGCHILD case when we exit because the afs process has terminated.
* server.c: Fix double "the" in comment.Andre Noll2021-08-30
| | | | Found by the vim spell checker.
* afh: Constify definition of audio format handlers.Andre Noll2018-12-21
| | | | | | | | | | | | | | | | | | | | | | | | | | The audio_format_handler structure contains only pointers, and the ->init method of each instance initializes these pointers to constant values. The ->init() method is thus useless at best, and it prevents the structures from being declared constant. This patch removes ->init() of struct audio_format_handler and the public afh_init() which iterates over all audio formats to call each ->init() method. The audio format handlers are modified to define an instance of the structure rather than an init function which fills the fields of the given structure. The structure can be declared constant, but not static because afh_common.c needs a way to refer to it. We rely on weak symbols to deal with audio format handlers which are not compiled in. The codec-independent code in afh_common.c defines a weak instance of the audio_format_handler structure for each audio format. The command handlers which are compiled in override the weak symbol with their own definition. The afh receiver used to define afh_init() as its (receiver!) init function, which no longer exists. Since receiver init functions are optional, we don't need to supply a replacement. However, play.c calls ->init() of the afh_receiver unconditionally. This call needs to be removed to avoid a null pointer dereference.
* Check for abstract sockets only once.Andre Noll2018-08-12
| | | | | | | | | | | | | | | In net.c there is a static variable which is supposed to cache whether the abstract local socket namespace is supported. This variable is pointless because it is only ever set by command handlers, which exit after the command completed. Hence the command handler process of each subsequent afs command checks again. To make the caching work as intended we must initialize the variable in the *parent* process. The parent process, however, does not create any local sockets. This patch changes init_unix_addr() to initialize the variable without creating a socket when NULL is passed as the name parameter. The server process passes NULL to initialize the static variable while command handlers pass non NULL.
* Merge branch 'refs/heads/t/long-help'Andre Noll2018-06-10
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This series introduces lsu.c and lsu.h which contain helpers related to the lopsub library. These helpers are designed to be shared between the executables. The series starts by implementing a generic help command for lopsub suites and converts para_server. Subsequent patches convert audiod and para_play. The second part of the series adds another lopsub related helper which merges command line options and config file options. Each executable is modified to make use of the new helper, getting rid of quite some code duplication. The conflict resolution for server.c has been tested for a while. Cooking for five weeks. * refs/heads/t/long-help: play: Use lsu_merge_config_file_options(). mixer: Use lsu_merge_config_file_options(). gui: Use lsu_merge_config_file_options(). filter: Use lsu_merge_config_file_options(). audioc: Use lsu_merge_config_file_options(). audiod: Use lsu_merge_config_file_options(). client: Use lsu_merge_config_file_options(). lsu: Add helper to merge config file options, convert server. Trivial: Rename completion_result variables. play: Implement help --long. audiod: Implement help --long. Introduce lsu.{c,h}, implement help --long for para_server.
| * lsu: Add helper to merge config file options, convert server.Andre Noll2018-04-22
| | | | | | | | | | | | | | | | | | | | | | | | | | After the command line options have been parsed, most paraslash executables read options from a config file. The two lopsub parse result structures are then merged in a way that command line options take preference over config file options. This logic is duplicated in all executables. This patch introduces a generic helper to eliminate the duplication. The new lsu_merge_config_file_options() will eventually be employed by all executables which need to parse the config file. This patch, however, only converts para_server.
* | Merge branch 'refs/heads/t/listen-address'Andre Noll2018-05-28
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | server: Implement --listen-address for control service.Andre Noll2018-04-17
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For hosts with multiple IP addresses one might want to configure the listening sockets so that connections can only arrive on a subset of the host's addresses. This patch implements this feature. Unlike para_listen_simple() the new para_listen() receives an optional argument to let the caller specify the listening address in addition to the port number. para_listen_simple() is now a simple wrapper that passes a NULL pointer as the new argument which indicates that the socket should listen on all local addresses, just like prior to this change. The set of listening addresses for the control service of para_server can be specified via the new --listen-address option. This option can be given multiple times, once for each listening address. Due to this change the server needs to maintain more than a single file descriptor to dispatch incoming connections. Hence the integer ->listen_fd of struct server_command_task has to be replaced by an array of file descriptors and the {pre,post}_select methods of the command task have iterate over all descriptors in the array. The meaning of the --port option has changed due to the new option: since the argument to --listen-address can also contain a port number, the argument to --port is only used for addresses with no port number, or if --listen-address is not given at all. Although the http and dccp senders also open a listening socket, this commit affects only the control service of para_server (listening on TCP 2990 by default). Senders will be covered in the next commit.