paraslash.git
2 years agoMerge branch 'maint'
Andre Noll [Thu, 24 Mar 2022 18:58:12 +0000 (19:58 +0100)]
Merge branch 'maint'

A single fix for a benign bug.

* maint:
  afs: Update dummy mood assumptions to reflect the reality.

2 years agoafs: Update dummy mood assumptions to reflect the reality.
Andre Noll [Mon, 14 Mar 2022 18:52:46 +0000 (19:52 +0100)]
afs: Update dummy mood assumptions to reflect the reality.

The code in afs.c assumes that loading the dummy mood always succeeds,
and this is even documented in change_current_mood(). However, this
has never been true because we call into osl library functions which
may fail for various reasons. In particular, if the server is started
without a database the attempt to load the dummy mood fails because
the audio file table does not exist.

The current code was not prepared to handle this case, and does stupid
things like storing the negative error code in *num_admissible and
returning success.

Fix this confusion by adjusting the documentation and letting
activate_mood_or_playlist() fail early. One of its callers,
init_admissible_files(), needs also be adjusted because it asserted
in its error path that the mood which failed to load was not the
dummy mood.

This is a benign bug because the most common way to hit this is
at startup on a fresh install when the database does not exist. In
this case the caller, init_admissible_files(), ignores the negative
num_admissible value.

2 years agocom_ls(): Drop "audio file table syntax error" messsage.
Andre Noll [Sun, 13 Feb 2022 20:29:03 +0000 (21:29 +0100)]
com_ls(): Drop "audio file table syntax error" messsage.

This error message is printed if ls is called with an invalid argument
for the listing mode or sort order. That's not a syntax error, so
use the standard EINVAL error code instead.

2 years agoaac_afh: Be more lenient about zero sized reads.
Andre Noll [Wed, 18 Aug 2021 14:44:15 +0000 (16:44 +0200)]
aac_afh: Be more lenient about zero sized reads.

These actually happen for example when the file contains a meta
tag with an empty string value. POSIX says that the read() function
shall return zero and have no other results, so don't return -1 if
the number of bytes read is zero.

Similarly, return zero if the file offset is beyond EOF.

2 years agoparaslash 0.7.0 v0.7.0
Andre Noll [Sat, 12 Mar 2022 16:31:50 +0000 (17:31 +0100)]
paraslash 0.7.0

2 years agoMerge branch 'refs/heads/t/logo'
Andre Noll [Sat, 12 Mar 2022 16:22:15 +0000 (17:22 +0100)]
Merge branch 'refs/heads/t/logo'

The fancy new svg logo and a couple of changes which streamline
the look of the web pages.

Cooking for a month.

* refs/heads/t/logo:
  web: Add horizontal space between table columns.
  web: Clean up style sheet.
  web: Avoid bold face on main page.
  web: Add padding to all pages.
  web: Move navigation into top level table.
  web: Link to "./index.html" rather than to ".".
  web: Remove selected APIs page.
  web: Avoid "integrated" in feature list of main page.
  web: Shorten slogan.
  web: The new logo for paraslash-0.7.
  manual: Avoid vertical space between coding style items.

2 years agomood.c: Fix memory leak in error path of load_mood().
Andre Noll [Thu, 10 Mar 2022 20:32:22 +0000 (21:32 +0100)]
mood.c: Fix memory leak in error path of load_mood().

When an existing mood definition happens to be invalid so that
mp_init() fails, we return negative and leak the mood structure
just allocated.

This bug was introduced by the commit which removed version 1 moods.
It was found by code inspection.

Fixes: 184ea897a9b4
2 years agoMerge branch 'maint'
Andre Noll [Sat, 12 Mar 2022 15:55:45 +0000 (16:55 +0100)]
Merge branch 'maint'

A couple of urgent fixes for old bugs, the critical one being the
patch to reject empty mood arguments.

Cooking only for a few days to get these fixes merged ASAP.

* maint:
  com_addatt(): Fix memory leak.
  mood.c: Fix memory leak in change_current_mood().
  mp.c: Fix memory leak on parse errors.
  Reject empty mood arguments.

2 years agocom_addatt(): Fix memory leak.
Andre Noll [Mon, 7 Mar 2022 21:02:11 +0000 (22:02 +0100)]
com_addatt(): Fix memory leak.

We miss to free the lopsub parse result on exit. Found by valgrind.

2 years agomood.c: Fix memory leak in change_current_mood().
Andre Noll [Tue, 8 Mar 2022 22:37:08 +0000 (23:37 +0100)]
mood.c: Fix memory leak in change_current_mood().

In two error cases we return without freeing the bison mood parser
and the temporary array. Worse, in these cases we also expose the
partially loaded mood via the global current_mood.

The good news is that these errors should be "impossible" to trigger
in practice.

2 years agomp.c: Fix memory leak on parse errors.
Andre Noll [Thu, 10 Mar 2022 21:14:01 +0000 (22:14 +0100)]
mp.c: Fix memory leak on parse errors.

When mp_yyparse() fails we miss to free the abstract syntax tree.

Found by valgrind.

