paraslash.git
12 years agosc_send_result(): Error out on short writes.
Andre Noll [Sun, 11 Dec 2011 19:23:14 +0000 (20:23 +0100)]
sc_send_result(): Error out on short writes.

This affects only afs command handlers, where short writes should
never happen as the socket fd is set to blocking mode. But still.

12 years agoafh: Use write_all rather than plain write().
Andre Noll [Sun, 11 Dec 2011 19:21:53 +0000 (20:21 +0100)]
afh: Use write_all rather than plain write().

We are currently using plain write() to write out the audio
file header. If this results in a short write, or if the write
is interrupted, we should just try again. So it's safer to call
write_all() here.

12 years agofd: Let write_all() return an error on short writes.
Andre Noll [Sun, 11 Dec 2011 20:12:13 +0000 (21:12 +0100)]
fd: Let write_all() return an error on short writes.

Short writes are often ignored because most callers of write_all()
do not check the return value. Rather than fixing all callers, this
patch teaches write_all() to detect short writes and return the new
E_SHORT_WRITE error code in this case.

Currently write_all() is a wrapper for write(), similar to
write_nonblock() but lacking the safety checks of the latter. To get
these safety checks, write_all() is changed to call write_nonblock().

Unfortunately, this involves some code movement.

12 years agofd: Improve error handling of write_nonblock().
Andre Noll [Sun, 11 Dec 2011 18:48:56 +0000 (19:48 +0100)]
fd: Improve error handling of write_nonblock().

This function had two shortcomings: First, a call to write might
fail with errno set to EINTR in case the write call was interrupted
before any data was written. This is not fatal and one should just
retry the write in this case.

Secondly, POSIX allows to return either EAGAIN or EWOULDBLOCK if the
write would block but we only check for EAGAIN. This is no problem on
Linux since both constants refer to the same value on Linux. However,
POSIX does not require them to be equal, so we have to check for both.

This patch corrects both issues.

12 years agoMove send_buffer() and send_va_buffer() from net.c to fd.c.
Andre Noll [Tue, 6 Dec 2011 20:07:56 +0000 (21:07 +0100)]
Move send_buffer() and send_va_buffer() from net.c to fd.c.

These functions end up calling plain write(), hence they work on
arbitrary file descriptors, not just network sockets. So they really
belong to fd.c rather than to net.c. Rename the two functions to
write_buffer() and write_va_buffer().

12 years agoRemove send_bin_buffer().
Andre Noll [Tue, 6 Dec 2011 19:50:29 +0000 (20:50 +0100)]
Remove send_bin_buffer().

It is just a trivial wrapper for write_all(). This patch changes all
callers to use write_all() directly and removes the wrapper.

12 years agofd: Make write_all() receive the length by value.
Andre Noll [Tue, 6 Dec 2011 19:46:17 +0000 (20:46 +0100)]
fd: Make write_all() receive the length by value.

Not a single caller actually checked the value of the passed
len pointer after the call, which is a sure sign for a bad API.
Just return the number of bytes written.

12 years agoFix two minor documentation issues.
Andre Noll [Thu, 19 Jan 2012 21:37:24 +0000 (22:37 +0100)]
Fix two minor documentation issues.

12 years agolsatt: Do not print "no matches" message unconditionally.
Andre Noll [Fri, 20 Jan 2012 21:42:39 +0000 (22:42 +0100)]
lsatt: Do not print "no matches" message unconditionally.

com_lsatt() needs to know if output has been sent to the client in
order to decide whether it should print the "no matches" error message.
Currently this message is printed if at least one argument was given
and send_callback_request() returned zero.

However, send_callback_request() returns zero on success and negative
on errors. Hence, if at least one argument was given, the error
message is printed regardless of whether there was a match.

Fix this bug by changing send_callback_request() to return the number
of received shared memory areas on success.

12 years agocommand.c: Fix typo in comment.
Andre Noll [Sun, 15 Jan 2012 16:13:33 +0000 (17:13 +0100)]
command.c: Fix typo in comment.

12 years agoFix typo in audiod man page.
Andre Noll [Tue, 10 Jan 2012 18:56:39 +0000 (19:56 +0100)]
Fix typo in audiod man page.

12 years agoMerge branch 't/web_fix'
Andre Noll [Tue, 10 Jan 2012 18:43:25 +0000 (19:43 +0100)]
Merge branch 't/web_fix'

12 years agoChange year in copyright message to 2012.
Andre Noll [Sat, 7 Jan 2012 01:34:18 +0000 (02:34 +0100)]
Change year in copyright message to 2012.

12 years agoMake web pages conform to the HTML standard again.
Andre Noll [Fri, 6 Jan 2012 06:56:56 +0000 (07:56 +0100)]
Make web pages conform to the HTML standard again.

Without this fix, the w3c validator complains about end tags for
element <p> which is not open. Removing both start and end tags makes
it happy again and causes no visible change, at least in one browser.

12 years agoafh/audioc: Explicitly mark STDOUT as blocking.
Andre Noll [Tue, 6 Dec 2011 17:17:57 +0000 (18:17 +0100)]
afh/audioc: Explicitly mark STDOUT as blocking.

STDOUT_FILENO is usually set to blocking mode, but as we rely on this,
it is safer to clear the nonblock flag explicitly.

