Merge topic branch t/afs-select into master A single patch which silences the select command. The merge conflicted in afs.c, but that was trivial to resolve. * refs/heads/t/afs-select: server: Implement select -verbose.
Merge topic branch t/afs-ls-a into master A new feature for the ls command. Unfortunately, several bugs were found after the topic graduated to next, so the series contains a few fixup commits on top of the single patch which implements the feature. * refs/heads/t/afs-ls-a: afs: Really fix memory leak in mood_load(). afs: Fix memory leak in mood_load(). playlist: Fix error handling of playlist_load(). server: Fix NULL pointer dereference in com_ls(). Implement ls --admissible=m/foo.
Merge topic branch t/fd into master A rash of patches which clean up a good part of fd.c. Nothing major here, mostly simplifications and documentation improvements. * refs/heads/t/fd: fd: Simplify and move for_each_file_in_dir(). fd.c: Improve error checking of para_mkdir(). fd: Revamp para_mkdir(). fd: Improve read_pattern(), rename it to read_and_compare(). fd: Remove log message from para_munmap(). fd: Open-code para_chdir(). fd: Remove file_exists(). fd: Improve documentation of xwritev(). fd: Improve documentation of write_all(). fd: Improve documentation of write_va_buffer().
server: Fix memory leak at exit. If a playlist is open on exit, we miss to free it. Not a real leak, but still..
server: Add missing newline in select -v error output. The error message that lacks the newline can be triggered by runing "select -v X".
server: Implement select -verbose. Just set ->pbout to NULL if the new option is not given. This supresses normal output while error messages still make it to the client because those are sent with afs_error().
Implement ls --admissible=m/foo. Currently there can be only one score table at a time because the functions of score.c refer to the global score_table variable. To implement the new feature, we need to overcome this restriction so that the callback of the ls command can populate an independent score table to print its output without interfering with the score table that is currently active. This commit changes most functions of score.c to receive an additional table pointer argument. All current users of the score table pass a NULL pointer to instruct the functions to operate on the global score table as before. However, if the ls command is invoked with an optional mood argument to -a. the callback calls mood_load(), followed by mood_loop() and mood_unload(). The former returns an opaque handle which is then passed to the other two functions to instruct them to operate on the temporary score table instead of the global one. To make the feature work for playlists as well, analogous functionality is implemented in playlist.c. The new mop_loop() of aft.c performs the disambiguation in a similar way as the activate_mood_or_playlist() does. It is a bit simpler though, since the ls command does not have to deal with NULL arguments and does not need to fall back to the dummy mood.
afs: Improve error message in init_admissible_files(). arg may well be NULL here, so print "dummy" in this case.
fd: Revamp para_mkdir(). It has two callers which both pass the mode value 0777 and contain extra code to regard the EEXIST error case as a success. Move the common bits into the wrapper and improve the documentation.
server: Improve error diagnostics of com_select(). The attempt to select a non-existing mood or playlist currently results in remote: key not found in rbtree This is a bit cryptic, so be a bit more user-friendy and provide a paraslash error code for this case.
Introduce afs_error(). The callbacks of some afs commands employ the normal ->pbpout para buffer to send an error message to the client on failure. These messages are therefore tagged with the OUTPUT sideband designator just as regular command output. The receiving client writes such messages to stdout, so applications which call para_client have no other way than parsing the output to guess whether it is normal command output or an error message. This commit improves on this by providing a public helper in afs.c to format and send an error message that is tagged with the ERROR sideband designator and thus gets written to stderr on the client side. All afs callbacks which currently use ->pbout for error messages are converted to call the new helper.
afs.c: Move com_select() and its callback down. Preparation for the upcoming introduction of afs_error(), which will be called by the select callback and should therefore be located above the callback. No code changes, nothing to see here.
Rename mood_switch(), mood_close(), playlist_{open/close}. This naming is unfortunate because we also have the static {mood,pl}_{open,close}() in blob.c which operate on the osl table. In contrast, the functions renamed in this commit operate on blob objects and change the current mood or playlist. Let's call these operations load/unload to avoid confusion.
Assume that score_open() and score_clear() always succeed. Since the score table has only volatile columns, the only possible error is memory exhaustion, in which case we can only abort anyway. This patch changes score_open() to abort if osl_open() fails. This allows us to let score_clear() return void. We can't get rid of the return value of score_open(), however, since a pointer to this function is stored the afs table operations structure.
afs.c: Rename ->handler of struct callback_query to ->cb. The term "handler" is already overloaded. Besides command and signal handlers we have callback result handlers, table event handlers and max size handlers for para buffers. The simple "cb" is a shorter and clearer name for the callback function pointer.
Simplify and improve activate_mood_or_playlist(). The logic of this function can be simplified to match the four possible cases for the argument. Each of the four conditional blocks now initializes ret, mode and the message pointer. The message is then printed into the para buffer, which is now passed to the function instead of a char ** because this simplifies the select callback a bit. The other callers (for init and SIGHUP handling) pass NULL and don't need to be adjusted. To make this work we have to make sure that the message pointer is properly initialized in all cases, not only in the error case as before. Thus, playlist_open() and mood_switch() are changed to return a suitable message also on success. For playlists, the message only contains the number of files in the playlist. For moods we also include the afs statistics of the mood and no longer write this information to the server log. We omit the correction factors and the normalization divisor, however, as these are not very interesting. The only purpose of the num_admissible parameter of activate_mood_or_playlist() was to let the caller log this information. This task is now performed by playlist_open() and mood_switch(), so the parameter can be dropped.
afs: Replace ->init of afs tables by table operations. This is simpler, avoids the run-time initialization, and allows us to mark the instances of the operations structures constant. Improve the documentation a bit while at it.
Remove mood.h. It's too small to be useful. Simply move the three function declarations to afs.h, next to the playlist related functions.
Clean up and rename change_current_mood(). Move the code which destroys the current mood to the end of the function so that we can still return to the old mood if something goes awry. To make this work, various functions need to be adjusted to no longer refer to to afs statistics via the global current_mood pointer. Pass a pointer to the statistics structure to those. Also get rid of the local mood pointer variable in favor of ->m of struct admissible_array. Rename the function because it is public and deserves the mood_ prefix.
afs.c: Improve activate_mood_or_playlist(). Merge the two conditional branches to simplify the code and increase the event counter to notify the server also in the SIGHUP case. This is the right thing to do because we did (re)load the mood or playlist.