2 years agoserver: Loglevel adjustments for shutdown path.
Andre Noll [Thu, 21 Oct 2021 19:48:24 +0000 (21:48 +0200)]
server: Loglevel adjustments for shutdown path.

The log output of the server is rather verbose with respect to
shutdown messages. These not only occur when the server exits but
also in command handler context each time a command is executed.

This patch quietens these messages in two ways. For some messages we
simply reduce the log level. For others we print the message only in
server context, i.e. when process_is_command_handler() returns false.

2 years agoReject empty mood arguments.
Andre Noll [Fri, 11 Mar 2022 23:42:06 +0000 (00:42 +0100)]
Reject empty mood arguments.

Currently we crash in mood.c due to an assertion.

2 years agoMerge tag 'v0.6.4'
Andre Noll [Tue, 22 Feb 2022 08:17:23 +0000 (09:17 +0100)]
Merge tag 'v0.6.4'

paraslash-0.6.4

2 years agoMerge branch 'refs/heads/t/sha256'
Andre Noll [Mon, 21 Feb 2022 14:52:42 +0000 (15:52 +0100)]
Merge branch 'refs/heads/t/sha256'

A couple of changes which start to eliminate the use of sha1 in favor
of sha256. This series is only the first step, though, as we need to
keep sha1 for the time being to provide backward compatibility.

Cooking for four months.

* refs/heads/t/sha256:
  manual: Avoid sha1.
  upgrade_db: Add copyright and purpose to upgrade_db.c.
  web: Add link to the para_upgrade_db(1) man page.
  afs: Switch to sha256 and change default database path.
  Add para_upgrade_db.
  Use sha256 for the challenge response.
  Introduce hash2 (sha256).
  Assume sideband and aes_ctr128 are always supported/requested.

2 years agoaudiod: Avoid delay in status transition from standby to on.
Andre Noll [Thu, 25 Nov 2021 19:25:43 +0000 (20:25 +0100)]
audiod: Avoid delay in status transition from standby to on.

In close_receiver() we invalidate the current audio format value
to prevent the receiver from re-starting too quickly. See commit
2d61a8005c74 (audiod: Invalidate current audio format on close)
from seven years ago for details.

This invalidation happens in particular when the receiver is closed
because audiod was told to enter standby mode. If audiod is switched
back on shortly thereafter, no receiver can't be started because we
forgot the current audio format and must wait up to one minute until
the next status item dump arrives from the server which re-initializes
the current audio format value.

Fix this flaw by only invalidating the current audio format when
audiod operates in "on" mode.

Fixes: 2d61a8005c74
2 years agoweb: Add horizontal space between table columns.
Andre Noll [Sun, 14 Nov 2021 19:16:01 +0000 (20:16 +0100)]
web: Add horizontal space between table columns.

This tweaks the style sheet to make the rows of the tables easier to
read. It affects the topic list on the development page and the list
of files on the doxygen API page.

2 years agoweb: Clean up style sheet.
Andre Noll [Tue, 9 Nov 2021 17:16:15 +0000 (18:16 +0100)]
web: Clean up style sheet.

This removes some unnecessary cruft. The pages still look as before,
at least in elinks and firefox.

2 years agoweb: Avoid bold face on main page.
Andre Noll [Sun, 7 Nov 2021 22:21:03 +0000 (23:21 +0100)]
web: Avoid bold face on main page.

There is no reason to highlight this particular word.

2 years agoweb: Add padding to all pages.
Andre Noll [Sat, 6 Nov 2021 20:48:32 +0000 (21:48 +0100)]
web: Add padding to all pages.

Wrap text paragraphs in <p>...</p> and increase the margin value for
the html body in the css file. This looks much better in firefox.

No change to the contents.

2 years agoweb: Move navigation into top level table.
Andre Noll [Sat, 6 Nov 2021 20:28:10 +0000 (21:28 +0100)]
web: Move navigation into top level table.

Now the pages no longer look as if they were made in the nineties. More
like 2001 :)

2 years agoweb: Link to "./index.html" rather than to ".".
Andre Noll [Sat, 6 Nov 2021 20:31:59 +0000 (21:31 +0100)]
web: Link to "./index.html" rather than to ".".

When browsing the generated html locally, clicking the logo or the
about link may cause the browser to open the directory view, which
is annoying. This commit makes these links open the main page instead.

2 years agoweb: Remove selected APIs page.
Andre Noll [Sat, 6 Nov 2021 19:43:30 +0000 (20:43 +0100)]
web: Remove selected APIs page.

This list was outdated and not well maintained. Change the link on
the documentation page to point to the list of files instead.

2 years agoweb: Avoid "integrated" in feature list of main page.
Andre Noll [Sun, 14 Nov 2021 19:06:39 +0000 (20:06 +0100)]
web: Avoid "integrated" in feature list of main page.

It's not clear what this is supposed to mean.

2 years agoweb: Shorten slogan.
Andre Noll [Sun, 31 Oct 2021 22:52:02 +0000 (23:52 +0100)]
web: Shorten slogan.

The two removed words do not convey any additional information.

