Andre Noll [Mon, 12 Jun 2023 16:06:10 +0000 (18:06 +0200)]
server: Fix NULL pointer dereference in com_ls().
The previous commit which extended the -a option of the ls command
to accept an optional argument introduced the following flaw: If the
argument of -a corresponds to the name of a mood for which no files
are admissible, the server crashes due to a NULL pointer dereference
because mood_load() leaves the mood instance pointer uninitialized
although it returns zero, indicating success.
This behaviour of mood_load() contradicts the promises made in
its documentation. Fix mood_load() by not special-casing the "zero
admissible files" case, which even simplifies the code a bit. If all
goes well but no files turn out to be admissible, we now open the
score table anyway and set the mood pointer to the allocated mood as
usual. Since get_statistics() may now be called with zero admissible
files, we have to add a check there before dividing by the number of
admissible files,
Andre Noll [Wed, 23 Mar 2022 22:19:55 +0000 (23:19 +0100)]
Implement ls --admissible=m/foo.
Currently there can be only one score table at a time because the
functions of score.c refer to the global score_table variable.
To implement the new feature, we need to overcome this restriction
so that the callback of the ls command can populate an independent
score table to print its output without interfering with the score
table that is currently active.
This commit changes most functions of score.c to receive an additional
table pointer argument. All current users of the score table pass a
NULL pointer to instruct the functions to operate on the global score
table as before.
However, if the ls command is invoked with an optional mood argument
to -a. the callback calls mood_load(), followed by mood_loop() and
mood_unload(). The former returns an opaque handle which is then
passed to the other two functions to instruct them to operate on the
temporary score table instead of the global one.
To make the feature work for playlists as well, analogous functionality
is implemented in playlist.c. The new mop_loop() of aft.c performs
the disambiguation in a similar way as the activate_mood_or_playlist()
does. It is a bit simpler though, since the ls command does not have
to deal with NULL arguments and does not need to fall back to the
dummy mood.
Andre Noll [Thu, 11 May 2023 17:50:22 +0000 (19:50 +0200)]
Merge branch 'maint'
Two fixes for gcc-12 warnings, and another fix for a benign but
embarrassing braino in gcrypt.c.
* maint:
gcrypt: Fix return value of apc_get_pubkey().
error.h: Be more careful with error code masking.
mp3_afh: Drop unused fields from struct mp3header.
Andre Noll [Mon, 8 May 2023 19:25:30 +0000 (21:25 +0200)]
gcrypt: Fix return value of apc_get_pubkey().
The function is supposed to return the key size in bytes, but it
returns the number of *bits*. A consequence of this bug is that
RSA keys which are too short to encrypt our 128 byte buffer are not
rejected as they should be. This is not too serious because we'll fail
later during the encryption step. Fix the bug anyway and clarify the
documentation of apc_get_pubkey().
Andre Noll [Sat, 6 May 2023 14:49:56 +0000 (16:49 +0200)]
error.h: Be more careful with error code masking.
It should never happen that two or more of the three special high bits
(osl, lopsub, system) are set in an integer that stores a paraslash
error value, but gcc-12 can't prove this and complains as follows:
Andre Noll [Sat, 6 May 2023 14:47:21 +0000 (16:47 +0200)]
mp3_afh: Drop unused fields from struct mp3header.
These are never initialized, but still checked in compare_headers(), so
gcc-12 is right when it complains about uninitialized use. Fix this by
simply removing the uninitialized fields and the comparisons. Fix also
a whitespace issue in the definition of compare_headers() while at it.
Andre Noll [Fri, 30 Dec 2022 14:08:59 +0000 (15:08 +0100)]
Consolidate EOF error codes.
Currently we have ~15 error codes which indicate an EOF condition. One
should suffice, so drop all codes except the generic E_EOF and use
that everywhere.
Andre Noll [Fri, 30 Dec 2022 13:47:46 +0000 (14:47 +0100)]
sched: Improve error diagnostics.
Currently the error code of the negative return value
from ->post_monitor() is not logged anywhere under normal
conditions. Instead we log "[dead]" in unlink_and_free_task(). Replace
this by a more meaningful message in task_reap().
Andre Noll [Sun, 13 Nov 2022 00:33:17 +0000 (01:33 +0100)]
build: Activate warnings and LTO on *BSD.
Newer versions of BSD ship compilers/packages which no longer
throw warnings, so activate the warnings on all platforms. Also LTO
(link-time optimization) seems to work on the test machines now,
so activate this as well.
Tested on FreeBSD-13.1 with clang-13.0.0 and on NetBSD-9.3 with
gcc-7.5.0.
Andre Noll [Thu, 29 Sep 2022 15:52:45 +0000 (17:52 +0200)]
Add two new tests for para_server.
In a (non-public) development branch the add subcommand was broken
although t0004-server exercises this subcommand and reported no
error. The bug went unnoticed because it would only bite when the
subcommand was given a directory to add, but the test specifies a
pathname which refers to a regular file.
To detect such breakage early, add a test which tries to add a
directory and another which exercises the rm command.
Andre Noll [Sun, 25 Sep 2022 22:01:48 +0000 (00:01 +0200)]
Manually tweak Doxyfile to squash warnings.
The Doxyfile introduced by the previous commit (created by running doxygen -u)
causes doxygen to complain:
warning: Tag 'TCL_SUBST' at line 260 of file '-' has become obsolete.
To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
warning: argument 'a4wide' for option PAPER_TYPE is not a valid enum value
Using the default: a4!
Andre Noll [Sun, 25 Sep 2022 21:27:17 +0000 (23:27 +0200)]
Update DOXYFILE.
The patched file was created with doxygen -u with no manual editing. We
picked doxygen-1.8.17 although that's already a bit old because this
version ships with Ubuntu-20.04. However, this version generates a file
list (shown on the Documentation page) which lacks the description
column, so we use a self-compiled doxygen executable for the time
being.
Andre Noll [Mon, 30 Jan 2023 14:10:32 +0000 (15:10 +0100)]
aft: Always copy and compare full hash value.
Although we switched to 32 byte hash function in paraslash-0.7.0,
we kept comparing only the first 20 bytes to verify that the file
has not changed. Also the ls output and the status items contained
only the first 20 bytes of the hash value.
Andre Noll [Tue, 24 Jan 2023 22:13:55 +0000 (23:13 +0100)]
server: Don't save bogus chunk table for aac files.
The audio file selector stores the chunk table of each audio file
as an osl disk object. Since the aac audio format handler employs
dynamic chunks, these on-disk chunk tables of aac files will never
be consulted for streaming. They exist only for consistency with the
other audio formats and should be empty.
Due to a mis-computation of the chunk table size in the callback of
the add command we happen to store the serialized lopsub parse result
as the chunk table.
This is a benign bug since it only affects the ls command, and only
if -l=c is given to print the chunk table.
Andre Noll [Thu, 6 Oct 2022 15:12:13 +0000 (17:12 +0200)]
Fix memory leak in para_play().
We leak one filter parse result per audio file played. Valgrind reports:
==24559== 24 (12 direct, 12 indirect) bytes in 1 blocks are definitely lost in loss record 34 of 104
==24559== at 0x4044B0B: calloc (vg_replace_malloc.c:1328)
==24559== by 0x453A997: lls_parse (lopsub.c:768)
==24559== by 0x8057612: filter_setup (filter_common.c:98)
==24559== by 0x80500A4: load_file (play.c:377)
==24559== by 0x80500A4: load_next_file (play.c:454)
==24559== by 0x80500A4: play_post_monitor (play.c:1154)
==24559== by 0x8051110: call_post_monitor (sched.c:80)
==24559== by 0x8051110: sched_post_monitor (sched.c:106)
==24559== by 0x8051110: schedule (sched.c:148)
==24559== by 0x804EB80: main (play.c:1217)
Andre Noll [Tue, 24 Jan 2023 18:57:33 +0000 (19:57 +0100)]
server: ls -l=c: Don't print chunk table in case of dynamic chunks.
The chunk table stored in the osl disk object of the paraslash
database is useless for audio formats which support dynamic chunks
(aac only). Omit this part of the ls output.
Andre Noll [Tue, 24 Jan 2023 18:16:50 +0000 (19:16 +0100)]
server: Fix ls -l=c.
This classic copy+paste bug caused ls -l=c to work as if -l=m had
been given. Introduced seven years ago in commit 7af252cbfe13 (server:
Convert com_ls() to lopsub).
Andre Noll [Tue, 17 Jan 2023 15:29:16 +0000 (16:29 +0100)]
Merge topic branch t/ff-compat into master
A single commit which removes support for the old syntax of the ff
command where negative values could be specified with a postfix such
as "ff 30-". This syntax has long been deprecated.
* refs/heads/t/ff-compat:
server: Remove compatibility code of com_ff().
Andre Noll [Thu, 1 Dec 2022 17:08:44 +0000 (18:08 +0100)]
Merge topic branch t/openssl-3 into master
Two patches. The first suppresses warnings when compiling against
openssl-3, the second switches the two hash functions over to the
EVP API. More work is needed but it does not hurt to merge this first
step now.
* refs/heads/t/openssl-3:
openssl: Switch to evp API for sha1 and sha256.
openssl: Deactivate openssl-3 warnings for now.
Andre Noll [Wed, 9 Nov 2022 19:46:48 +0000 (20:46 +0100)]
server: Fix race condition in com_stat().
We need to block not only SIGTERM but also SIGUSR1 in the command
handler of the stat server command because otherwise the signal is
lost if it arrives within a small race window. If this happens, the
next status update will be up to 50 seconds late. The race condition
is even explained in the comment nearby...
The bug was observed in a situation where the last admissible file
of the current mood became inadmissible, causing the server to stop
streaming. This is reflected by the status flags transition from P
(playing) to N (stopped) via the intermediate state PN (trying to
load next file). After either transition the server process sends
SIGUSR1 to the command handler.
If the second signal arrives just after the PN state was sampled
but before the command handler goes to sleep by calling pselect(2),
the signal handler runs and sets subcmd_should_die, but this won't be
acted upon until after we sleep for up to 50 seconds in pselect(2). As
a result, para_audiod, hence para_gui, keep reporting the stale PN
state during this period.
This bug was present in the code base since day one of the git repo
in 2006.
Andre Noll [Wed, 9 Nov 2022 19:20:26 +0000 (20:20 +0100)]
server: Avoid deadlock in daemon_log().
Currently both the generic signal handler in signal.c and the signal
handler for the stat command handler in command.c call daemon_log()
via PARA_EMERG_LOG(). This is problematic because daemon_log()
takes the log mutex and the signal might arrive while daemon_log()
is executing. If this race condition is hit, the process deadlocks
because daemon_log() tries to acquire a mutex which it already holds.
All three types of server processes (main, afs and command handler)
are susceptible to this bug, but regardless of which process happens
to hit the race window, the server process hangs waiting on the mutex,
and no longer accepts connections.
Fix this by removing the problematic log call in the generic case and
by printing it out of interrupt context in the command handler case.
This bug was introduced together with the log mutex five years ago.
Andre Noll [Sun, 20 Nov 2022 18:21:35 +0000 (19:21 +0100)]
Merge topic branch t/afs-cleanups into master
A fair number of patches which clean up all parts of the audio file
selector. The most visible change is probably that error messages from
afs callbacks are sent with a proper sideband designator so that they
are written to stderr on the client side.
* refs/heads/t/afs-cleanups: (30 commits)
Introduce afs_error().
afs.c: Move com_select() and its callback down.
Rename mood_switch(), mood_close(), playlist_{open/close}.
Assume that score_open() and score_clear() always succeed.
playlist.c: Rename playlist_info -> playlist_instance.
mood.c: Rename struct mood to mood_instance.
afs.c: Rename ->handler of struct callback_query to ->cb.
Simplify and improve activate_mood_or_playlist().
afs: Replace ->init of afs tables by table operations.
Merge load_playlist() into playlist_open() and simplify.
Simplify row_belongs_to_score_table().
Remove mood.h.
Clean up and rename change_current_mood().
mood.c: Simplify and rename load_mood().
mood.c: Move struct statistics into struct mood.
afs.c: Improve activate_mood_or_playlist().
Improve playlist_open().
blob.c: Don't initialize table pointer in table->init().
blob: Constify name argument of blob_get_def_by_name().
Rename admissible_file_loop() -> score_loop().
...
Andre Noll [Wed, 16 Nov 2022 17:12:04 +0000 (18:12 +0100)]
Merge topic branch t/mixer into master
A few patches for the sleep subcommand of para_mixer, in particular
the two new options to set the initial mood.
This code has been cooking in next for exactly one month.
* refs/heads/t/mixer:
mixer: sleep: Fade out before stopping the stream.
mixer: sleep: Cycle audiod on stop.
mixer: sleep: Add --initial-mood and --initial-delay.
mixer: sleep: Always set initial volume and channel.
mixer: sleep: Improve description of sleep subcommand.
Andre Noll [Mon, 14 Nov 2022 21:16:22 +0000 (22:16 +0100)]
Merge tags 'v0.5.9' and 'v0.6.4' into maint
For some reason, the release commits for 0.5.9 and 0.6.4 releases
(which updated only the NEWS file) did not make it into the maint
branch. This octopus commit merges both tags to correct this omission.
Andre Noll [Sun, 2 Oct 2022 18:10:47 +0000 (20:10 +0200)]
Doxyfile: Remove GNUC definitions.
These defines have been present since day one of the git repo in 2006.
The log message of the cvs commit which introduced them back then
just states "activate the source browser", so it will have to remain
a mystery why __GNUC__ and __GNUC_MINOR__ needed to be predefined.
Andre Noll [Mon, 7 Nov 2022 16:34:31 +0000 (17:34 +0100)]
Merge topic branch t/net into master
A moderately sized series which contains a bunch of simple cleanups
for net.c and net.h.
* refs/heads/t/net:
net: De-doxify static functions.
net: Refer to correct man page in stringify_port().
net: Pass true/false instead of 0/1 to makesock().
net: Demote log level of error message in makesock().
net: Rename para_connect_simple() -> para_connect().
net: Make is_valid_ipv{4,6}_address() local to net.c.
net: Remove IPPROTO_DCCP define.
net: Make single-use macros local.
net: Combine documentation of struct flowopts.
net: Drop extern keyword of function declarations.
Andre Noll [Mon, 22 Nov 2021 18:41:20 +0000 (19:41 +0100)]
openssl: Deactivate openssl-3 warnings for now.
openssl-3 depreciated a bunch of functions we are using in openssl.c,
but the suggested alternatives are not available in older versions
of the openssl library. This makes a smooth transition harder than
necessary. Suppress the warnings for now.
Andre Noll [Tue, 27 Sep 2022 10:05:01 +0000 (12:05 +0200)]
gui: Allow for 4-digit image IDs on 80-character terminals.
Currently, the first digit of a 4-digit image ID get truncated to
three characters if the width of the terminal window is at its minimal
size of 80 characters. We can squeeze out two more characters from
the previous field, so this is easy to fix.
Andre Noll [Sat, 22 Oct 2022 17:59:52 +0000 (19:59 +0200)]
mood: Fix compute_score().
This fixes a bug which was introduced 10 months ago in merge
commit 88bf6848d1c (Merge branch 'refs/heads/t/rm_v1_moods'). This
merge conflicted in mood.c, and the conflicting hunks that touched
compute_score() were resolved incorrectly. Put simply, we kept the
old code and disregarded the correction factors that were introduced
by the other side of the merge. As a result, at mood load time the
correction factors were initialized correctly but not taken into
account for computing the score of the admissible files.
The fact that the bug went unnoticed for so long can only mean that
the correction factors don't make much of a difference in practice.
However, the bug was found because one particular mood behaved
unexpectedly, likely because its admissible files consisted of a
bunch of very new files among many very old ones.
Andre Noll [Mon, 16 May 2022 19:08:05 +0000 (21:08 +0200)]
server: Remove compatibility code of com_ff().
The old syntax "ff 30-" is undocumented and deprecated since four
years thanks to commit 9d232e63. According to the comment, the removal
of the feature was scheduled for 0.7.0 but as of 0.7.1 the syntax is
still accepted. So remove the extra code now.
Andre Noll [Tue, 30 Aug 2022 11:55:54 +0000 (13:55 +0200)]
Introduce afs_error().
The callbacks of some afs commands employ the normal ->pbpout para
buffer to send an error message to the client on failure. These
messages are therefore tagged with the OUTPUT sideband designator
just as regular command output.
The receiving client writes such messages to stdout, so applications
which call para_client have no other way than parsing the output to
guess whether it is normal command output or an error message.
This commit improves on this by providing a public helper in afs.c
to format and send an error message that is tagged with the ERROR
sideband designator and thus gets written to stderr on the client
side. All afs callbacks which currently use ->pbout for error messages
are converted to call the new helper.
Andre Noll [Tue, 30 Aug 2022 11:55:48 +0000 (13:55 +0200)]
afs.c: Move com_select() and its callback down.
Preparation for the upcoming introduction of afs_error(), which will
be called by the select callback and should therefore be located
above the callback. No code changes, nothing to see here.
This naming is unfortunate because we also have the static
{mood,pl}_{open,close}() in blob.c which operate on the osl table. In
contrast, the functions renamed in this commit operate on blob objects
and change the current mood or playlist. Let's call these operations
load/unload to avoid confusion.
Andre Noll [Tue, 22 Mar 2022 18:33:52 +0000 (19:33 +0100)]
Assume that score_open() and score_clear() always succeed.
Since the score table has only volatile columns, the only possible
error is memory exhaustion, in which case we can only abort
anyway. This patch changes score_open() to abort if osl_open()
fails. This allows us to let score_clear() return void. We can't get
rid of the return value of score_open(), however, since a pointer to
this function is stored the afs table operations structure.
Andre Noll [Thu, 17 Mar 2022 21:59:44 +0000 (22:59 +0100)]
afs.c: Rename ->handler of struct callback_query to ->cb.
The term "handler" is already overloaded. Besides command and signal
handlers we have callback result handlers, table event handlers and
max size handlers for para buffers. The simple "cb" is a shorter and
clearer name for the callback function pointer.
Andre Noll [Sun, 13 Mar 2022 22:28:21 +0000 (23:28 +0100)]
Simplify and improve activate_mood_or_playlist().
The logic of this function can be simplified to match the four
possible cases for the argument. Each of the four conditional blocks
now initializes ret, mode and the message pointer.
The message is then printed into the para buffer, which is now
passed to the function instead of a char ** because this simplifies
the select callback a bit. The other callers (for init and SIGHUP
handling) pass NULL and don't need to be adjusted.
To make this work we have to make sure that the message pointer is
properly initialized in all cases, not only in the error case as
before. Thus, playlist_open() and mood_switch() are changed to return
a suitable message also on success.
For playlists, the message only contains the number of files in the
playlist. For moods we also include the afs statistics of the mood
and no longer write this information to the server log. We omit the
correction factors and the normalization divisor, however, as these
are not very interesting.
The only purpose of the num_admissible parameter of
activate_mood_or_playlist() was to let the caller log this
information. This task is now performed by playlist_open() and
mood_switch(), so the parameter can be dropped.
Andre Noll [Tue, 15 Mar 2022 20:59:12 +0000 (21:59 +0100)]
afs: Replace ->init of afs tables by table operations.
This is simpler, avoids the run-time initialization, and allows us
to mark the instances of the operations structures constant. Improve
the documentation a bit while at it.
Andre Noll [Fri, 11 Mar 2022 22:38:13 +0000 (23:38 +0100)]
Merge load_playlist() into playlist_open() and simplify.
They are reasonably small. Remove the weird calling convention with
the PLAYLIST_LOADED error code and the pointless check for the dummy
row because they only obfuscate the code. Moreover, the comment of
load_playlist() is actively misleading because this function is not
a loop callback. Extend the documentation of the combined public
playlist_open() while at it.
The code can be simplified by calling pl_get_def_by_name() rather
than osl_get_row() followed by pl_get_name_and_def_by_row().
Andre Noll [Thu, 10 Mar 2022 19:27:08 +0000 (20:27 +0100)]
Simplify row_belongs_to_score_table().
This function was over-engineered because only one caller passed a
non-NULL rank pointer without actually using the rank for anything
other than printing it in a log message. So drop the rank parameter
and adjust the callers and the log message accordingly.
Moreover, the function returned int rather than bool to be able to
also return an error code in case the osl lookup function fails. This
should never happen though, because the only possible errors are
invalid row or table pointers, and these indicate a bug. So abort in
this case and let the function return bool.
Andre Noll [Tue, 8 Mar 2022 17:46:07 +0000 (18:46 +0100)]
Clean up and rename change_current_mood().
Move the code which destroys the current mood to the end of the
function so that we can still return to the old mood if something
goes awry.
To make this work, various functions need to be adjusted to no longer
refer to to afs statistics via the global current_mood pointer. Pass
a pointer to the statistics structure to those.
Also get rid of the local mood pointer variable in favor of ->m of
struct admissible_array.
Rename the function because it is public and deserves the mood_ prefix.
Andre Noll [Tue, 8 Mar 2022 22:08:23 +0000 (23:08 +0100)]
mood.c: Simplify and rename load_mood().
We first turn the given mood name into a row of the mood table, then
get the mood definition from the row. It's equivalent and much easier
to call mood_get_def_by_name() instead.
Rename the function because init_mood_parser() tells the reader
what the function actually does.
Andre Noll [Sun, 20 Mar 2022 18:22:29 +0000 (19:22 +0100)]
mood.c: Move struct statistics into struct mood.
Because it's part of the state of an open mood. Expand and improve
the documentation of struct mood and current_mood while at it, and
kill the pointless return value of update_afs_statistics().
Andre Noll [Mon, 7 Mar 2022 19:21:59 +0000 (20:21 +0100)]
afs.c: Improve activate_mood_or_playlist().
Merge the two conditional branches to simplify the code and increase
the event counter to notify the server also in the SIGHUP case. This
is the right thing to do because we did (re)load the mood or playlist.
Andre Noll [Mon, 7 Mar 2022 18:20:07 +0000 (19:20 +0100)]
Improve playlist_open().
It's easier to let playlist_open() fill in the error text than
to do this in the caller. This is also how the counterpart of
playlist_open(), change_current_mood(), is implemented. Drop the
server log message because this error is usually caused by a client
passing a misspelt playlist name.
Fix the documentation of the return value of the function
while at it: It returns the playlist length on success, and
activate_mood_or_playlist(), its single caller in afs.c, depends
on that.
Andre Noll [Tue, 8 Mar 2022 22:05:52 +0000 (23:05 +0100)]
blob: Constify name argument of blob_get_def_by_name().
This function does not modify the string, although the char pointer
is used as the ->data pointer of an osl object, which is non-constant.
We need to cast away the const qualifier to avoid a compiler warning,
but that's still better than accepting only non-constant strings,
as this means to put the cast into the callers.
Andre Noll [Tue, 8 Mar 2022 19:47:59 +0000 (20:47 +0100)]
Rename admissible_file_loop() -> score_loop().
The function simply iterates the entries of the score table. The new
name is shorter, more to the point, and indicates that the function
is implemented in score.c.
Streamline the documentation while at it and swap the arguments,
as the reversed order is more natural.
Andre Noll [Tue, 8 Mar 2022 19:26:34 +0000 (20:26 +0100)]
Remove get_num_admissible_files().
This public function had only one caller outside of score.c and this
caller already knows the number of admissible files because this
number is also stored in the afs statistics structure.
Open-coding the remaining caller in score.c allows us to remove the
public function.
Andre Noll [Tue, 8 Mar 2022 22:55:26 +0000 (23:55 +0100)]
mood.c: Remove row_is_admissible().
The function has become trivial, so open-code the one-liner twice.
Since mp_eval_row() returns bool and never fails, the comment was
misleading and the error checking unnecessary.
Andre Noll [Tue, 15 Mar 2022 18:09:46 +0000 (19:09 +0100)]
afs.c: Remove enum afs_table_num.
The definition of afs_tables[] does not need this enumeration to
initialize the array and everybody else just needs the number of
elements which can as well be obtained with ARRAY_SIZE.
Since enum values are of type int but ARRAY_SIZE expands to a size_t
value we need an adjustment for a format string in open_afs_tables().
Andre Noll [Mon, 14 Mar 2022 22:22:58 +0000 (23:22 +0100)]
attribute.c: Remove struct addatt_event_data().
It is passed to afs_event() to tell the table event handlers the
name and bit number of the newly added attribute. However, the only
table which does not ignore attribute add events is the mood table,
and this just reloads the current mood without even looking at the
information passed.
Andre Noll [Sun, 6 Mar 2022 20:05:09 +0000 (21:05 +0100)]
mixer: sleep: Cycle audiod on stop.
This modifies the sleep command to turn off audiod before sending the
stop command to the server. This way the stream terminates immediately
(on the local machine) rather than when the input queue of the stream
has drained, which may be a several seconds later.
This is important because we are going to set the initial volume but
don't want to change the volume of the stream which is about to end.
Currently this is "solved" by sleeping one second, but this has always
been a hack that never worked well in practice.
In order to be able to send commands to para_audiod we introduce
audioc_cmd() which shares most of the implementation of client_cmd(),
so we make both functions wrappers for the new run() which works for both
command types.
To avoid code duplications we also introduce stop() which does the
equivalent of
Andre Noll [Sun, 20 Mar 2022 18:48:41 +0000 (19:48 +0100)]
net: Demote log level of error message in makesock().
This function has no idea how severe the failure actually is, so log
only with loglevel notice and let the callers be more verbose if this
is a stern error.
The visible result of this change is that audiod no longer prints a
warning every five seconds if the server is not running.
Andre Noll [Thu, 10 Mar 2022 22:59:04 +0000 (23:59 +0100)]
net: Make is_valid_ipv{4,6}_address() local to net.c.
These inline functions are only used in net.c, so they do not need
to be declared in net.h. De-doxyfy their documentation because static
functions don't need doxygen comments.
Andre Noll [Thu, 10 Mar 2022 23:48:20 +0000 (00:48 +0100)]
net: Remove IPPROTO_DCCP define.
This macro is defined in the system headers on all moderately new
Linux versions, FreeBSD-13 and NetBSD-9, so our local fallback is
not needed anymore.
Andre Noll [Mon, 14 Mar 2022 21:28:27 +0000 (22:28 +0100)]
Makefile: Fix compilation after header removal, try #2.
This is a revised version of 3bc858ee0d9b, which got reverted in f0b8296a0635 because of a flaw related to how CPPFLAGS was handled.
When switching from an older git version which still contains some
header file to a newer version where it got removed, a .d file remains
in build/deps which lists the no longer existing header file as a
prerequisite. This causes the build to fail because the prerequisite
cannot be created. The problem can be worked around by removing the
stale .d file, for example by running make clean, but this is no real
fix, and is inefficient.
The root of the matter is that .d files depend on their .c counterpart,
but this dependency is not stated anywhere in the Makefile. Thus, we
need a rule for the .d target with the same prerequisites and the same
recipe as the object file target. GNU make supports multiple targets,
but the feature does not seem to work as advertised, regardless of
whether rules with independent targets or rules with grouped targets
(using the &: separator) are employed. Thus we bite the bullet and
use two separate rules.
Another issue is that the CC command refers to CFLAGS and CPPFLAGS,
which get modified according to the target. We currently do this
modification only for object files but not for the dependency files,
so this needs to be fixed as well. We make use of make's "call"
function feature to avoid having to duplicate the file names and
patterns.
Andre Noll [Sun, 13 Mar 2022 19:49:41 +0000 (20:49 +0100)]
para_play: Compute the current time more accurately.
Currently get_play_time() throws away the subsecond part of the
timeval and returns a number in seconds. We can improve on that
by letting the function return milliseconds instead. However, with
milliseconds we must perform multiplications using 64 bit integers
to avoid integer overflows.
This also affects the pause and play commands, which should now
reposition the stream more accurately. It still won't be perfect,
though, because play.c has no way of knowing the number of the chunk
which is currently being decoded.
Andre Noll [Mon, 3 Oct 2022 15:59:56 +0000 (17:59 +0200)]
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.