12 years agocom_init(): Return proper error code.
Andre Noll [Sun, 11 Dec 2011 19:24:53 +0000 (20:24 +0100)]
com_init(): Return proper error code.

If an error occurred during database initialization, we send an error
message to the client.  However, it this fails, we currently log
the send error rather than the error that caused that initialization
to fail. Fix this by logging the root cause of the problem instead.

12 years agoaudiod: Fix bug in status_pre_select().
Andre Noll [Fri, 23 Dec 2011 20:51:00 +0000 (21:51 +0100)]
audiod: Fix bug in status_pre_select().

We have to take the minimum input size into account when deciding
whether a minimal delay should be requested from the scheduler.
Without this, a busy loop is possible.

12 years agoMerge remote-tracking branch 's/master'
Andre Noll [Sat, 24 Dec 2011 17:30:07 +0000 (18:30 +0100)]
Merge remote-tracking branch 's/master'

12 years agosend: Make ->send_fec() return void.
Andre Noll [Mon, 5 Dec 2011 20:04:02 +0000 (21:04 +0100)]
send: Make ->send_fec() return void.

There is only one caller, vss_send(), which ignores the return value.
So there is no point in returning an error code from this method.

12 years agoAlways include stdbool.h.
Andre Noll [Sat, 3 Dec 2011 16:38:11 +0000 (17:38 +0100)]
Always include stdbool.h.

This adds the #include statement for stdbool.h to para.h. This allows
to get rid of the individual includes in *.c.

More importantly, since all *.c files include para.h, booleans will
now be available everywhere so that we won't need to touch dozens of
files anymore whenever a boolean is added to a public structure.

12 years agoweb: Fix year in release announcement.
Andre Noll [Tue, 6 Dec 2011 18:55:13 +0000 (19:55 +0100)]
web: Fix year in release announcement.

12 years agonew codename, reset version to git
Andre Noll [Tue, 6 Dec 2011 16:37:35 +0000 (17:37 +0100)]
new codename, reset version to git

12 years agothe paraslash-0.4.9 release tarball
Andre Noll [Tue, 6 Dec 2011 16:33:10 +0000 (17:33 +0100)]
the paraslash-0.4.9 release tarball

12 years agoparaslash 0.4.9 v0.4.9
Andre Noll [Tue, 6 Dec 2011 16:29:16 +0000 (17:29 +0100)]
paraslash 0.4.9

12 years agoMerge branch 't/interactive'
Andre Noll [Sun, 4 Dec 2011 23:13:32 +0000 (00:13 +0100)]
Merge branch 't/interactive'

Conflicts:
string.h

12 years agoMerge branch 't/flac'
Andre Noll [Tue, 29 Nov 2011 07:36:49 +0000 (08:36 +0100)]
Merge branch 't/flac'

12 years agoMerge branch 't/generic_match_count'
Andre Noll [Fri, 25 Nov 2011 12:13:35 +0000 (13:13 +0100)]
Merge branch 't/generic_match_count'

12 years agoDocument interactive sessions and add link to libreadline.
Andre Noll [Fri, 9 Sep 2011 16:29:25 +0000 (18:29 +0200)]
Document interactive sessions and add link to libreadline.

12 years agoRewrite bash completion.
Andre Noll [Thu, 8 Sep 2011 23:58:35 +0000 (01:58 +0200)]
Rewrite bash completion.

Now that para_client and para_audioc gained the --completion option for
completing a partially entered command line, we can use this feature
in the bash completion script. This allows to avoid duplicating the
available commands in the completion script.

12 years agoInteractive mode for para_audioc.
Andre Noll [Mon, 5 Sep 2011 18:46:06 +0000 (20:46 +0200)]
Interactive mode for para_audioc.

This is in the same spirit as the previous commit which added
interactive session support for para_client. It implements command
completion and command line history for para_audioc.

Just as for para_client the new completion code in audioc.c is
compiled in only if libreadline was found by configure. In this case
para_audioc starts an interactive session if no command was given at
the command line.

12 years agoclient: Implement interactive mode.
Andre Noll [Mon, 5 Sep 2011 13:47:34 +0000 (15:47 +0200)]
client: Implement interactive mode.

This makes para_client enter an interactive session when started with no
command. Command line history and command completion are available in
interactive sessions.

This populates the previously empty files interactive.h and interactive.c which
contain the readline/interactive specific part. Everything in these files is
independent of para_client.  Conversely, client.c and client_common.c are
independent of readline.

The public API defined in interactive.h was designed to be reused from other
applications. In fact, a subsequent commit changes para_audioc to offer
interactive sessions as well.

12 years agostring: Introduce compute_word_num().
Andre Noll [Sun, 28 Aug 2011 21:36:17 +0000 (23:36 +0200)]
string: Introduce compute_word_num().

The completion code needs to determine the word the curser is
currently on.  Libreadline only provides the start and end position
of the current word in the line buffer, but not the word number.

This patch adds compute_word_num() to string.c which uses the same
algorithm as create_argv() to determine the word boundaries.

12 years agoconfigure: Introduce checks for libreadline.
Andre Noll [Thu, 25 Aug 2011 19:53:42 +0000 (21:53 +0200)]
configure: Introduce checks for libreadline.

This adds interactive.o to the object list of para_client if readline
was found and links para_client against libreadline in this case.

The new source files interactive.c and interactive.h are empty for now.