2 years agoweb: The new logo for paraslash-0.7.
Andre Noll [Sun, 31 Oct 2021 22:07:06 +0000 (23:07 +0100)]
web: The new logo for paraslash-0.7.

This new svg logo was not made with a graphical editor but with a
plain text exitor. Unfortunately, ImageMagick is unable to create
a working .ico file from the svg source. Therefore we continue to
carry a manually created .ico file in the repo.

The new logo is less wide than the previous one, and it does not look
nice when it floats to the right side of its tabular cell. Fortunately
this can be fixed by removing some code from the style sheet.

2 years agomanual: Avoid vertical space between coding style items.
Andre Noll [Mon, 8 Nov 2021 10:43:49 +0000 (11:43 +0100)]
manual: Avoid vertical space between coding style items.

For some reason markdown inserts vertical space between adjacent
items if the code example is not enclosed in <pre>...</pre>.

2 years agoMerge branch 'refs/heads/t/rm_v1_moods'
Andre Noll [Thu, 10 Feb 2022 15:34:19 +0000 (16:34 +0100)]
Merge branch 'refs/heads/t/rm_v1_moods'

A single commit which removes a long obsolete feature.

Cooking for almost a year.

* refs/heads/t/rm_v1_moods:
  Remove support for version 1 moods.

2 years agoUpdate copyright year.
Andre Noll [Mon, 3 Jan 2022 19:32:18 +0000 (20:32 +0100)]
Update copyright year.

Happy new year.

2 years agoMerge branch 'refs/heads/t/rm_task_subcmd'
Andre Noll [Mon, 3 Jan 2022 19:18:08 +0000 (20:18 +0100)]
Merge branch 'refs/heads/t/rm_task_subcmd'

A single commit containing an incompatible change for 0.7.0.

Cooking for almost a year.

* refs/heads/t/rm_task_subcmd:
  Remove obsolete server subcommand "task".

2 years agoweb: Add Download link for master tarballs.
Andre Noll [Fri, 3 Dec 2021 15:43:51 +0000 (16:43 +0100)]
web: Add Download link for master tarballs.

This link was deleted by accident when v0.6.2 was released.

2 years agomanual: Avoid sha1.
Andre Noll [Sat, 4 Dec 2021 16:41:34 +0000 (17:41 +0100)]
manual: Avoid sha1.

The section on client-server authentication is no longer accurate
because it depends on the version of client and server whether sha1
or sha256 is used for authentication. Since the hash function is an
implementation detail which should not be mentioned in the manual,
let's avoid the term and talk about cryptographic hash functions
instead.

2 years agoMerge branch 'refs/heads/t/ubsan'
Andre Noll [Sun, 28 Nov 2021 17:10:11 +0000 (18:10 +0100)]
Merge branch 'refs/heads/t/ubsan'

A single patch which adds an option to ./configure to instruct the
compiler to activate its undefined behaviour checker.

Cooking for two months.

* refs/heads/t/ubsan:
  New configure option: --enable-ubsan.

2 years agodaemon: Improve documentation of daemon_set_log_color_or_die().
Andre Noll [Tue, 19 Oct 2021 19:36:54 +0000 (21:36 +0200)]
daemon: Improve documentation of daemon_set_log_color_or_die().

The function receives a severity string, not a log level number.

2 years agoMerge branch 'refs/heads/t/duration-keyword'
Andre Noll [Mon, 22 Nov 2021 13:39:27 +0000 (14:39 +0100)]
Merge branch 'refs/heads/t/duration-keyword'

A single patch which was created already in 2018 but did not propagate
to next and master for no good reason.

Cooking for a month.

* refs/heads/t/duration-keyword:
  mood: Make "duration" a new keyword for the mood grammar.

2 years agoerror.h: Document the error code enumeration.
Andre Noll [Mon, 15 Nov 2021 20:35:25 +0000 (21:35 +0100)]
error.h: Document the error code enumeration.

Doxygen complains about the missing comment.

2 years agocommand.c: Remove unused includes.
Andre Noll [Wed, 20 Oct 2021 21:48:28 +0000 (23:48 +0200)]
command.c: Remove unused includes.

None of these are needed. Tested on Linux, FreeBSD and NetBSD.

2 years agoMerge branch 'refs/heads/t/score-formula'
Andre Noll [Thu, 18 Nov 2021 15:23:20 +0000 (16:23 +0100)]
Merge branch 'refs/heads/t/score-formula'

A single patch which modifies the score function of the audio file
selector to re-scale the two quantities that comprise the score value.

Cooking for six months.

* refs/heads/t/score-formula:
  Rework score formula.

2 years agoMerge branch 'refs/heads/t/list-cleanups'
Andre Noll [Mon, 15 Nov 2021 18:31:41 +0000 (19:31 +0100)]
Merge branch 'refs/heads/t/list-cleanups'

A bunch of simple patches which streamline the macros and inline
functions of list.h which were taken from linux long ago without
adjusting the coding style.

Cooking for three months.

