Andre Noll [Wed, 23 Jul 2025 16:25:16 +0000 (18:25 +0200)]
vss: Fix (harmless) memory leak.
Without the call to afh_close(), if an mp4 file is being streamed when a
server command is executed, valgrind reports many memory leaks such as this:
32,384 bytes in 1 blocks are still reachable in loss record 10 of 10
at 0x4047BE2: realloc (vg_replace_malloc.c:1801)
by 0x8052A99: arr_realloc (string.c:40)
by 0x8052AC8: arr_alloc (string.c:61)
by 0x8069CE7: read_stsz (mp4.c:244)
by 0x8069CE7: parse_sub_atoms (mp4.c:563)
by 0x806A3A6: parse_sub_atoms (mp4.c:575)
by 0x806A3A6: parse_sub_atoms (mp4.c:575)
by 0x806A3A6: parse_sub_atoms (mp4.c:575)
by 0x806A3A6: parse_sub_atoms (mp4.c:575)
by 0x806A524: open_file (mp4.c:622)
by 0x806A5B0: mp4_open (mp4.c:669)
by 0x8069593: aac_afh_open (aac_afh.c:69)
by 0x804E7DF: afh_get_chunk (afh_common.c:249)
This only affects aac/mp4 because this is the only supported audio format
which employs dynamic chunks.
Andre Noll [Wed, 9 Jul 2025 21:33:47 +0000 (23:33 +0200)]
aft: Don't leak status_item_ls_data.path.
Currently we initialize this pointer variable by creating a copy of the memory
mapped osl object on the heap, and leak this copy on exit. We may avoid the
copy since we may as well look up the path again in make_status_items(). This
is cheap because we already know the row of the audio file table at this point.
Andre Noll [Sun, 6 Jul 2025 23:00:47 +0000 (01:00 +0200)]
aft: Simplify make_inode_status_items().
This function calls get_audio_file_path_of_row() although the path is already
known at this point. Moreover, since the function is called twice to produce
the human-readable and the parser-friendly status items, we perform identical
work in each call. We can easily avoid a system call by calling stat(2)
only once in the caller, The mtime string is also computed twice, so move
the computation into the caller as well.
Andre Noll [Mon, 28 Jul 2025 16:08:43 +0000 (18:08 +0200)]
call_callback(): Fix error text.
It was clearly intended to print the error text which corresponds to ret2
here because the function returns ret but discards the value of ret2 after
logging the error.
Andre Noll [Wed, 9 Jul 2025 23:54:11 +0000 (01:54 +0200)]
Modify para_hostname() to return a static buffer.
All but one caller immediately free the result after using it. The exception
is daemon.c, which maintains a copy in struct daemon, and leaks it on exit.
All users can trivially be converted to use the new version, which does not
require to free the result.
Andre Noll [Wed, 9 Jul 2025 23:38:01 +0000 (01:38 +0200)]
audiod: Free status items on exit.
In close_stat_pipe() we call clear_and_dump_items(), then dump the
status items again for no good reason. Rename clear_and_dump_items() to
clear_status_items(), stop dumping items there, and call the new function
also from audiod_cleanup() to avoid the memory leaks at exit.
Andre Noll [Wed, 9 Jul 2025 22:34:24 +0000 (00:34 +0200)]
openssl: Fix a memory leak.
This leak happens only with openssl-1.1, where we call RSA_free() which does
not free the coefficient for the Chinese remainder theorem we extracted from
the key file.
Andre Noll [Tue, 8 Jul 2025 19:00:32 +0000 (21:00 +0200)]
fec: Don't oversize gf_exp[].
Apart from the initialization code, there is only one user of the Galois
field exponential table. This user passes a value modulo GF_SIZE, so we
never access the second half of the array.
Andre Noll [Mon, 30 Jun 2025 18:27:11 +0000 (20:27 +0200)]
server: Allocate the scheduler structure after calling afs_init().
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.
Andre Noll [Tue, 10 Jun 2025 14:06:03 +0000 (16:06 +0200)]
Make struct sched private, introduce sched_new().
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.
Andre Noll [Tue, 8 Jul 2025 20:28:24 +0000 (22:28 +0200)]
btr: Fix buffer tree merging.
The merge case of add_btrb_to_children() is rather broken. For one, if
the node has more than one child and we end up freeing the btr buffer in
the first iteration, we read stale contents when calling may_merge_btrb()
in the next iteration of the loop.
Secondly, not all callers of add_btrb_to_children() cope with btrb being
freed after merging occurred. In particular, the alsa writer triggers an
invalid read such as:
at 0x804C7AC: btr_drop_buffer_reference (buffer_tree.c:351)
by 0x804CD4A: btr_pushdown_br (buffer_tree.c:520)
by 0x804CD4A: btr_pushdown (buffer_tree.c:539)
by 0x804D948: check_wav_post_monitor (check_wav.c:194)
by 0x804C31B: call_post_monitor (sched.c:118)
by 0x804C31B: sched_post_monitor (sched.c:144)
by 0x804C31B: schedule (sched.c:184)
by 0x804A9CE: setup_and_schedule (write.c:97)
by 0x804A9CE: main (write.c:149)
The problem is that btr_pushdown_br() calls add_btrb_to_children(), followed
by btr_drop_buffer_reference(). The first function frees br->btrb in the
may-merge case and the second function reads from this pointer.
This patch addresses both issues. It renames may_merge_btrb() to
try_merge_btrb(), checks more carefully if a merge is possible, and performs
the merge. This function needs to return whether the buffer was merged because
the callers have to clean up in different ways depending on whether or not
buffers were merged.
This retains the nice speedup of f64cbcc03484 at the cost of even more
complicated buffer tree code.
Reproducer (must run on a slow machine or under valgrind to trigger):
Andre Noll [Sun, 6 Jul 2025 22:27:48 +0000 (00:27 +0200)]
aft: Reload afhi before creating the status items.
make_status_items() accesses the audio format handler information via
status_item_ls_data.afhi, which was set when the current audio file was
loaded. However, the pointers of the ahfi structure might have become stale
if the server reloads the afs tables in between, for example when SIGHUP
was received. This may lead to a crash or worse.
Andre Noll [Sun, 6 Jul 2025 21:20:16 +0000 (23:20 +0200)]
aft: Improve error path of open_and_update_audio_file().
On errors that occur after status_item_ls_data->path has been initialized, we
return without setting ->path to NULL. This is bad because a subsequent event
could call make_status_items(), which then proceeds using the invalid path.
This commit adds a few labels to improve the error handling and to clean
up properly in all cases. A side effect of this change is that on certain
errors where we used to fail we now continue, trying the next best file as
long as there are entries left in the score table.
Andre Noll [Mon, 30 Jun 2025 17:46:14 +0000 (19:46 +0200)]
Improve error diagnostics of add server command.
If a file whose path does not match any known ending is attempted to be
added, we silently ignore the file even if --verbose is given. This happens
for example, if the audio format handler for the given file was not compiled
in. Make this case more obvious by sending a message if --verbose is given.
Andre Noll [Mon, 16 Jun 2025 19:36:19 +0000 (21:36 +0200)]
mood: Don't abort the check if an empty mood exists.
It's perfectly valid to define a mood whose definition is empty. Nevertheless,
the osl loop callback mood_get_name_and_def_by_row(), which is called by the
check subcommand, returns an error in this case because it cannot map the
empty file. This terminates the osl loop and results in a rather cryptic
error about loop termination. To improve on this, detect this case, print
a more decent message, and continue the loop.
Empty playlists were handled correctly, but the name of the empty playlist
was not shown in the message. Fix this as well.
Andre Noll [Sat, 14 Jun 2025 17:03:59 +0000 (19:03 +0200)]
aft: Avoid unnecessary allocation of current hash buffer.
Currently we allocate the hash pointer of the global status_item_ls_data
structure once at first use. We can avoid the allocation by having it point
to the global current_hash[]. This way it always contains an up-to-date value,
so we no longer need to re-lookup the hash in aft_close().
Andre Noll [Sun, 29 Jun 2025 15:45:43 +0000 (17:45 +0200)]
Merge topic branch t/deprecate_setatt into master
A single patch which deprecates the setatt server subcommand. This subcommand
fails, for example, if the name of an audio file happens to end in '+' or
'-'. The replacement for setatt is the touch subcommand, which gained two
options to set or unset attributes.
* refs/heads/t/deprecate_setatt:
server: Deprecate setatt in favor of touch.
Andre Noll [Mon, 2 Jun 2025 22:58:25 +0000 (00:58 +0200)]
sched.h: Remove an unnecessary declaration.
This incomplete declaration is not needed because the first use of struct
task is the declaration of task_register() further down in the file. This
function returns a pointer to struct task, and this works as an incomplete
declaration as well.
Andre Noll [Mon, 9 Jun 2025 19:23:59 +0000 (21:23 +0200)]
server: Delay vss shutdown in command handler context.
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.
Andre Noll [Mon, 2 Jun 2025 20:48:41 +0000 (22:48 +0200)]
Prefer __func__ to __FUNCTION__.
The former is part of the C99 standard, while the latter is only provided
for backward compatibility. This change also silences many gcc warnings when
compiling with -Wpendantic (disabled in the default build).
Andre Noll [Mon, 2 Jun 2025 22:36:31 +0000 (00:36 +0200)]
Doxgen: Do not omit brief descriptions.
Commit 3107d2411a7a was a bit overzealous because with BRIEF_MEMBER_DESC
and REPEAT_BRIEF both set to NO the short text does not even make it into
the detailed description. This was unintended, so partially revert this change.
Andre Noll [Mon, 2 Jun 2025 19:42:21 +0000 (21:42 +0200)]
Merge topic branch t/wmadec into master
A few patches which remove unused code from the wma decoder and audio
format handler. Notably, noise coding was removed completely since
it was only used for unusual bit rates. Most likely, it never worked
in the first place.
* refs/heads/t/wmadec:
wmadec: Fix typo in comment.
wmadec: Remove a stale comment in wma_init().
wmadec: Kill pointless start/end computations.
wmadec: Remove noise coding.
wmadec: Simplify wma_init().
wmadec: Remove fft().
Andre Noll [Mon, 26 May 2025 18:38:37 +0000 (20:38 +0200)]
Shrink struct rmatt_event_data.
The aft event handler needs to know the bit number of the attribute which is
being removed in order to clear the bit in the afs info structure of each row
of the audio file table. The handler does not need to know the attribute's
name, though, and remove_attribute() already prints it, so remove this field
from the event data structure.
Andre Noll [Sun, 25 May 2025 17:29:57 +0000 (19:29 +0200)]
INSTALL: Remove installation instructions of lopsub.
These days, people should just install the Debian package. If lopsub is not
installed, the configure script prints detailed instructions about how to
obtain lopsub with and without apt.
Andre Noll [Wed, 19 Mar 2025 21:05:16 +0000 (22:05 +0100)]
Introduce VSS_NEW_AUDIO_FILE to fix playlist updates.
The playlist event handler handles afsi change events by moving the affected
entry to the end of the playlist. This is the right thing to do if the
event was triggered by virtual streaming system streaming a new file. It is
incorrect, however, if the event was triggered by a subcommand such as touch.
This commit introduces the new afs event type VSS_NEW_AUDIO_FILE to distinguish
between the two different use cases. The audio file table event handler
ignores the VSS_NEW_AUDIO_FILE event while the playlist event handler ignores
the AFSI_CHANGE event. The moods event handler treats both events equally,
Get rid of a pointless static one-liner function in playlist.c while at it.
Andre Noll [Wed, 14 May 2025 22:27:47 +0000 (00:27 +0200)]
aft: Pass correct afsi argument to AFSI_CHANGE event handlers.
Each time a new audio file is opened for streaming, we update the numplayed
and lastplayed fields of its afs info entry of the audio file table, then
update the global afsi and ahfi structures, then trigger an AFSI_CHANGE event,
which calls all table event handlers. The event handlers receive as arguments
a pointer to the old afsi and a pointer to the already modified aft row.
The AFSI_CHANGE event handler of the audio file table gets called in the
situation described above, and also via the touch and cpsi subcommands,
because these also change the afsi info structure and therefore trigger
AFSI_CHANGE events as well. The handler checks whether the affected audio
file is the current audio file, and if it is, extracts the modified afsi
from the audio file table into the global afsi structure.
The problem is that in case of the above "next audio file" scenario, the
old afsi pointer points to the global afsi structure, which gets updated
by the aft event handler. Therefore the event handlers which happen to run
after the event handler of the audio file table see the already updated afsi
through the old_afsi pointer.
Since the audio file table happens to be the first table of the 7-element
afs_tables[] array iterated by afs_event(), all six other event handlers see
the incorrect afsi. However, only the moods event handler looks at the old afsi
to update the mean and quadratic variation of the lastplayed and numplayed
values of the afs statistics. Due to the bug described above, the old and
new lastplayed and numplayed values coincide, and therefore the statistics
update is a no-op. In practice, at least for moods with many admissible files,
the values will only be slightly off, so the bug is rather benign.
Fix this by renaming the on-stack new_afsi to old_afsi, adjusting
initializations accordingly, and passing a pointer to this instance instead.
Andre Noll [Wed, 21 May 2025 18:36:52 +0000 (20:36 +0200)]
Improve documentation of set_max_chunk_size().
The old text implied that the function could be removed at some point, which
is not the case. Remove this part of the documentation and clarify what the
function actually does.
Andre Noll [Wed, 21 May 2025 18:23:23 +0000 (20:23 +0200)]
Warn about old (0.5.x or earlier) on-disk afhi.
Nine years ago, starting with commit 234647bb5, old on-disk entries are
reported with a notice to re-add the file in order to update the audio file
table. Bump the loglevel for now, and add a comment to turn the check into
a hard error eventually.
Andre Noll [Tue, 20 May 2025 20:47:46 +0000 (22:47 +0200)]
buffer_tree: Assert that we don't pass NULL to memcpy().
The buffer pointer cannot be NULL here because this only happens when the
buffer tree area is full, which is not the case thanks to the previous n <=
btr_pool_unused(btrp) check.
Andre Noll [Tue, 20 May 2025 19:33:04 +0000 (21:33 +0200)]
Merge topic branch t/build into master
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}.
Andre Noll [Sun, 16 Mar 2025 23:15:40 +0000 (00:15 +0100)]
server: Deprecate setatt in favor of touch.
This adds --set-attribute and --unset-attribute to the touch subcommand,
re-implementing the features of the setatt command with a saner syntax.
We augment the change_atts_data structure using pre-computed values for
verbose and dry-run mode and pass a pointer to this structure rather than
the general callback arg pointer. The existing setatt subcommand neither
sets nor consults the two new booleans.
The touch completer of para_client is updated to complete the two new options,
executing the lsatt subcommand to get the attribute names. The manual and
the test suite also need minor adjustments.
Andre Noll [Sat, 19 Apr 2025 11:39:26 +0000 (13:39 +0200)]
Revamp bash_completion.
This rewrite of the bash_completion script improves completion for the
para_client and para_audioc commands significantly.
One flaw which is fixed by this patch is related to the fact that by default
readline creates COMP_WORDS by splitting at characters that separate a shell
command, including "=", but for paraslash commands we only want to split at
spaces. So we modify the completer to return the special code 124 to instruct
readline to try split again with space as the only delimiter.
Andre Noll [Sat, 3 May 2025 18:07:34 +0000 (20:07 +0200)]
bash completion: Fix help option parsing.
If we complete on para_client or para_audioc options rather than on server
or audiod subcommands, we parse the --help output to determine the options to
complete on. The regular expression we currently use for that is too lenient
because it also matches the options in the synopsis section of the help output.
Fix this by prefixing the expression with '^' to extract only the options
of the subsequent help text.
Andre Noll [Sun, 6 Apr 2025 20:14:43 +0000 (22:14 +0200)]
i9e: Introduce i9e_cword_is_option_arg().
Call the new function to complete --admissible, --sort and --listing-mode of
the ls subcommand and teach the touch completer to prevent filename completion
if a numerical argument is expected. The grab subcommand of para_audiod
also benefits from the new helper: para_audioc learned to complete the three
different grab modes.
Since --admissible expects a mood or playlist argument, factor out the code
from the select completer which returns the list of all moods and playlists
so that it can be called by the ls completer as well.
Andre Noll [Sun, 6 Apr 2025 17:30:53 +0000 (19:30 +0200)]
i9e: Constify i9e_complete_option().
i9e_extract_completions() and i9e_complete_option() both take a char **
argument for the option/string list although they do not modify the pointers
of the list. This commit marks these pointer variables constant.
Andre Noll [Mon, 5 May 2025 21:52:42 +0000 (23:52 +0200)]
load_afd(): Double check shared memory sizes.
The shared memory ID is sent by a trusted source, so it is a programming error
(rather than a runtime error that could be handled) if the size of the shared
memory area is smaller than the size of an audio file data structure. Thus,
the right thing to do is to abort immediately in this case.
Andre Noll [Mon, 28 Apr 2025 22:03:26 +0000 (00:03 +0200)]
mp3_afh: Document id3_field_init() and id3_field_finish().
These functions are somewhat obscure because they are not part of the
libid3tag API. They are not part of the internal paraslash API either,
so their documentation should not be shown on the API page. Exclude the
documentation with the doxygen \cond and \endcond markers.
Andre Noll [Sun, 23 Mar 2025 20:53:15 +0000 (21:53 +0100)]
blob: Get rid of the two dummy event handlers.
The four blob operation structures defined in blob.c are created by
a macro which initializes the function pointer for the event handler
to ${name}_event_handler, where $name is the blob type, i.e. one of
images, lyrics, moods, playlists.
Only two of the four, moods and playlists, need an event handler
because the images and lyrics tables ignore events. Currently we
have to define dummy functions {images,lyrics}_event_handler() to
avoid link errors. This extra code can easily be avoided by making
the macros a little smarter.
Andre Noll [Tue, 18 Mar 2025 18:31:33 +0000 (19:31 +0100)]
Check return value of lsu_com_help().
This function fails if an invalid command name is passed as the argument, yet
all callers ignore the error. Modify the callers to print the strerror text as
appropriate and no longer do that in lsu_lopsub_error(). Rename this function
and introduce the error type argument to print more meaningful error messages.