12 years agoclient: Split client_open() and client_close().
Andre Noll [Sun, 4 Sep 2011 16:41:40 +0000 (18:41 +0200)]
client: Split client_open() and client_close().

For interactive para_client sessions, we set up the client
configuration from the values given at the command line and in the
config file just as we do for non-interactive mode. However, in
interactive mode we must be able to execute arbitrary many client
commands using the same configuration. client_open() sets up the
configuration from the command line arguments and client_close()
destroys the configuration, so both functions do more than what is
needed in interactive mode.

This patch splits client_open() into two functions
client_parse_config() and client_connect(). The old client_open()
remains with the same semantics as before, it just calls both of the
new functions().

In the same spirit, client_close() is split into client_disconnect(),
which closes the file descriptor and deallocates the ressources of
the current command but does not free the configuration.

This allows to re-use the client configuration multiple times for
interactive sessions.

12 years agosched: Allow more than one running scheduler instance.
Andre Noll [Fri, 2 Sep 2011 16:27:29 +0000 (18:27 +0200)]
sched: Allow more than one running scheduler instance.

The interactive completion code must be able to run a second,
independent scheduler instance for generating the possible completions.
This is currently not possible because the pre_select and post_select
list heads of the scheduler are defined globally in sched.c.

This patch moves these list heads from sched.c to struct sched. This
leaves only the global "now" variable in sched.c, but it is OK to
update this from all scheduler instances, so it can stay.

Moving the two list heads to struct sched requires that several
public functions, among them register_task(), grow an additional
parameter. The (mostly trivial) changes that update all callers to
provide the new argument make the patch rather invasive, unfortunately.

12 years agoTeach command_util to print also completions.
Andre Noll [Sun, 28 Aug 2011 04:34:55 +0000 (06:34 +0200)]
Teach command_util to print also completions.

This adds completion mode to command_util.sh. When exectuted in this
mode, it prints array initializers for all supported commands. This
will be used to generate the array of completers for para_client and
para_audiod.

12 years agoAllow switching between different log methods at runtime.
Andre Noll [Mon, 29 Aug 2011 17:17:38 +0000 (19:17 +0200)]
Allow switching between different log methods at runtime.

Currently, para_client defines its para_log function via the
INIT_STDERR_LOGGING() macro which generates a log function that
writes to stderr. However, we will need to switch to a different,
curses-aware logging function when operating in interactive mode.

To support more than one log method the type of para_log is changed
from a function to a (public) pointer variable. This variable is
supposed to point to the log function currently in use so that the
application can simply set para_log differently in order to switch
between log functions.

The patch also changes the INIT_STDERR_LOGGING() macro to receive the
name of the log function to be defined and to let para_log point to
the newly defined function.

12 years agocommand_util: Fix quoting in template_loop().
Andre Noll [Sun, 30 Oct 2011 11:54:32 +0000 (12:54 +0100)]
command_util: Fix quoting in template_loop().

Without this additional quoting, the command usage string is incorrect
in case the template contains square brackets. For example, the usage
of the lsblob commands was printed as

Usage: lspl [-i] [-l] [-r] t

rather than the desired

Usage: lspl [-i] [-l] [-r] [pattern]

because the command "echo [pattern]" prints "t" since there is a
subdirectory called "t" in the source tree.

12 years agoMerge branch 't/recv_improvements'
Andre Noll [Sun, 20 Nov 2011 14:05:15 +0000 (15:05 +0100)]
Merge branch 't/recv_improvements'

12 years agoCompilation fix for FreeBSD.
Andre Noll [Thu, 17 Nov 2011 09:27:30 +0000 (10:27 +0100)]
Compilation fix for FreeBSD.

Commit 25ca796b (daemon: Introduce parent_waits flag for
daemonize().) broke the compilation on FreeBSD due to signal.h not
being included. This patch adds the missing include.

12 years agoMerge branch 't/makefile_cleanups'
Andre Noll [Wed, 16 Nov 2011 10:28:33 +0000 (11:28 +0100)]
Merge branch 't/makefile_cleanups'

12 years agodoc: Add flac documentation to manual and FEATURES.
Andre Noll [Sat, 6 Aug 2011 15:10:20 +0000 (17:10 +0200)]
doc: Add flac documentation to manual and FEATURES.

12 years agoImplement the flac decoding filter.
Andre Noll [Wed, 3 Aug 2011 22:52:48 +0000 (00:52 +0200)]
Implement the flac decoding filter.

This replaces the dummy functions in flacdec_filter.c by a working
implementation. Although it contains an ugly workaround for a
shortcoming in the flac library, see the comment in read_cb() for
details, it seems to work fine.

12 years agoImplement the flac audio format handler.
Andre Noll [Wed, 28 Sep 2011 20:55:07 +0000 (22:55 +0200)]
Implement the flac audio format handler.

This adds another audio format to para_server and para_afh. Since
meta data tags flac are essentially vorbis comments, they are fully
supported. However, the audio format handler accepts only flac
files with fixed block size, and ogg/flac is not supported either at
this point.

12 years agoInitial support for FLAC (the free lossless audio codec).
Andre Noll [Sun, 31 Jul 2011 22:39:54 +0000 (00:39 +0200)]
Initial support for FLAC (the free lossless audio codec).

This adds tests for flac headers and libraries to configure.ac and
adds configure options to override the default location of these files.