* refs/heads/t/list-cleanups:
  list.h: Convert INIT_LIST_HEAD macro to inline function.
  list.h: Fix parameter doc of iterators.
  list.h: Move list_is_singular() up.
  list.h: Rename argument of list_move().
  list.h: Don't use "new" as an variable name.
  list.h: Open-code LIST_POISON1 and LIST_POISON2.
  list.h: Get rid of internal helpers.
  list.h: Trivial cleanups.
  list.h: Remove unused list_for_each_entry_safe_reverse.

2 years agoi9e: Fix typo: s/ie9/i9e.
Andre Noll [Mon, 18 Oct 2021 20:25:01 +0000 (22:25 +0200)]
i9e: Fix typo: s/ie9/i9e.

It's weird that this was not noticed for so long.

Fixes: e541d7bea7febed8cb9f8a65ae4bd9bdd1b5c8a0
Fixes: 3e3d8e1b48bbd8dbf46adf517c311b5e78dc820f
2 years agoupgrade_db: Add copyright and purpose to upgrade_db.c.
Andre Noll [Tue, 9 Nov 2021 18:11:21 +0000 (19:11 +0100)]
upgrade_db: Add copyright and purpose to upgrade_db.c.

2 years agoRemove unused error code E_OGG_STREAM_FLUSH.
Andre Noll [Sun, 7 Nov 2021 21:39:16 +0000 (22:39 +0100)]
Remove unused error code E_OGG_STREAM_FLUSH.

The last user was removed four years ago.

Fixes: c8466194a4842e319abdedfb38ddc93630e25471
2 years agoweb: Fix typo on documentation page.
Andre Noll [Sun, 7 Nov 2021 15:37:41 +0000 (16:37 +0100)]
web: Fix typo on documentation page.

This typo was introduced four years ago when para_fade was renamed
to para_mixer.

Fixes: 7031f4e380b429e9c0eea1b8e5484dabdbb12ae5
2 years agoMerge branch 'refs/heads/t/writer_improvements'
Andre Noll [Sun, 7 Nov 2021 16:07:24 +0000 (17:07 +0100)]
Merge branch 'refs/heads/t/writer_improvements'

A small set of patches which fix some minor issues, notably a problem
related to the handling of early EOF which affects all paraslash
writers.

* refs/heads/t/writer_improvements:
  alsa_write: Avoid spurious underrun warnings.
  Teach writers to abort gracefully on early EOF.
  alsa_write: Simplify alsa_post_select().

2 years agoweb: Add link to the para_upgrade_db(1) man page.
Andre Noll [Sun, 7 Nov 2021 15:42:50 +0000 (16:42 +0100)]
web: Add link to the para_upgrade_db(1) man page.

Of course this should have been done in the commit which added the
new executable.

Fixes: 56e54c8c75d59a8e5072451941aa56c727d99d26
2 years agoweb: Fix internal link to manual.
Andre Noll [Thu, 4 Nov 2021 20:14:57 +0000 (21:14 +0100)]
web: Fix internal link to manual.

This must have worked at some point...

Looks like it's no good idea to assume that these identifiers are
stable across markdown versions...

2 years agoparaslash 0.6.4
Andre Noll [Thu, 4 Nov 2021 16:15:26 +0000 (17:15 +0100)]
paraslash 0.6.4

Another v0.6 release to mark the destination of the maint branch
which will now be fast-forwarded to this commit. Subsequent merges
of topic branches into master will incorporate incompatible changes,
so from now on the master branch should be regarded as pre-0.7.

2 years agoparaslash 0.6.4 v0.6.4
Andre Noll [Thu, 4 Nov 2021 16:15:26 +0000 (17:15 +0100)]
paraslash 0.6.4

2 years agoMerge branch 'maint'
Andre Noll [Thu, 4 Nov 2021 16:10:34 +0000 (17:10 +0100)]
Merge branch 'maint'

* maint:
  paraslash 0.5.9

2 years agoparaslash 0.5.9
Andre Noll [Thu, 4 Nov 2021 15:56:56 +0000 (16:56 +0100)]
paraslash 0.5.9

A final v0.5-release to record the tip of the maint branch when
paraslash-0.5 became EOL. Shortly after this commit the 0.6.4 release
will be drawn from master, and maint will be fast-forwarded to point
to the v0.6.4 commit.

2 years agocommand.c: Make aux_info_cb() static.
Andre Noll [Thu, 28 Oct 2021 12:44:25 +0000 (14:44 +0200)]
command.c: Make aux_info_cb() static.

It is only used in command.c.

2 years agostring: Remove malloc attribute from para_realloc().
Andre Noll [Tue, 26 Oct 2021 18:19:58 +0000 (20:19 +0200)]
string: Remove malloc attribute from para_realloc().

Quoting from the corresponding section of the gcc-10 manual:

This tells the compiler that a function is 'malloc'-like, i.e.,
that the pointer P returned by the function cannot alias any other
pointer valid when the function returns, and moreover no pointers to
valid objects occur in any storage addressed by P.

Using this attribute can improve optimization. Compiler predicts
that a function with the attribute returns non-null in most cases.
Functions like 'malloc' and 'calloc' have this property because they
return a pointer to uninitialized or zeroed-out storage. However,
functions like 'realloc' do not have this property, as they can return
a pointer to storage containing pointers.

