Andre Noll [Sun, 21 Oct 2007 11:43:22 +0000 (13:43 +0200)]
Complete afs event handling.
Add blob event handling. This definitely needs some
more fine-tuning, but that can be changed gradually
thanks to the generic event handling code.
In playlist mode there's nothing to do, as we're
not interested in any blob events. So install only
a dummy handler for the scoring system and decide
whether to reload the score table in mood.c.
Andre Noll [Thu, 11 Oct 2007 12:35:28 +0000 (14:35 +0200)]
Add --gc-sections to LDFLAGS.
This, together with -fdata-sections and -ffunction-sections brought
nice size reductions. Before:
-rwxr-xr-x 1 maan fml 29K Oct 11 14:32 para_audioc*
-rwxr-xr-x 1 maan fml 42K Oct 11 14:32 para_client*
-rwxr-xr-x 1 maan fml 33K Oct 11 14:32 para_fade*
-rwxr-xr-x 1 maan fml 38K Oct 11 14:32 para_filter*
-rwxr-xr-x 1 maan fml 54K Oct 11 14:32 para_fsck*
-rwxr-xr-x 1 maan fml 52K Oct 11 14:32 para_gui*
-rwxr-xr-x 1 maan fml 42K Oct 11 14:32 para_recv*
-rwxr-xr-x 1 maan fml 216K Oct 11 14:32 para_server*
-rwxr-xr-x 1 maan fml 38K Oct 11 14:32 para_write*
After:
-rwxr-xr-x 1 maan fml 21K Oct 11 14:31 para_audioc*
-rwxr-xr-x 1 maan fml 33K Oct 11 14:31 para_client*
-rwxr-xr-x 1 maan fml 29K Oct 11 14:31 para_fade*
-rwxr-xr-x 1 maan fml 29K Oct 11 14:31 para_filter*
-rwxr-xr-x 1 maan fml 45K Oct 11 14:31 para_fsck*
-rwxr-xr-x 1 maan fml 47K Oct 11 14:31 para_gui*
-rwxr-xr-x 1 maan fml 30K Oct 11 14:31 para_recv*
-rwxr-xr-x 1 maan fml 208K Oct 11 14:31 para_server*
-rwxr-xr-x 1 maan fml 29K Oct 11 14:31 para_write*
Andre Noll [Sun, 7 Oct 2007 19:03:54 +0000 (21:03 +0200)]
Only declare error codes that are safe to use.
The following type of bug occurred frequently since the introduction
of error.h: An error code was defined for some file a.c and was used
in another file b.c. This is all good if each executable that contains
b.o also contains a.o.
If this is not the case, i.e. if there is an executable that contains
b.o but _not_ a.o, the error texts of all errors defined for a.c are
not included in the executable. This results in a segmentation fault
at runtime if PARA_STRERROR() is used for such an error code.
Unfortunately, this was hard to spot because all error codes were
visible everywhere. This patch gets rid of this flaw by making
only those error codes visible for b.c which are safe to use.
According to the above, the set of error codes which are safe to use
in b.c can be defined as follows. Let E_1, ... E_n be the set of
executables that contain b.o and let, for j=1,...n, S_j be the
set of files those files contained in E_j. Then, all errors defined
in the intersection
S_1 \cap S_2 \cap ... \cap S_n
are safe to use in b.c. The patch adds a function to configure.ac
That computes this intersection. Unfortunately, it is rather expensive.
The good news is that this simplifies error.h a bit and that it
already revealed a couple of bugs which are also fixed in the patch:
- afs.c used E_SIGNAL_CAUGHT which was only defined in audiod.
Introduce E_AFS_SIGNAL and change afs.c accordingly.
- audiod uses E_RECV_SYNTAX, which belonged to recv which is
not contained in audiod. Move it to recv_common instead.
This bug is also present in v0.2.x and needs a similar fix.
- E_NOTDIR was used in fd.c, but was defined in osl.c. Not all
executables that include fd.o also include osl.o. Move E_NOTDIR
to the set of errors for fd.
Andre Noll [Fri, 5 Oct 2007 18:18:22 +0000 (20:18 +0200)]
Make it compile on Solaris.
This required a bit of work as Solaris has gethostbyname() and
socket-related functions not in libc but in libsocket and libnsl.
So add corresponding checks to configure.ac.
Moreover, make para_gui optional and add configure options for
specifying the directory containing the curses headers and curses
lib.
Andre Noll [Thu, 4 Oct 2007 14:11:59 +0000 (16:11 +0200)]
afs.c: Introduce client list for afs (fixes dosable bug).
With the old code, a malicious local user could easily cause a DOS
by connecting to the local afs socket but never sending any data
through that socket. This caused afs to block on the read() from the
new client fd.
This patch fixes this flaw by introducing a doubly liked list of
connected clients. Each entry in this list contains an open file
descriptor and the time the client connected.
In command_pre_select() we add each fd in the list to the set of
fds to be checked for readability. In command_post_select() we loop
through that list and check each fd again. Whenever the fd for a
client is readable we read from that fd and execute an afs command
if the client sent the valid magic cookie.
However, if the fd is not ready, we close the connection if more than
AFS_CLIENT_TIMEOUT seconds (default: 3) have passed since the client
connected. This hopefully avoids another possible DOS: A malicious
user could try to flood us with connections until the limit of open
fds is reached.
Andre Noll [Tue, 2 Oct 2007 13:56:10 +0000 (15:56 +0200)]
Make it compile on FreeBSD.
This was easier than expected. Only two items needed fixing:
- signal.h has to be included for several files that use signals.
- The __used and __packed macros are already defined on FreeBSD which
leads to an error at compile time. Fortunately paraslash doesn't use
these macros at all, so we can simply remove them.
Andre Noll [Tue, 2 Oct 2007 12:04:46 +0000 (14:04 +0200)]
fsck.c: Fix several bugs in dump mode.
- Don't abort if a directory can't be created because it already exists.
- Use correct variable for the disk storage name column.
- If more than one table is to be dumped, use a directory for each table.
- Remove __a_unused for main()'s argc which _is_ being used.
Andre Noll [Sat, 29 Sep 2007 12:00:14 +0000 (14:00 +0200)]
attribute.c: Clear attribute bits already at remove time.
If an attribute gets removed, the old code deferred clearing the
corresponding attribute bit in the afsi of all audio files until
that bit got reclaimed by add_att. This is problematic because of
the new no_attribute_set mood method.
Andre Noll [Sat, 29 Sep 2007 11:39:34 +0000 (13:39 +0200)]
mood.c: Add no_attributes_set mood method.
Also fix a bug in mm_played_rarely_parser(): If no arg was
specified in the mood definition, a NULL pointer is passed to that
function, so it must not blindly dereference that pointer.
Andre Noll [Sat, 29 Sep 2007 11:13:50 +0000 (13:13 +0200)]
Speed up mood loading.
The old code passed a pointer to the row of the audio file table to the
mood scoring functions. The scoring functions had to obtain the afsi,
afhi, path from that row pointer. Thus, at mood load time, the afsi,
afhi, path was extracted N times for each audio file if there are N
mood lines that used this info.
This patch changes the mood scoring functions so that they take
three pointers to afsi, afhi, path instead of the row pointer.
add_item_score(), the single caller of the mood scoring functions,
provides these pointers, i.e. they get extracted from the row pointer
only once per audio file.
This is still not optimal as most scoring functions use only one of
the three pointers. But let's not over-engineer the thing.
Andre Noll [Thu, 27 Sep 2007 15:47:46 +0000 (17:47 +0200)]
Implement pattern matching for com_touch().
Also, add -p and -v options and fix converting the last played
time which is a 64 bit intger, so strtol() will fail do it on 32
bit machines after 2039 ;)
To fix this, introduce para_atoi64() which calls strtoll() which
is 64 bit even on 32 bit machines and define para_atoi32() which
calls para_atoi64() and checks the boundaries.
Andre Noll [Thu, 27 Sep 2007 10:25:05 +0000 (12:25 +0200)]
Gerneralize for_each_matching_blob().
It's not only useful for blobs. For instance the rm and the touch
commands might also want to use something similar. So move it to
afs.c and call it for_each_matching_row().
Andre Noll [Wed, 26 Sep 2007 14:37:00 +0000 (16:37 +0200)]
Fix table init.
The previous patch introduced two instances of a bug which weren't noticed by
the compiler because attribute_table and score_table were declared as void *
pointers. Change that to struct osl_table *, and add the missing '&' operator.
Andre Noll [Wed, 26 Sep 2007 09:29:07 +0000 (11:29 +0200)]
addblob: Overwrite existing blobs.
Previously, an attempt to add a blob with a name of an already
existing blob failed (siltenly). Just replace the existing blob
with the new contents instead.
Andre Noll [Tue, 25 Sep 2007 12:16:14 +0000 (14:16 +0200)]
make get_playlist_data() generic.
Other blob types might use an analogous function as well, so introduce
blob_get_name_and_def_by_row() in blob.c, and use some preprocessor
magic to define such a function for each blob type.
Change all users of get_playlist_data() to use the new
pl_blob_get_name_and_def_by_row() and remove get_playlist_data().
Andre Noll [Tue, 25 Sep 2007 09:39:23 +0000 (11:39 +0200)]
More mood cleanups.
- Avoid use of global current_mood pointer where possible.
- Change name of non-static functions that use the current mood pointer:
mood_open() -> change_current_mood()
mood_close() -> close_current_mood()
mood_reload() -> reload_current_mood()
Andre Noll [Sun, 23 Sep 2007 20:38:54 +0000 (22:38 +0200)]
afs.c: Avoid noisy log message.
para_server regularly sends SIGUSR1 to all of its children. afs
just ignores that signal, so only print a log message if a signal
different from SIGUSR1 was caught.