Moreover, a (non-working) implementation of the flac audio format
handler and the flac decoder are introduced. All new functions are
defined as empty dummies to be filled with content in subsequent
commits.

12 years agobtr: Introduce btr_next_buffer_omit().
Andre Noll [Tue, 9 Aug 2011 18:00:12 +0000 (20:00 +0200)]
btr: Introduce btr_next_buffer_omit().

This function is useful for the flac decoder.

12 years agoMake vorbis comment helper functions generic.
Andre Noll [Sun, 31 Jul 2011 23:08:20 +0000 (01:08 +0200)]
Make vorbis comment helper functions generic.

copy_comment() and copy_if_tag_type() are useful also to the new flac
audio format handler, so move these functions to string.c and make
them public.

Rename them to safe_strdup() and key_value_copy() respectively,
as this is more to the point.

12 years agoCalculate width of audio formats in ls output.
Andre Noll [Mon, 1 Aug 2011 22:22:58 +0000 (00:22 +0200)]
Calculate width of audio formats in ls output.

Currently the field width for the audio format is hard-coded as three
as the name of each supported audio format (mp3, ogg, aac, wma, spx)
consists of three characters.

However, with the forthcoming flac support, this is no longer true
since "flac" consists of four characters. So the ls command must
calculate the maximal field width of the audio formats of all listed
files.

This is achieved by introducing the new audio_format_width member of
struct ls_widths.

12 years agostdin: Increase input buffer.
Andre Noll [Mon, 3 Oct 2011 18:45:09 +0000 (20:45 +0200)]
stdin: Increase input buffer.

Some flac files may contain the contain arbitrary large metadata
at the beginning and libflac wants to see this data in one go.
128K should be enough for most cases.

12 years agodaemon: Introduce parent_waits flag for daemonize().
Andre Noll [Sat, 12 Nov 2011 13:37:01 +0000 (14:37 +0100)]
daemon: Introduce parent_waits flag for daemonize().

In daemon mode, para_server should not detach from the console
until it is listening on its command socket. The previous approach
turned out to be buggy and has been reverted in the previous commit.

This second attempt tries to get it right. It adds a boolean parameter
"parent_waits" to daemonize(). After daemonize() has forked, the
parent process does not exit immediately if parent_waits is true but
waits until the child process sends SIGTERM to its parent, or exits.

para_server makes use of the new flag in server_init(). The daemon
process (child) sends SIGTERM to its parent after the command socket
has been initialized. para_audiod, on the other hand, does not need
this feature, so it calls daemonize() with parent_waits == false to
get the old behaviour.

12 years agoRevert "server: Listen on command socket before daemonizing."
Andre Noll [Fri, 11 Nov 2011 20:50:56 +0000 (21:50 +0100)]
Revert "server: Listen on command socket before daemonizing."

This reverts commit 7a4b6d5f19976ceac581f6dc235fcbd9b30c767f, which
was a rather bad idea because it caused the afs process to inherit
the open file descriptor of the command socket, so two processes
listened on the command socket at the same time.

Even worse, the afs process also inherited the command task in its
scheduler setup, causing it to answer incoming connections as well.
In fact it was more or less random which of the two processes served
an incoming connection.

If it was the afs process, interesting things happened in the command
handler due to its address space being a copy of the afs process,
where parts of what is needed for some commands not properly set
up. For example the si and the sender commands segfaulted due to a
NULL pointer dereference.

It's weird that this bug was not noticed earlier.

12 years agovss: Avoid read-overflowing the header buffer for ogg streams.
Andre Noll [Thu, 10 Nov 2011 08:22:25 +0000 (09:22 +0100)]
vss: Avoid read-overflowing the header buffer for ogg streams.

valgrind complains because of invalid reads/writes in vss.c:

==998== Invalid write of size 1
==998==    at 0x8050B09: vss_post_select (vss.c:574)
==998==    by 0x806106C: schedule (sched.c:71)
==998==    by 0x804EE04: main (server.c:579)
==998==  Address 0x46d99bc is 0 bytes after a block of size 548 alloc'd
==998==    at 0x4028A3B: realloc (vg_replace_malloc.c:632)
==998==    by 0x805356B: para_realloc (string.c:40)
==998==    by 0x80506EC: vss_post_select (vss.c:331)
==998==    by 0x806106C: schedule (sched.c:71)
==998==    by 0x804EE04: main (server.c:579)
==998==

...

==5543== Invalid read of size 1
==5543==    at 0x8050EBD: vss_post_select (vss.c:1099)
==5543==    by 0x806108E: schedule (sched.c:71)
==5543==    by 0x804EE04: main (server.c:579)
==5543==  Address 0x47c70ac is 0 bytes after a block of size 3,956 alloc'd
==5543==    at 0x4028A3B: realloc (vg_replace_malloc.c:632)
==5543==    by 0x805358D: para_realloc (string.c:40)
==5543==    by 0x80642AA: add_ogg_page (ogg_afh.c:78)
==5543==    by 0x8064458: vorbis_get_header_callback (ogg_afh.c:132)
==5543==    by 0x8063EF1: process_ogg_packets (ogg_afh_common.c:48)
==5543==    by 0x8063F9A: ogg_get_file_info (ogg_afh_common.c:144)
==5543==    by 0x8064200: vorbis_get_header (ogg_afh.c:149)
==5543==    by 0x804FDD9: recv_afs_result (vss.c:1006)
==5543==    by 0x80503F4: vss_post_select (vss.c:1124)
==5543==    by 0x806108E: schedule (sched.c:71)
==5543==    by 0x804EE04: main (server.c:579)