Found by code inspection, the unpached code never caused problems.
Also, the function definition in string.c does not contain the
attribute.

2 years agoalsa_write: Avoid spurious underrun warnings.
Andre Noll [Fri, 27 Aug 2021 13:52:43 +0000 (15:52 +0200)]
alsa_write: Avoid spurious underrun warnings.

Receiving EPIPE does not necessarily mean that an underrun occurred. We
also have to check the pcm state.

2 years agoTeach writers to abort gracefully on early EOF.
Andre Noll [Sun, 5 Sep 2021 18:16:59 +0000 (20:16 +0200)]
Teach writers to abort gracefully on early EOF.

For very short streams it may happen that the receiver and decoder
unregister themselves from the buffer tree before the writer had a
chance to query the information from the decoder which it needs to
open the audio device. This leads to errors such as

Aug 25 14:24:51 schubert (5) get_btr_value: cmd sample_rate: Operation not supported
Aug 25 14:24:51 schubert (5) get_btr_value: cmd channels: Operation not supported
Aug 25 14:24:51 schubert (5) get_btr_value: cmd sample_format: Operation not supported
Aug 25 14:24:51 schubert (4) alsa_init: channels count not available: Invalid argument

This may happen with all receivers, audio formats and writers,
although it is most common with ogg streams.

This commit changes get_btr_sample_rate() and friends to return a
standard error code rather than assuming success. The alsa, ao and
oss writers are patched to check the return value and fail gracefully
if one of these functions fails.

2 years agoalsa_write: Simplify alsa_post_select().
Andre Noll [Sun, 5 Sep 2021 16:57:28 +0000 (18:57 +0200)]
alsa_write: Simplify alsa_post_select().

Clean up the private alsa data structure in alsa_close() and teach
this function to DTRT even if pad->handle is NULL because alsa_init()
failed.

2 years agoafs: Switch to sha256 and change default database path.
Andre Noll [Fri, 13 Mar 2020 18:44:00 +0000 (19:44 +0100)]
afs: Switch to sha256 and change default database path.

This switches the hash column of the audio file table to use sha256
rather than sha1. Due to the preparations implemented in the previous
patches this is a mechanical conversion that could have been performed
by a script.

The only non-trivial thing is the rename of the audio file table
directory, which changes from "audio_files" to "audio-files" because
this is the name the conversion script introduced in the previous
commit picked.

2 years agoAdd para_upgrade_db.
Andre Noll [Fri, 6 Mar 2020 13:26:39 +0000 (14:26 +0100)]
Add para_upgrade_db.

This new executable is required to convert existing paraslash databases
to the new format. Only the layout of the audio file table changes
due to the switch from sha1 to sha256. The command creates and opens
a new audio file table and copies over each row, using an arbitrary
(incorrect) hash value for the values in hash column of the destination
table.

After all rows have been copied in this way, the old table is deleted
and the database directory is renamed from afs-database-0.4 to
afs-database-0.7, which will be the default path in paraslash-0.7.

Subsequent patches will modify para_server to load the database
from the new path and use sha256 instead of sha1 for the hash that
identifies the audio file. The user must then start the thusly patched
para_server and force-add all audio files to correct the hashes. This
approach keeps para_upgrade_db minimal and shortens its running time.

2 years agoUse sha256 for the challenge response.
Andre Noll [Thu, 12 Mar 2020 22:13:17 +0000 (23:13 +0100)]
Use sha256 for the challenge response.

sha1 is broken and should no longer be used. This commit introduces
the new server feature "sha256". It is announced during the handshake
with the client. The client code is patched to detect whether the
server supports the feature and uses sha256 if it does.

This change is backwards compatible. That is, old clients can still
connect to a new server (using sha1). Also new clients can connect
to an old server (and also use sha1 in this case).

2 years agoIntroduce hash2 (sha256).
Andre Noll [Thu, 12 Mar 2020 15:06:12 +0000 (16:06 +0100)]
Introduce hash2 (sha256).

This adds a second hash function which will replace sha1. Both openssl
and libgcrypt support sha256, so it is easy to do. There are no users
of the new functions so far, so this patch has no effect yet.

2 years agoAssume sideband and aes_ctr128 are always supported/requested.
Andre Noll [Thu, 12 Mar 2020 21:08:16 +0000 (22:08 +0100)]
Assume sideband and aes_ctr128 are always supported/requested.

Sideband connections and the AES-based stream cipher have become
mandatory in paraslash-0.6.

The server no longer needs to annouce the feature as 0.6.x clients
request it, regardless of whether it was announced or not. It needs
to still accept the option, though.

On the client side, we don't need to request the features any more
as the server just ignores the request.

2 years agoclient_common: Improve documentation of client_{pre,post}_select().
Andre Noll [Tue, 5 Oct 2021 19:31:06 +0000 (21:31 +0200)]
client_common: Improve documentation of client_{pre,post}_select().

It was outdated and not worded very well. In particular, it referred
to a task pointer although the argument is named "context". Also,
client_open() does not return a "client data structure", so talk
about the effect of that function rather than its return value.

