Andre Noll [Tue, 23 Aug 2011 17:41:27 +0000 (19:41 +0200)]
Introduce clear_afhi().
aft.c and afh.c contain identical code to free all members of an
instance of struct afh_info. This commit introduces the public
function clear_afhi(), and patches both aft.c and afh.c to call the
new function.
Andre Noll [Wed, 24 Aug 2011 12:38:39 +0000 (14:38 +0200)]
http_recv: Trivial cleanup.
This variant to specify the size of an allocation is to be preferred
because (a) it's shorter, and (b) it breaks at compile time if "tmp" is
renamed but the argument to sizeof() was not updated accordingly.
Andre Noll [Thu, 5 Apr 2012 23:18:23 +0000 (01:18 +0200)]
Define status item list in afh_common.c.
The status_item_list array is needed for the audio format handler info
struct (afhi), so all executables which contain afh_common.o need it.
Currently, afh.c and command.c define their own instance for para_afh
and para_server respectively.
Moving the definition of the array to afc.c saves one instance. No
big deal.
Andre Noll [Thu, 5 Apr 2012 23:18:23 +0000 (01:18 +0200)]
interactive: Set stderr to nonbuffered mode.
fdopen() might return a stream which is fully buffered or line buffered.
We want unbuffered unconditionally, so explicitly set the stream to
unbuffered mode.
Andre Noll [Thu, 29 Mar 2012 17:58:04 +0000 (19:58 +0200)]
Merge branch 't/gui_improvements'
gui: Make some functions return void.
gui: Rename client_cmd_cmdline() to para_cmd().
gui: Check return value of para_exec_cmdline_pid().
gui: Also display command's stderr output.
Andre Noll [Sun, 25 Mar 2012 12:51:25 +0000 (14:51 +0200)]
mood.c: Silence gcc warning.
The newly released gcc-4.7.0 complains about "m" being used
uninitialized in change_current_mood(). gcc is wrong, but this is
not obvious to see: In change_current_mood(), "m" is only going to
be used if load_mood() returns non-negative. This happens only on
success, when load_mood() returns 1. In this case "m" was previously
set to mlpd.m which was initialized to NULL at the top of load_mood()
and later set to the newly allocated mood structure.
This patch makes it easier for gcc by initializing "m" to NULL
upfront. This causes the warning to go away.
Andre Noll [Tue, 13 Mar 2012 15:37:36 +0000 (16:37 +0100)]
Link against libz if compiling with libid3tag support.
libid3tag depends on libz. On Linux, libz is automatically linked to
para_server and para_afh but at least on FreeBSD compilation fails
due to undefined references to "uncompress" and "compress2".
This patch explicitly adds -lz to $server_ld_flags and $afh_ldflags
if libid3tag was detected.
Andre Noll [Wed, 7 Mar 2012 17:16:52 +0000 (18:16 +0100)]
configure: Add --with-id3tag-headers/libs.
If libid3tag was intalled at a non-standard location, the configure
script would not find it. Currently there is no way to tell configure
to look for libid3tag elsewhere.
This adds two new options, --with-id3tag-headers and --with-id3tag-libs,
to overcome this shortcoming.
Andre Noll [Tue, 13 Mar 2012 21:17:18 +0000 (22:17 +0100)]
gui: Also display command's stderr output.
Currently, both para_cmd() and display_cmd() redirect stderr to
/dev/null, so any error messages of the command being executed do
not make it to the bottom window. This is inconvenient at times,
and makes debugging hard.
This patch prints the stderr output in the bottom window using
COLOR_ERRMSG.
As for the implementation, the global command_pipe integer
variable becomes an integer array of length two which contains
the two file descriptors for stdout and stderr. We also need two
buffers in do_select(), so command_buf becomes a two-dimensional
array. do_select() now has to monitor two file descriptors per command
and it returns only after the peer has closed both fds.
Andre Noll [Tue, 13 Mar 2012 21:30:34 +0000 (22:30 +0100)]
gui: Check return value of para_exec_cmdline_pid().
external_cmd() calls this function to execute the given command.
However, as para_exec_cmdline_pid() may fail, e.g. because the
underlying call to fork() failed due to hitting the RLIMIT_NPROC
resource limit, we must check the return value. The other two command
dispatchers got this right, but external_cmd() did not.
Andre Noll [Sun, 5 Feb 2012 13:18:11 +0000 (14:18 +0100)]
configure.ac: Do not include server-only objects unconditionally.
We included the list of server-only objects in $all_errlist_objs
even if para_server is not going to be built (because libosl was
not found). This confuses t0004-server which bases the decision
whether it should skip its tests on whether server.o is contained
in $all_errlist_objs.
So add these objects to $all_errlist_objs only if libosl is detected.
Andre Noll [Fri, 13 Jan 2012 22:54:08 +0000 (23:54 +0100)]
audioc: Fix memory leak in configfile_exists().
In case the config file does not exist, the function returns NULL
without freeing the config_file buffer.
This patch also makes config_file non-static. As configfile_exists()
is called at most once, it is pointless to have a static variable
there. The condition "if (!config_file)" is always true, so we can
get rid of the conditional alltogether.
Andre Noll [Thu, 8 Dec 2011 20:01:01 +0000 (21:01 +0100)]
Improve error diagnostics of mmap_full_file().
On mmap errors, this function used to return the error code it got
from mmap(). Unfortunately, in at least two cases, this results in
rather obscure error messages:
$ para_afh -i .
main: No such device
$ touch foo; para_afh -i foo
main: Invalid argument
This simple patch specifically checks whether the given fd refers
to a directory or an empty file so that the error messages become
more readable:
$ para_afh -i .
main: failed to mmap "."
main: Is a directory
$ touch foo; para_afh -i foo
main: failed to mmap "foo"
main: file is empty
Andre Noll [Thu, 1 Dec 2011 18:25:47 +0000 (19:25 +0100)]
audiod: Deprecate the --no_default_filters option.
This option does not make much sense anymore these days as we have
sane defaults in case no filter was given. We prefer deprecation over
removal because this allows to switch between old and new versions
without having to edit the config file.
The option will be removed after the next release.
Andre Noll [Sun, 22 Jan 2012 21:45:21 +0000 (22:45 +0100)]
para_client: Fix a memory leak.
The main function of para_client first calls client_parse_config()
to decide whether to start an interactive session, run in completion
mode or execute the given command. In the third case case we call
client_open() which calls client_parse_config() again, thereby
leaking the client_task structure which was returned by the first
call to client_parse_config().
Fix this leak by calling client_connect() instead of client_open().
Andre Noll [Fri, 6 Jan 2012 03:15:34 +0000 (04:15 +0100)]
Replace PARA_VSNPRINTF by xvasprintf().
The PARA_VSNPRINTF macro is rather clumsy, and too large to be inlined.
Moreover, it does not return the length of the formated string, so
users have to call strlen() after the call to PARA_VSNPRINTF(). This
is extra work which can easily be avoided since the number of bytes
written is returned by the underlying call to vsnprintf().
This patch replaces the macro by the public function xvasprintf(),
which is similar to the non-standard vasprintf() on GNU systems. It
also adds xasprintf(), a similar variant which takes a variable number
of arguments.
Unlike PARA_VSNPRINTF, xasprintf() and xvasprintf() return the number
of bytes written. This relies on vsnprintf() conforming to the C99
standard and breaks in particular on glibc 2.0 systems. Since glibc
2.0 is about 15 years old, this is unlikely to cause problems on
real systems.
All users which called strlen() right after xvasprintf() are changed
to use the return value of xvasprintf() instead.
Andre Noll [Sat, 24 Dec 2011 00:22:58 +0000 (01:22 +0100)]
command: Introduce struct command_context.
This exposes a couple of variables which were previously local to
handle_connect() to the command handlers, allowing them to make use
of the full command context.
All newly exposed variables are stored in an instance of the new
structure, and the command handlers now take a pointer to such
a structure.
Andre Noll [Fri, 23 Dec 2011 17:28:45 +0000 (18:28 +0100)]
Introduce xwritev().
For the sideband API we will need to write two buffers one after
another. This patch adds the new public function xwritev() to fd.c
which takes an arbitrary number of buffers and calls writev() to
perform the write.
With this function in place, xwrite() becomes a trivial wrapper
for xwritev().
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.
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().
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.
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().
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.