The problem is that for ogg streams chunk 0 points to a buffer on
the heap rather than to the mapped audio file, but we are checking
the buffer bounds against the memory map.

The fix consists of two parts. (a) We now treat a FEC group special
if it starts at chunk zero: Such a group now contains only this single
chunk. (b) When setting up the FEC group we always compare the buffer
bounds against the start of the first buffer in the group rather than
the memory map.

12 years agovss: Don't prefault header.
Andre Noll [Thu, 10 Nov 2011 09:14:21 +0000 (10:14 +0100)]
vss: Don't prefault header.

Commit 7bba6232 (vss: Mmap audio files using MAP_POPULATE.) introduced
read-ahead for chunks of the mmapped audio file. However, it missed
the fact that for ogg streams chunk 0 is created on the fly and stored
in a dynamically allocated buffer. Read-ahead on this buffer is likely
to access memory not owned by the process and might lead to a segfault.

Fix this bug by not performing read-ahead for chunk zero.

12 years agocom_lsblob: Print an error message if no blob matched.
Andre Noll [Tue, 1 Nov 2011 20:43:51 +0000 (21:43 +0100)]
com_lsblob: Print an error message if no blob matched.

Just to be consistent with other commands.

12 years agocom_ls: Print an error message if no file matched.
Andre Noll [Tue, 1 Nov 2011 19:05:07 +0000 (20:05 +0100)]
com_ls: Print an error message if no file matched.

In case at least one pattern was given and no matches were found,
the ls command returned with no output at all. This makes it print a
"no matches" error message instead.

12 years agocatblob: Fix "no matches" message.
Andre Noll [Mon, 26 Sep 2011 20:51:48 +0000 (22:51 +0200)]
catblob: Fix "no matches" message.

The catblob commands are supposed to print this message only if none
of the given patterns matches any blob in the database.  However, in
case all of the matching blobs are empty, we do print the message.

The problem is that the match count is not being increased due
to cat_blob() returning negative for empty blobs. This count is
computed in action_if_pattern_matches() which calls cat_blob() as
its action handler which in turn calls osl_open_disk_object(). But
this function returns -E_OSL_EMPTY for empty blobs, and cat_blob()
just passes through this value.

This patch changes cat_blob() so that it explicitly checks for
-E_OSL_EMPTY and returns zero in this case so that the match counter
will be increased.

12 years agoafs: Make catblob commands print an error if no blob matched.
Andre Noll [Wed, 6 Jul 2011 20:32:06 +0000 (22:32 +0200)]
afs: Make catblob commands print an error if no blob matched.

This is straight-forward given the new generic num_matches
counter which was introduced in the previous patch.

12 years agoafs: Provide generic counter for matching rows.
Andre Noll [Wed, 6 Jul 2011 20:30:59 +0000 (22:30 +0200)]
afs: Provide generic counter for matching rows.

Several afs commands implemented their own counters, often only to
find out whether they should print an error message because no rows
matched the given pattern(s).

This patch makes counting matching rows generic by increasing the new
pattern_match_data->num_matches counter in action_if_pattern_matches()
so that all commands which use this facility for iterating over all
audio files can evaluate the counter afterwards. This allows to remove
several per-command counters.

12 years agoMerge branch 't/alsa_improvements'
Andre Noll [Sun, 6 Nov 2011 11:14:17 +0000 (12:14 +0100)]
Merge branch 't/alsa_improvements'

12 years agoMerge branch 't/t0004'
Andre Noll [Sun, 6 Nov 2011 11:06:25 +0000 (12:06 +0100)]
Merge branch 't/t0004'

12 years agoweb: Rework text on download page.
Andre Noll [Wed, 2 Nov 2011 16:25:02 +0000 (17:25 +0100)]
web: Rework text on download page.

The git link to kernel.org was defunct and is probably not the best
pointer anyway. These days everybody knows git, so let's simply not
link to any git page.

This patch also reorders the three options for downloading (clone repo,
download snaphot, download release) so that git comes first.

12 years agohttp_recv: Fill both buffer pool buffers simultaneously.
Andre Noll [Tue, 20 Sep 2011 22:55:05 +0000 (00:55 +0200)]
http_recv: Fill both buffer pool buffers simultaneously.

This changes http_recv_post_select() to call readv_nonblock() rather
than read_nonblock() to read data from the socket, just like the udp
and dccp receivers do.

This saves one iteration of the scheduler loop if the end of the
buffer pool area is reached.

12 years agorecv: Make ->btrp and ->fd generic.
Andre Noll [Tue, 20 Sep 2011 22:36:08 +0000 (00:36 +0200)]
recv: Make ->btrp and ->fd generic.

All three receivers maintain a file descriptor and a buffer tree
pool per connection. Currently these are part of the receiver node's
private_data structure, which is a needless code duplication.

This patch moves both fields to the generic struct receiver_node. Since
the private_data structure of the udp and dccp receivers contained
no other fields, this allows to get rid of it completely for these
two receivers.