2 years agocompress: Demote log level of clip message.
Andre Noll [Sat, 9 Oct 2021 17:42:52 +0000 (19:42 +0200)]
compress: Demote log level of clip message.

These messages trigger from time to time without having much audible
effect, so they are usually not serious.

2 years agomood: Make "duration" a new keyword for the mood grammar.
Andre Noll [Thu, 30 Aug 2018 20:09:54 +0000 (22:09 +0200)]
mood: Make "duration" a new keyword for the mood grammar.

The new keyword makes it possible to define moods which impose a
constraint on the duration of the admissible files. For example,
the expression

duration < 120 * 1000

selects only files which are shorter than two minutes.

The implementation is pretty simple.

2 years agoRemove ->fd of struct audio file data.
Andre Noll [Sun, 5 Sep 2021 20:38:41 +0000 (22:38 +0200)]
Remove ->fd of struct audio file data.

This structure contains information about the next audio file. It
is stored in a shared memory area, and a reference to this area is
sent through a pipe from the afs process to the server process. The
file descriptor of the next audio file, however, must be passed via
Unix socket magic (SCM_RIGHTS) and thus does not need to be part of
the structure.

Moreover, it's easier to define the afd structure in
open_and_update_audio_file() of aft.c rather than in its caller,
open_next_audio_file() of afs.c, because the caller only needs the
fd of the audio file and the shared memory ID but not the audio file
data structure itself.

Expand the documentation of open_and_update_audio_file() a bit while
at it.

2 years agoaudiod: Use para_malloc().
Andre Noll [Sat, 9 Oct 2021 15:20:06 +0000 (17:20 +0200)]
audiod: Use para_malloc().

If the allocation fails we feed NULL to strncpy(3) which should
result in a segfault. With para_malloc() a clear error message will
be shown instead.

Found by gcc's -fanalyzer option.

2 years agosync_filter: Silence noisy warning.
Andre Noll [Sun, 19 Sep 2021 15:08:40 +0000 (17:08 +0200)]
sync_filter: Silence noisy warning.

It's perfectly fine to fail here due to EOF, so don't print a log
message in this case.

2 years agoafs: Improve error diagnostics if no admissible files are found.
Andre Noll [Sun, 5 Sep 2021 19:36:55 +0000 (21:36 +0200)]
afs: Improve error diagnostics if no admissible files are found.

Currently, the server prints something like the following with
loglevel error:

Sep 05 21:19:42 (4) (31845) open_next_audio_file: key not found in rbtree
Sep 05 21:19:42 (4) (31844) recv_afs_result: afs code: 1, expected: 0
Sep 05 21:19:42 (4) (31844) recv_afs_result: did not receive open fd from afs

This is both cryptic and scary, given that this error is handled by
simply clearing the play bit from the vss status flags.

This commit changes the code to only print one clear log message with
loglevel notice:

Sep 05 21:34:45 (3) (5233) log_statistics: no admissible files

2 years agoplay: Avoid gcc warning when compiling without readline.
Andre Noll [Tue, 28 Sep 2021 20:05:45 +0000 (22:05 +0200)]
play: Avoid gcc warning when compiling without readline.

The EXPORT_PLAY_CMD_HANDLER() macro is only used when READLINE support
is enabled, which leads to

play.c:112: warning: macro "EXPORT_PLAY_CMD_HANDLER" is not used [-Wunused-macros]

Define the macro only when HAVE_READLINE is defined by moving down
the definition to the first user, com_quit().

2 years agoserver: Wait for command handler exit also when afs dies.
Andre Noll [Tue, 21 Sep 2021 12:09:39 +0000 (14:09 +0200)]
server: Wait for command handler exit also when afs dies.

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.

2 years agovss: Avoid double free on exit.
Andre Noll [Mon, 20 Sep 2021 18:42:37 +0000 (20:42 +0200)]
vss: Avoid double free on exit.

When para_server fails to receive the fd for the next audio file,
the memory pointed to by mmd->afd.afhi.chunk_table is freed but the
pointer is not set to NULL. If the failure was due to server and afs
receiving SIGINT, the subsequent signal handling code might attempt
to free the chunk table again. This double free error is detected by
glibc, which results resulting in messages such as

free(): invalid size
Aborted

Fortunately, this is easy to fix.

2 years agovss: Handle empty chunk groups gracefully.
Andre Noll [Mon, 20 Sep 2021 17:15:12 +0000 (19:15 +0200)]
vss: Handle empty chunk groups gracefully.

The assertion in compute_group_size() triggers if the stream is
positioned right at the end of the file when the next chunk group
starts. This was observed with an mp3 file and the udp sender when
pausing and restarting the stream at the end of the file.

Fix this braino by returning EOF instead of aborting if the next
chunk group happens to be empty.

2 years agoupd sender: Don't send FEC EOF from command handler context.
Andre Noll [Mon, 20 Sep 2021 18:28:42 +0000 (20:28 +0200)]
upd sender: Don't send FEC EOF from command handler context.

