Commit Graph
66 Commits
Author SHA1 Message Date
Belbo b98e6a9ac0 Fixed race condition when stopping other threads with SIGUSR1
Many threads have a main loop that checks some exit variable in the loop condition. To stop a thread, another thread sets that exit variable, sends a SIGUSR1 to that thread to get it out of blocking calls like read(), write() or select(), and finally joins it.

There was a race condition though: if the signal arrived after the loop condition was checked but before the blocking system function was entered, the target thread essentially ignored the signal, made the blocking call anyway, and could get stuck forever there.

The only way around this race condition is to block SIGUSR1 in the destination thread during the critical time interval. This requires that the blocking system call and the call to unblock SIGUSR1 be an atomic unit. There is only one system call that makes this possible: pselect(), which takes a signal mask to replace the current signal mask with, but only while pselect() runs. Other functions like read(), recv(), write() and sendto() may only be called if we can be sure that they don't block. For this purpose, the file descriptors must be set to non-blocking mode and we must prepend the call to them with a call to pselect() to block until the socket becomes readable/writable.
2017-11-01 20:46:05 +01:00
Belbo 3e54765193 Fixed loop condition in non_blocking_write()
The while loop should be repeated, if the last write attempt was a partial write only. In this case, however, rc is greater than 0 (should be 1), not equal to 0.
2017-10-31 23:19:22 +01:00
Belbo 19ff6042cf Prevent buffer overflow in log functions
die(), warn(), debug() and inform() write the string into a limited internal buffer first. They now use vsnprintf() instead of vsprintf() to prevent an overflow of that buffer.
2017-10-31 23:19:21 +01:00
Mike Brady 3001f39bc5 3.1.2 pretty-print using clang-format 2017-09-07 12:02:00 +01:00
Mike Brady 48c1d3eb20 Add fixes suggested by using "infer" 2017-09-03 22:46:57 +01:00
Mike Brady 31a09bb368 Fix some silent issues that were highlighted by "infer" 2017-09-03 15:08:13 +01:00
Mike Brady d3148eb464 Improve handling of player lock and simplify handling of loss of connection and improve some debug messages 2017-08-27 12:43:42 +01:00
Mike Brady e513e5330c Tidy up source using clang-format 2017-07-31 11:57:57 +02:00
Cody Cutrer 3e9e228564 read stdout from the on-start command to choose ALSA output device
refs GH-452
2017-06-24 19:46:03 -06:00
Mike Brady e37c277b0a Add a "run_this_when_volume_is_set" facility to call a program when the volume is set. The AirPlay volume is passed. 2017-04-23 12:37:11 +01:00
Mike Brady a53b4c5c36 Fix some warnings from clang on FreeBSD. One was significant -- the randarray stuff didn't look right. 2017-04-16 16:52:43 +01:00
Tobias Kortkamp c9e378f515 FreeBSD doesn't have ETIME but both FreeBSD and Linux know ETIMEDOUT 2017-04-15 02:28:57 +02:00
Mike Brady 5855264eff Improve error reporting in non-blocking write code 2017-04-07 18:45:28 +01:00
Yann Pomarede 2ab2a84c14 change function die, warn, inform and debug
change funcions die, warn, inform and debug argument from `char*` to `const char*` to prevent a warning in C==
2017-02-28 12:47:03 +01:00
Mike Brady cf29625d2c Clang Format 2017-02-11 12:12:07 +00:00
Mike Brady 2a4a4ed22b Add volume_max_db setting which works on the hw mixer if it exists or the sw attenuator otherwise. 2017-02-05 16:18:05 +00:00
Mike Brady 0764199545 Add possibility of using an array of precalculated pseudo random numbers to reduce processor load. 2017-01-30 18:34:09 +00:00
Mike Brady 62aaf07478 Add support for mbed TLS and deprecate polarssl support 2017-01-30 08:21:12 +00:00
Mike Brady 064bd293c5 Tidy up with a clang-format 2016-09-11 10:35:53 +01:00
Mike Brady 8d008fa2ec Begin to add full-scale post processing. Does not compile. 2016-09-08 15:56:22 +01:00
Mike Brady 4849c1d429 Remove mersenne generator -- too slow, try another one 2016-09-07 16:55:14 +01:00
Mike Brady 945483d9c3 Merge support of apple's ALAC decoder 2016-08-28 21:38:24 +01:00
Mike Brady 1fe705cf5f Remove variable delay from non_blocking_write and include it whether metadata is enabled or not. Remove the INSTALL file and ignroe it in git. 2016-06-26 15:20:09 +01:00
Mike Brady a1b975106a Quieten some debug messages. 2016-05-26 08:28:06 +01:00
Mike Brady fd336f45c4 Merge pull request #314 from joerg-krause/development
Fix build without metadata support
2016-05-23 23:11:00 +01:00
Mike Brady e5c6ea8b29 Add some diagnostics to non_blocking_write/3. 2016-05-23 21:10:15 +01:00
Jörg Krause 28efe16f73 Fix build without metadata support
Commit f36352dc4e introduced the parameter
pipe_timeout for the metadata config. If shairport-sync is now configured
without metadata support, the build fails with:

