daemon: Improve documentation of daemon_open_log_or_die(). This function has no return value, so don't use \return.
New audiod command: ll to change the log level at runtime. The new public daemon_get_loglevel() is needed in the zero argument case. Otherwise, the ll command handler parses the argument and calls daemon_set_loglevel(). The lopsub stanza for the subcommand is stored in a separate file which is currently only included by the lopsub suite for para_audiod, but will be included as well by the server suite. For similar reasons we implement the completer as a generic public function, i9e_ll_completer(), although it only has one caller in audioc.c. Another caller follows when the ll server command is added.
daemon: Kill get_loglevel_by_name(). Open-code the logic in daemon_set_log_color_or_die() and get the values from the new SEVERTIES macro rather than duplicating the severity list in get_loglevel_by_name(). The SEVERTIES macro will turn out to be handy for the ll subcommands of para_server and para_audiod which are introduced in subsequent commits.
server/audiod: Don't parse loglevel argument unnecessarily. Currently the severity string (debug, info, etc.) given to --loglevel is parsed twice: Once by lopsub, which returns the loglevel as the index into the array of severity strings. We turn this index into a string and pass the string to daemon_set_loglevel() which parses the string again to turn it back into a log level value (which happens to coincide with the index value). Clean this up by letting daemon_set_loglevel() receive a log level value rather than a severity string. This also allows us to remove the now unused ENUM_STRING_VAL() macro from audiod.c.
daemon: Improve documentation of daemon_set_log_color_or_die(). The function receives a severity string, not a log level number.
daemon: Add documentation of daemon_set_hooks(). The function was introduced already one year ago in commit ced0c17d1a3e (daemon: Introduce log mutex), but no documentation was provided back then.
daemon: Introduce log mutex. Currently the server processes append messages to the log file without coordination. This usually does not cause problems, but sometimes the log messages of the main server process and the afs process get interleaved due to the lack of serialization. This patch serializes access to the common log file by employing a new lock: the log_mutex. Like the mmd_mutex, it is realized as an one-element System V semaphore set. Logging is performed by the daemon subsystem implemented in daemon.c. This subsystem is also used by para_audiod which is single-threaded and thus does not need to care about serialization of log messages. To keep daemon.c working for both para_server and para_audiod, struct daemon gains two optional methods, ->pre_log_hook and ->post_log_hook. If the function pointers are not NULL, the methods are called before and after a message is logged. For para_server the methods call back to the server code to take and release the lock. para_audiod does not need to be modified because if the new function pointers are left at their default value NULL, so no hooks are called.
daemon: Fix log reload for relative paths. If the argument to --logfile is a relative path, it is interpreted as relative to the current working directory. In daemon mode, the current working directory is changed to / during startup. Hence, when para_server re-opens the log file after it received SIGHUP, the logfile path will now be interpreted as relative to the the root of the file system. Fix this by remembering the original current working directory. Opening "." as recommended in getcwd(3) is not an option here since the whole point of changing the cwd to / is to prevent the daemon from keeping the cwd busy.
Improve daemon_open_log_or_die(). If the log file can not be re-opened, the error message is lost because the log file has already been closed when PARA_EMERG_LOG() is called. We can do better by deferring the call to daemon_close_log() until the new log file has been opened. With the patch applied, the reason why the (new) log file could not be opened is logged to the old file.
Shorten copyright notice. The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
doxygen: Remove some stale doxygen references. When we switched to lopsub, the callback request functions became unused and were removed. At the same time, all command handlers were made static, so they are no longer part of the doxygen documentation and we shouldn't refer to them any more. Also struct slot_info and the server_uptime variable have been made private to their respective files audiod and time.c. Tthe latter was in fact replaced by a timeval struct long ago. The http and udp receivers don't have an init function any more, and get_chunk_table_of_row() was removed ten years ago in commit 54a480ae. Most references of the source code documentation will be annotated with \ref in a subsequent commit to avoid this kind of documentation bug in the future.
daemon: Fix race condition in daemonize(). If parent_waits is true, the parent process waits for a signal from the child before it exits. However, this signal can arive before the parent has set up its signal handler. This patch closes the race window by switching from signals to pipes. We now create a pipe before the new process is forked, and let the parent block on read(2) until the child exits or indicates success by writing a byte to one end of the pipe. The child process receives the file descriptor of the writing end of the pipe as the return value of daemonize(). The only user of the parent_waits feature is para_server, which is changed accordingly.
daemon: Improve "daemonizing" log message. The function name "daemonize" is shown anyway, so let's print the path to the log file instead.
daemon: Make daemon_init_colors_or_die() independent of gengetopt. The function receives the values given to the --log-color option as a char * array, which is the type that gengetopt provides for the arguments to string options which may be given multiple times. This patch gets get rid of this implementation detail. The function no longer takes the arguments to --log-color at all and applications now must call daemon_set_log_color_or_die() themselves to set user-defined per-loglevel colors. To make this work, we let daemon_init_colors_or_die() return a boolean which indicates whether color mode should be enabled, and daemon_set_log_color_or_die() is made public. The two users of this API, para_server and para_audiod, are adjusted accordingly.
daemon: Constify argument of two functions. daemon_set_logfile() and daemon_set_loglevel() do not modify the passed string, so the type of the argument should be const char *.
daemon: Improve color error message. If the string passed to daemon_set_log_color_or_die() can not be parsed, we don't have a syntax error but an invalid argument.
daemon: New option --priority for server and audiod. On slow hardware it is useful to set the priority of the para_audiod process to avoid sound artefacts due to buffer underruns. This patch adds an option for this purpose which is available for para_server and para_audiod.
daemon: Improve daemon_log_welcome(). This function is used within para_server and para_audiod. Adding the "para_" prefix in daemon_log_welcome() rather than its callers avoids the duplication. Also rename the "whoami" parameter to "name" and add documentation for it. Finally, the build date is not really important in the log message, so simply remove it.
Allow to start server and audiod as daemon with no logfile. Currently para_audiod and para_server won't start in the background if no logfile is specified, so "-dL /dev/null" must be given to force this. This is a bit tedious to type, so this commit makes "/dev/null" the default. To achive this, we can simply remove the gengetopt "dependon" statement from daemon.m4. This works because if no logfile was given, log output is written to stderr, which is redirected to /dev/null in case -d was also given. We need to open /dev/null in read-write mode though, but no other changes are required.
daemon: Introduce daemon_init_colors_or_die(). The log color logic is already contained in para_server and para_audiod. Let's use a single function in daemon.c for this purpose. daemon_set_default_log_colors() and daemon_set_log_color_or_die() can be made static since they are only called from daemon.c now.