Without this, the EOF packet might be sent twice: once by the command
handler which stopped the stream and once by the server process. This
does not hurt, but results in additional unnecessary network traffic,
so return early from udp_close_target() when we're running in command
handler context.

2 years agoNew configure option: --enable-ubsan.
Andre Noll [Sat, 15 Jul 2017 12:34:29 +0000 (14:34 +0200)]
New configure option: --enable-ubsan.

If the new option is given, -fsanitize=undefined is passed to the
compiler to enable the undefined behavior detector.

We don't check whether this option is supported because the configure
option is off by default.

2 years agoafh: Avoid memory leak at exit.
Andre Noll [Thu, 26 Aug 2021 17:31:25 +0000 (19:31 +0200)]
afh: Avoid memory leak at exit.

We missed to free the lopsub parse result. This is not a real leak
because it's a one-off allocation and we are about to exit anyway. It's
worth to fix nevertheless, though, because with the patch applied,
valgrind says "no leaks are possible". Hence any other output means
we have introduced a new memory leak.

2 years agoaac_afh: Fix check of return value of mp4ff_meta_update().
Andre Noll [Fri, 13 Aug 2021 19:47:47 +0000 (21:47 +0200)]
aac_afh: Fix check of return value of mp4ff_meta_update().

This function returns zero on failure, and one on success, so the
current check for a negative return value is incorrect. The call to
mp4ff_meta_get_by_index() suffers from the same mistake.

2 years agocom_jmp(): Handle negative values gracefully.
Andre Noll [Sat, 3 Jul 2021 12:36:43 +0000 (14:36 +0200)]
com_jmp(): Handle negative values gracefully.

Currently these get silently converted to a (large) unsigned number,
which causes para_server to skip to the next audio file. This patch
modifies the command handler to check whether the given value is
within range and fails the command if it is out of range.

Remove an uninteresting log message while at it.

2 years agoserver.c: Fix double "the" in comment.
Andre Noll [Sat, 28 Aug 2021 14:43:45 +0000 (16:43 +0200)]
server.c: Fix double "the" in comment.

Found by the vim spell checker.

2 years agoMerge branch 'maint'
Andre Noll [Mon, 30 Aug 2021 18:33:40 +0000 (20:33 +0200)]
Merge branch 'maint'

Just one cherry-picked commit to make the maint branch compile with
newer glibc.

* maint:
  Avoid warning about sys/sysctl.h on glibc-2.30.

2 years agoAvoid warning about sys/sysctl.h on glibc-2.30.
Andre Noll [Tue, 20 Aug 2019 07:10:53 +0000 (09:10 +0200)]
Avoid warning about sys/sysctl.h on glibc-2.30.

From glibc-2.30 NEWS:

The Linux-specific <sys/sysctl.h> header and the sysctl function have
been deprecated and will be removed from a future version of glibc.

Compilation against the glibc-2.30 headers results in the following warning:

In file included from ipc.c:10:
/usr/include/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp]

On NetBSD and FreeBSD, however, we still need to include the header
to get the declaration of sysctlbyname(3).

This patch changes ipc.c to include sys/sysctl.h only if __FreeBSD__ or
__NetBSD__ is defined.  Also remove the pointless check for __APPLE__.

2 years agolist.h: Convert INIT_LIST_HEAD macro to inline function.
Andre Noll [Thu, 20 May 2021 18:38:34 +0000 (20:38 +0200)]
list.h: Convert INIT_LIST_HEAD macro to inline function.

Inline functions are easier to read and write, and we get type
safety.

2 years agolist.h: Fix parameter doc of iterators.
Andre Noll [Thu, 20 May 2021 18:37:44 +0000 (20:37 +0200)]
list.h: Fix parameter doc of iterators.

2 years agolist.h: Move list_is_singular() up.
Andre Noll [Thu, 20 May 2021 18:31:46 +0000 (20:31 +0200)]
list.h: Move list_is_singular() up.

This way all simple inline functions come before the various iterators.

2 years agolist.h: Rename argument of list_move().
Andre Noll [Sat, 15 May 2021 15:30:44 +0000 (17:30 +0200)]
list.h: Rename argument of list_move().

It's only the entry that is moved to a different list, so call the
argument "entry" rather than "list".

2 years agolist.h: Don't use "new" as an variable name.
Andre Noll [Sat, 15 May 2021 15:25:25 +0000 (17:25 +0200)]
list.h: Don't use "new" as an variable name.

vim syntax highlighting trips over it.

2 years agolist.h: Open-code LIST_POISON1 and LIST_POISON2.
Andre Noll [Sat, 15 May 2021 15:22:02 +0000 (17:22 +0200)]
list.h: Open-code LIST_POISON1 and LIST_POISON2.

There is only one user of each.

2 years agolist.h: Get rid of internal helpers.
Andre Noll [Sat, 15 May 2021 15:18:24 +0000 (17:18 +0200)]
list.h: Get rid of internal helpers.

They only obfuscate the code.

2 years agolist.h: Trivial cleanups.
Andre Noll [Sat, 15 May 2021 14:18:44 +0000 (16:18 +0200)]
list.h: Trivial cleanups.