12 years agoMerge branch 't/afs_argv0'
Andre Noll [Sat, 29 Oct 2011 09:08:26 +0000 (11:08 +0200)]
Merge branch 't/afs_argv0'

12 years agoMerge branch 't/map_populate'
Andre Noll [Mon, 24 Oct 2011 13:31:31 +0000 (15:31 +0200)]
Merge branch 't/map_populate'

12 years agoMerge branch 't/unix_path_max_fix'
Andre Noll [Tue, 18 Oct 2011 17:32:16 +0000 (19:32 +0200)]
Merge branch 't/unix_path_max_fix'

12 years agoalsa: Improve error diagnostics.
Andre Noll [Fri, 29 Jul 2011 22:43:16 +0000 (00:43 +0200)]
alsa: Improve error diagnostics.

Always print the alsa error string corresponding to the failed library
call. This allows to get rid of all but one alsa errors in error.h.

12 years agoalsa: Make two variables local to alsa_init().
Andre Noll [Fri, 29 Jul 2011 21:46:28 +0000 (23:46 +0200)]
alsa: Make two variables local to alsa_init().

The two members buffer_frames and buffer_time of struct
private_alsa_data are only needed in alsa_init(), so make them
local. Rename buffer_frames to buffer_size since this is the value
returned by snd_pcm_hw_params_get_buffer_size().

12 years agoalsa: Dump the configuration on startup.
Andre Noll [Tue, 26 Jul 2011 20:47:20 +0000 (22:47 +0200)]
alsa: Dump the configuration on startup.

Currently we log selected alsa parameters, but it is sometimes
useful to see the full configuration. This patch adds a call to
snd_pcm_dump() to alsa_init() which obtains the alsa hardware and
software configuration. It is printed for loglevels info and debug.

12 years agoalsa: Avoid busy loop with dmix.
Andre Noll [Sat, 8 Oct 2011 17:16:14 +0000 (19:16 +0200)]
alsa: Avoid busy loop with dmix.

When using alsa's direct mixing plugin, the alsa poll fd might be ready
for IO even though nothing can be written to the alsa handle. This
leads to a busy loop in para_audiod and para_write and makes these
applications eat up considerable amounts of CPU time during playback.

This patch fixes the problem by reading from the alsa fd after a
failed write. It also adjusts the test for when to return early from
alsa_post_select(). The old code was not wrong, however, since we
should never reach the test if poll_fd is negative.

12 years agoMakefile: Remove unused variable man_pages_in.
Andre Noll [Sat, 1 Oct 2011 22:11:01 +0000 (00:11 +0200)]
Makefile: Remove unused variable man_pages_in.

This variable is defined but never used, so it is safe to remove it.

12 years agoMakefile: Drop dependencies on *_command_list.[ch].
Andre Noll [Fri, 16 Sep 2011 20:16:45 +0000 (22:16 +0200)]
Makefile: Drop dependencies on *_command_list.[ch].

It is enough to let para_audiod and para_server depend on their object
files only as these object files in turn depend on _command_list.[ch],
so Mr Transitivity does the work for us.

12 years agotestsuite: Introduce a new test for para_server.
Andre Noll [Sun, 11 Sep 2011 00:45:23 +0000 (02:45 +0200)]
testsuite: Introduce a new test for para_server.

This adds t0004-server.sh, a new test script which starts para_server
and tries to connect to it using the loopback device.

12 years agoserver: Kill temporary SIGCHLD handler.
Andre Noll [Wed, 12 Oct 2011 16:13:40 +0000 (18:13 +0200)]
server: Kill temporary SIGCHLD handler.

During startup, para_server sets up a temporary signal handler for
SIGCHLD in order to notice if the afs child process terminates
immediately (doing the signal setup after the fork would be too
late). This patch makes it block this signal during this period
instead. This works equally well and it fixes a weird problem on Mac
OS where the temporary SIGCHLD handler was executed although it had
been replaced by the generic signal handler of signal.c.

12 years agoserver: Listen on command socket before daemonizing.
Andre Noll [Tue, 20 Sep 2011 10:13:16 +0000 (12:13 +0200)]
server: Listen on command socket before daemonizing.

This makes sure that para_server is already listening on its TCP
command socket before it detaches from the console. This is desirable
because otherwise commands like

para_server -d -L /dev/null && para_client help

may fail due to para_client connecting before para_server starts to
listen.

12 years agotestsuite: Sort tests.
Andre Noll [Sun, 11 Sep 2011 21:08:56 +0000 (23:08 +0200)]
testsuite: Sort tests.

This guarantees that the tests are run in numerical order.

12 years agotestsuite: Don't write ANSI escapes to test output files.
Andre Noll [Sun, 11 Sep 2011 01:02:41 +0000 (03:02 +0200)]
testsuite: Don't write ANSI escapes to test output files.

The say() function adds ANSI escape sequences for colors to the output
if stdout is a tty. However, we don't want colors for output written
to a file, so don't use say() in this case.

12 years agotestsuite: t0001 depends on sha1sum.
Andre Noll [Mon, 19 Sep 2011 15:26:53 +0000 (17:26 +0200)]
testsuite: t0001 depends on sha1sum.

We don't want this test to fail if sha1sum is not installed.

12 years agoTrivial: Fix typo in documentation of para_next_signal().
Andre Noll [Fri, 14 Oct 2011 18:24:08 +0000 (20:24 +0200)]
Trivial: Fix typo in documentation of para_next_signal().