```
shairport.c: In function ‘main’:
shairport.c:766:9: error: ‘shairport_cfg {aka struct <anonymous>}’ has no member named ‘metadata_pipe_timeout’
   config.metadata_pipe_timeout = 5000; //milliseconds

```

Fix this by opting-out the affected code with CONFIG_METADATA.
2016-05-23 22:01:46 +02:00
Mike Brady 870de08db5 Add a little extra diagnostic to nno-blocking write 2016-05-23 16:43:02 +01:00
Mike Brady f36352dc4e Add setting for the time to wait for the metadata pipe to come ready, otherwise give up. Default 5,000 milliseconds. 2016-05-23 14:03:38 +01:00
Mike Brady 5f6f4a2636 replace the nonblocking write code 2016-05-23 11:58:22 +01:00
Mike Brady 46fac92f6c Add a utility for string substitution, rename apname to service_name 2016-05-21 13:05:15 +01:00
Jörg Krause f230e3e543 Fix vol2attn
This fixes calculation of the scaled attenuation if `max_dB` is different from
zero.

Closes: https://github.com/mikebrady/shairport-sync/issues/290
2016-05-09 15:10:37 +02:00
Mike Brady d02bb0e336 If the volume is out of range 0 -- -30 or -144, return minimum vol 2016-04-27 10:23:15 +02:00
Mike Brady e3986855dd Add type check comment. 2016-03-26 21:36:40 +00:00
Mke Brady 3b88d05137 Add CYGWIN flag check to be recognised as Posix-enough (?) 2015-10-21 10:22:56 +01:00
Mike Brady 1b52e26f8f Move non-blocking-write code here from rtsp.c 2015-08-06 14:30:44 +02:00
Mike Brady 670dd933a2 Use the renamed linux compilation flag renamed to include the word freebsd 2015-08-01 14:36:42 +02:00
Mike Brady cc4d9ece42 Revert back to CLOCK_MONOTONIC from CLOCK_MONOTONIC_RAW because OpenWrt doesn't recognise it 2015-07-02 15:17:36 +01:00
Mike Brady 8892561917 Use CLOCK_MONOTONIC_RAW for better timing estimation 2015-06-29 09:08:58 +00:00
Mike Brady 129a4dc568 Add declaration file of waitpid 2015-06-28 15:37:22 +01:00
Mke Brady 87a0475c16 Reformat using clang-format. 2015-06-01 23:16:50 +01:00
Mike Brady c2383d4942 Fix flush glitch, add artwork request to metadata set. 2015-03-18 21:02:49 +00:00
Mke Brady a6f156cfc0 Adjust the volume transfer function to be a bit steeper in mid to high volume 2015-03-16 21:11:04 +00:00
Mike Brady a2790fc102 Improve metadata output -- maybe it works reliably now. Add call to get audio parameters from back ends, to be able to give volume metadata. 2015-03-16 11:11:54 +00:00
Mike Brady 705a0be1e4 Add new optioons --statistics to print out the, um, statistics, and remove them from debug level 1. 2014-11-21 17:39:27 +00:00
Mke Brady eef08e4975 Change SIGUSR2 to turn on and off reserving the output device. 2014-10-19 16:43:59 +01:00
Mike Brady dc360d45c3 Adjust slope of volume control to be a bit faster at the lower end -- diagrams not updated. 2014-09-16 12:50:30 +01:00
Mike Brady 8548cdc67d Modify the volume control profile to make the lower range slower to progress -- seems smoother overall on a 120db (nominal) device. 2014-09-15 21:12:59 +01:00
Mike Brady 0733e962bb rename absolute_time_in_ns to absolute_time_in_fp (more accurate name). Fix osx timing calculation. 2014-09-07 12:31:23 +01:00
Mke Brady 3466530c9e Use popt library to allow on-start and on-stop commands to have arguments 2014-09-01 22:00:19 +01:00