Just whitespace fixes and comment improvements.

2 years agolist.h: Remove unused list_for_each_entry_safe_reverse.
Andre Noll [Sat, 15 May 2021 13:56:06 +0000 (15:56 +0200)]
list.h: Remove unused list_for_each_entry_safe_reverse.

2 years agoplay: Create ~/.paraslash.
Andre Noll [Tue, 25 May 2021 15:10:16 +0000 (17:10 +0200)]
play: Create ~/.paraslash.

Currently para_play won't save its history if this directory does
not exist. This patch makes it create the directory at startup.

2 years agoclient.c: Fix typo in comment.
Andre Noll [Thu, 27 May 2021 14:59:10 +0000 (16:59 +0200)]
client.c: Fix typo in comment.

2 years agomanual: Fix package name of flac library.
Andre Noll [Tue, 25 May 2021 15:09:17 +0000 (17:09 +0200)]
manual: Fix package name of flac library.

These days it is spellt lower case. Also realpath is not a separate
package anymore, so drop that.

2 years agoUpdate copyright year.
Andre Noll [Tue, 25 May 2021 15:08:30 +0000 (17:08 +0200)]
Update copyright year.

2 years agoINSTALL: Fix instructions for compiling from git.
Andre Noll [Tue, 25 May 2021 15:07:43 +0000 (17:07 +0200)]
INSTALL: Fix instructions for compiling from git.

The command line lacked the configure command.

2 years agoRework score formula.
Andre Noll [Mon, 25 Nov 2019 20:22:35 +0000 (21:22 +0100)]
Rework score formula.

Currently the two scales for the num_played and the last_played
components of the score value are computed independently of each
other. There is, however, a natural link between the two scales:
a file with best possible num_played value (zero) and worst possible
last_played value (now) should receive the average score zero.

This patch employs this idea to rescale the two components. See the
new comment to compute_score() for details about the implementation.

2 years agoserver: Don't crash on blank moods.
Andre Noll [Thu, 6 May 2021 18:29:06 +0000 (20:29 +0200)]
server: Don't crash on blank moods.

We special-case empty mood definitions (because we can't map the
osl object anyway), but we don't check whether the mood definition
contains anything else than whitespace or comments.

Such blank mood definitions result in an empty abstract syntax tree
indicated by ->ast of the mood parser's context structure being
NULL. We happily dereference that pointer in mp_eval_row() and die
by the resulting SIGSEGV.

The fix is trivial: simply treat blank moods in the same way as the
dummy mood, i.e. regard each audio file as admissible.

2 years agoaft: Silence format-overflow warning with gcc-10.
Andre Noll [Wed, 28 Apr 2021 11:17:03 +0000 (13:17 +0200)]
aft: Silence format-overflow warning with gcc-10.

aft.c: In function 'print_list_item':
aft.c:736:17: warning: '%*u' directive writing between 1 and 65529 bytes into a region of size 30 [-Wformat-overflow=]
  736 |   sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins,
      |                 ^~~
aft.c:736:16: note: directive argument in the range [1, 4294967295]
  736 |   sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins,
      |                ^~~~~~~~~~~~~~~
aft.c:736:16: note: directive argument in the range [-59, 59]
aft.c:736:3: note: 'sprintf' output between 8 and 65545 bytes into a destination of size 30
  736 |   sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins,
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  737 |    seconds % 60);
      |    ~~~~~~~~~~~~~

The code is correct but gcc can't prove it. Silence the warning by
passing the size of the buffer and asserting that it won't overflow
before printing to it.

3 years agomanual: Fix dead audiocoding.com link.
Andre Noll [Thu, 8 Apr 2021 15:12:02 +0000 (17:12 +0200)]
manual: Fix dead audiocoding.com link.

As pointed out by Sven, audiocoding.com has been out of service and
shut down the website since August of 2020. The library is still
available for download on the sourceforge project page, so link to
that page instead.

Reported-by: Sven <sven.videoproc@gmail.com>
3 years agoprebuffer: Remove buffer tree node on errors.
Andre Noll [Mon, 5 Apr 2021 18:29:28 +0000 (20:29 +0200)]
prebuffer: Remove buffer tree node on errors.

When the ->post_select method of a filter returns negative, it *must*
remove its buffer tree node as well. The prebuffer missed to do that,
which results in a stale reference to the buffer tree which keeps
the audiod slot busy. When no more slots are free, audiod hangs or
exits with a "no more free slots" message. This patch avoids this.

3 years agoRemove obsolete server subcommand "task".
Andre Noll [Tue, 17 Mar 2020 17:28:45 +0000 (18:28 +0100)]
Remove obsolete server subcommand "task".

It was deprecated long ago. Since v0.6.2 it does nothing anyway.

3 years agoRemove support for version 1 moods.
Andre Noll [Mon, 16 Mar 2020 18:30:55 +0000 (19:30 +0100)]
Remove support for version 1 moods.

Version 2 moods were introduced in v0.6.1 which was released more
than three years ago. Since then the older version 1 moods have
been deprecated. This commit gets rid of them removing quite some
questionable and unmaintained code.