12 years agodoc: Add some missing doxygen comments.
Andre Noll [Sat, 15 Oct 2011 19:21:07 +0000 (21:21 +0200)]
doc: Add some missing doxygen comments.

12 years agoMerge branch 't/clang_analyzer_fixes'
Andre Noll [Sat, 15 Oct 2011 13:36:38 +0000 (15:36 +0200)]
Merge branch 't/clang_analyzer_fixes'

12 years agopara_filter: Decode also small ogg vorbis files properly.
Andre Noll [Thu, 13 Oct 2011 14:10:11 +0000 (16:10 +0200)]
para_filter: Decode also small ogg vorbis files properly.

ogg_post_select() returns after initializing the decoder without
decoding anything, which is usually OK. However, if the file is smaller
than half of the size of the stdin buffer tree area, the whole file
is going to be fed to the decoder during the first iteration of the
scheduler loop. Currently this results in an empty output file.

The problem with small files is that the post select function of the
stdin buffer tree node encounters EOF on the next read and returns
EOF. This causes oggdec_post_select() to abort without producing any
output since its parent (stdin) is gone and there is no input pending.

This patch fixes the problem by setting the "have_more" flag after
ogg_init() returned successfully. oggdec_post_select() checks this
flag and only returns negative if it is unset.

12 years agoafs: Write 'afs' to argv[0].
Andre Noll [Sun, 11 Sep 2011 02:21:40 +0000 (04:21 +0200)]
afs: Write 'afs' to argv[0].

This allows to distinguish the afs process from the main server
process by looking at the ps output. Although there are less hacky
ways to achieve this (prctl(PR_SET_NAME, ...), setproctitle()), the
argv approach has the advantage of working on all supported operating
systems except FreeBSD. We have been doing the argv mangling for a
long time now in the command handlers and it has never caused any
problems, so it should be safe.

12 years agoMerge branch 't/uptime_cleanup'
Andre Noll [Mon, 10 Oct 2011 20:01:22 +0000 (22:01 +0200)]
Merge branch 't/uptime_cleanup'

12 years agoMerge branch 't/shmmax'
Andre Noll [Tue, 4 Oct 2011 19:41:47 +0000 (21:41 +0200)]
Merge branch 't/shmmax'

12 years agodoc: Minor doxygen fixes.
Andre Noll [Sat, 1 Oct 2011 21:35:18 +0000 (23:35 +0200)]
doc: Minor doxygen fixes.

doxygen's \cond and \endcond commands treat the word after the
command as the name of the section which should be excluded from the
documentatation. So it is wrong to put an arbitrary comment there.

This fixes a couple of doxygen warnings about unknown loglevel defines
and makes these defines actually show up in the generated HTML.

12 years agoFix UNIX_PATH_MAX on NetBSD.
Andre Noll [Mon, 19 Sep 2011 17:12:40 +0000 (19:12 +0200)]
Fix UNIX_PATH_MAX on NetBSD.

UNIX_PATH_MAX was hardcoded to 108 for all systems. However, at
least on 32 bit NetBSD the size of the sun_path buffer is only
104 bytes. This resulted in a very nasty bug caused by a memset()
overwriting 4 bytes on the stack.

Fix this by calculating the correct value at compile time.

12 years agoMerge branch 't/distcc'
Andre Noll [Mon, 26 Sep 2011 21:53:35 +0000 (23:53 +0200)]
Merge branch 't/distcc'

12 years agoopenssl RC4: Fix another invalid read.
Andre Noll [Mon, 26 Sep 2011 12:34:29 +0000 (14:34 +0200)]
openssl RC4: Fix another invalid read.

Commit 11993981 fixed this bug for the RC4 sending function
but missed to change sc_recv_bin_buffer() accordingly.

This patch avoids the following invalid read detected by valgrind:

==23299== Invalid read of size 8
==23299==    at 0x510A020: RC4 (in /lib/libcrypto.so.0.9.8)
==23299==    by 0x408771: sc_recv_bin_buffer (crypt.c:313)
==23299==    by 0x40837F: sc_recv_buffer (crypt_common.c:331)
==23299==    by 0x4073C2: T.41 (client_common.c:139)
==23299==    by 0x407758: client_post_select (client_common.c:268)
==23299==    by 0x406A34: schedule (sched.c:71)
==23299==    by 0x405625: main (client.c:572)
==23299==  Address 0x613ccb8 is 3,992 bytes inside a block of size 3,999 alloc'd
==23299==    at 0x4C274A8: malloc (vg_replace_malloc.c:236)
==23299==    by 0x405D9F: para_malloc (string.c:65)
==23299==    by 0x408741: sc_recv_bin_buffer (crypt.c:309)
==23299==    by 0x40837F: sc_recv_buffer (crypt_common.c:331)
==23299==    by 0x4073C2: T.41 (client_common.c:139)
==23299==    by 0x407758: client_post_select (client_common.c:268)
==23299==    by 0x406A34: schedule (sched.c:71)
==23299==    by 0x405625: main (client.c:572)

12 years agovss: Mmap audio files using MAP_POPULATE.
Andre Noll [Mon, 26 Sep 2011 06:27:18 +0000 (08:27 +0200)]
vss: Mmap audio files using MAP_POPULATE.

This fixes buffer underruns on an old laptop containing a
slow IDE disk. The problem was that getting the next chunk
from the map sometimes hit the disk and took more than 300ms.

This patch adds MAP_POPULATE to the flags for mmap() to
turn on read-ahead for the mapping. This almost fixed the
problem, but some buffer underruns remained. Moreover,
MAP_POPULATE is only available on Linux. To fix also the
remaining cases, we now read one byte from each of the next
few pages in the map after a chunk has been sent. This way
the next chunk should already be cached when it is needed.

12 years agocommand: Remove two dead stores.
Andre Noll [Mon, 15 Aug 2011 18:20:02 +0000 (20:20 +0200)]
command: Remove two dead stores.

command.c:771:2: warning: Value stored to 'ret' is never read
        ret = -E_BAD_USER;
        ^     ~~~~~~~~~~~
command.c:765:2: warning: Value stored to 'numbytes' is never read
        numbytes = ret;
        ^          ~~~

12 years agoaac_afh: Don't compute the number of milliseconds twice.
Andre Noll [Mon, 15 Aug 2011 18:16:38 +0000 (20:16 +0200)]
aac_afh: Don't compute the number of milliseconds twice.

aac_afh.c:194:16: warning: Value stored to 'ms' during its initialization is never read
        long unsigned ms = 1000.0 * afhi->chunks_total * tmp
                      ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

12 years agoogg_afh: Kill dead store.
Andre Noll [Mon, 15 Aug 2011 18:15:05 +0000 (20:15 +0200)]
ogg_afh: Kill dead store.

ogg_afh.c:108:3: warning: Value stored to 'ret' is never read
                ret = -E_OGG_PACKET_IN;
                ^     ~~~~~~~~~~~~~~~~

12 years agocrypt: Streamline get_asymmetric_key().
Andre Noll [Mon, 15 Aug 2011 18:05:11 +0000 (20:05 +0200)]
crypt: Streamline get_asymmetric_key().

The clang analyzer says

crypt.c:202:9: warning: Function call argument is an uninitialized value
        ret2 = para_munmap(map, map_size);
               ^                ~~~~~~~~
And right it is. This is not a bug though as map_size is only undefined
if map is NULL and in this case para_munmap does not look at its second
argument. However, this is rather subtle, so introduce a new label out_unmap
and jump there only if we really must unmap the file.

12 years agowmadec: Fix two dead stores.
Andre Noll [Mon, 15 Aug 2011 17:42:15 +0000 (19:42 +0200)]
wmadec: Fix two dead stores.

wmadec_filter.c:772:3: warning: Value stored to 'mult1' is never read
                mult1 = mult;
                ^       ~~~~
wmadec_filter.c:1015:3: warning: Value stored to 'n' is never read
                n = pwd->block_len;
                ^   ~~~~~~~~~~~~~~

Also convert a statement of the form x = x * y to x *= y;

12 years agoimdct: Remove dead store.
Andre Noll [Mon, 15 Aug 2011 17:36:46 +0000 (19:36 +0200)]
imdct: Remove dead store.

imdct.c:296:2: warning: Value stored to 'output' is never read
        output += n4;
        ^         ~~

12 years agodccp_recv: Avoid NULL pointer dereference.
Andre Noll [Thu, 15 Sep 2011 12:33:14 +0000 (14:33 +0200)]
dccp_recv: Avoid NULL pointer dereference.

dccp_recv.c:48:16: warning: Access to field 'btrp' results in a dereference of a null pointer (loaded from variable 'pdd')
        btr_pool_free(pdd->btrp);
                      ^~~

In dccp_recv_close(), if pdd is NULL, we avoid closing pdd->fd but
dereference pdd nevertheless one line later. Fix this by returning
early if pdd is NULL.

12 years agorecv: Improve documentation of generic_recv_pre_select().
Andre Noll [Tue, 20 Sep 2011 20:27:18 +0000 (22:27 +0200)]
recv: Improve documentation of generic_recv_pre_select().

Make it clear that this function returns the state of the given buffer
tree node, i.e. > 0 on success, == 0 if there is nothing to do and <
0 on errors.

12 years agoafh: Fix two typos in the man page.
Andre Noll [Sun, 18 Sep 2011 14:23:34 +0000 (16:23 +0200)]
afh: Fix two typos in the man page.

12 years agoOverhaul the daemon uptime functions.
Andre Noll [Wed, 10 Aug 2011 22:01:11 +0000 (00:01 +0200)]
Overhaul the daemon uptime functions.

The public interface of daemon.c offers some helpers for maintaining
and printing the uptime of the service. This interface consists of
the "uptime" enumeration and the public functions server_uptime()
and uptime_str(). The former function takes an uptime enum which is
either 'UPTIME_GET' or 'UPTIME_SET'.

It is cleaner to avoid the enumeration and have two separate
functions for getting and setting the uptime, so this patch
replaces server_uptime() by two new functions get_server_uptime()
and set_server_start_time(), renames uptime_str() to
get_server_uptime_str() and gets rid of the uptime enum.

All three new functions take an optional struct timeval * type argument
for the common case where the caller already knows the current time, or
wishes to specify another time for whatever reason. This allows to save
one time() system call per scheduler loop in para_server since with
this patch status_refresh() can pass the global "now" pointer (which
us updated by the scheduler once per loop) to get_server_uptime().