summaryrefslogtreecommitdiff
path: root/daemon.c (follow)
Commit message (Collapse)AuthorAge
* Don't discard const qualifier.Andre Noll2026-05-24
| | | | | | | | | gcc-16 rightfully complains as follows: daemon.c:66:19: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 66 | char *p = strchr(arg, ':'); In audiod.c, parse_stream_command() has the same issue, so fix both.
* Prefer paraslash_version() over PACKAGE_VERSION.Andre Noll2026-05-03
| | | | | | | Currently we use at several places the package version, i.e. the version that was checked out when the package was configured. The paraslash version is recomputed every time the package is build, so this is more up-to-date. So use paraslash_version() everywhere and remove PACKAGE_VERSION.
* Switch to SPDX identifiers.Andre Noll2026-03-17
| | | | | | | | Generated with sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h followed by manually tweaking the result a bit. No license change intended.
* Modify para_hostname() to return a static buffer.Andre Noll2025-08-07
| | | | | | | | All but one caller immediately free the result after using it. The exception is daemon.c, which maintains a copy in struct daemon, and leaks it on exit. All users can trivially be converted to use the new version, which does not require to free the result.
* Include regex.h from para.h.Andre Noll2025-05-19
| | | | Every .c file includes it anyway.
* daemon: Improve documentation of daemon_open_log_or_die().Andre Noll2022-09-27
| | | | This function has no return value, so don't use \return.
* New audiod command: ll to change the log level at runtime.Andre Noll2022-07-02
| | | | | | | | | | | | | | 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().Andre Noll2022-07-02
| | | | | | | | | 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.Andre Noll2022-07-02
| | | | | | | | | | | | | 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().Andre Noll2021-11-25
| | | | The function receives a severity string, not a log level number.
* daemon: Add documentation of daemon_set_hooks().Andre Noll2018-12-25
| | | | | | 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.Andre Noll2018-03-13
| | | | | | | | | | | | | | | | | | | | | | | 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.Andre Noll2018-02-11
| | | | | | | | | | | | | | 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().Andre Noll2018-02-11
| | | | | | | | | | 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.Andre Noll2017-09-22
| | | | | | | | | | | | | | | | | | | | | 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.Andre Noll2017-06-25
| | | | | | | | | | | | | | | | | | 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().Andre Noll2016-10-04
| | | | | | | | | | | | | | | | 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.Andre Noll2016-09-26
| | | | | 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.Andre Noll2016-08-07
| | | | | | | | | | | | | | | | 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.Andre Noll2016-07-03
| | | | | 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.Andre Noll2016-06-25
| | | | | 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.Andre Noll2015-10-15
| | | | | | | | 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().Andre Noll2015-07-22
| | | | | | | | 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.Andre Noll2015-04-30
| | | | | | | | | | | | | 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().Andre Noll2015-02-08
| | | | | | | | | 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.
* Update year in copyright headers.Andre Noll2015-01-12
| | | | | | | | | | | | | | | | Done with files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2014\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2014 Andre Noll/Copyright (C) \1 Andre Noll/1' $files In previous years we ran a similar script to set the second year in the range to the current year. This is kind of silly, so let's get rid of this useless information. This commit replaces "Copyright (C) A-B" by "Copyright (C) A" in all file headers, i.e. only the first year (A) is left in. Accurate information including time stamps for each change can be obtained from the git history.
* daemon.c: Remove unused daemon_clear_flag().Andre Noll2015-01-12
| | | | Found by cppcheck.
* daemon.c: Avoid setlinebuf().Andre Noll2015-01-12
| | | | | Using setvbuf() is equivalent, and more portable. See setbuf(3) for details.
* doc: Change email address to maan@tuebingen.mpg.deAndre Noll2014-08-18
| | | | | | | | | | | | | | The mail server on systemlinux.org was down for more than a week lately, so let's use an alternative official address. This commit changes all maan@systemlinux.org addresses to maan@tuebingen.mpg.de. Most .c and .h files contain the email address in the copyright header, so they must all be patched. Three other files contain the address for a different reason: * README lists email and git, gitweb and home page URLs * configure.ac needs it for configure -h * version.c contains it for the -V option of all commands
* daemon: Rename public functions.Andre Noll2014-06-19
| | | | | Let's reserve the daemon_ prefix for public functions of daemon.c to make it clear where these functions are defined.
* Simplify set_server_start_time().Andre Noll2014-06-19
| | | | | | | | | | | | | | This function receives a pointer to a timeval structure which is supposed to contain the daemon startup time. Passing NULL means to set the daemon startup time to the current time. There are only two callers of this function, in audiod.c and in server.c. The first one passes NULL, the other one initialises the timeval structure pointed to by the global now pointer to the current time, and passes this pointer. It's easier to let set_server_start_time() always act as if NULL had been passed.
* Change copyright year to 2014.Andre Noll2014-02-22
| | | | | | | | | This year, we're really on time. The changes in this patch were created by the following silly script: files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2013\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2013 Andre Noll/Copyright (C) \1-2014 Andre Noll/1' $files sed --in-place= -e 's/Copyright (C) 2013 Andre Noll/Copyright (C) 2013-2014 Andre Noll/1' $files
* Replace gettimeofday() by clock_gettime().Andre Noll2013-04-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | POSIX.1-2008 marks gettimeofday() as obsolete, so let's switch to clock_gettime(). clock_gettime() operates on timespecs rather than on timevals like gettimeofday() does. Since timevals are extensively used in all parts of paraslash, and select() takes a timeval pointer as the timeout parameter, it seems to be easiest to add a new wrapper, clock_get_realtime(). It calls clock_gettime(), performs error checking (all errors are treated fatal and abort the program), and converts the result to a timeval. Another difference between gettimeofday() and clock_gettime() is that sys/time.h needs to be included for gettimeofday(), while clock_gettime() is declared in time.h which gets included from para.h. Hence we can remove the include statement for sys/time.h everywhere. Programs which call clock_gettime need to be linked against librt on glibc versions before 2.17 while BSD and newer glibc-based systems have no such requirement. To make matters more interesting, MacOS lacks clock_gettime() completely although this function conforms to SUSv2 and POSIX.1-2001. We'd like to avoid the unnecessary dependence on librt on systems that have clock_gettime() in -lc, and we must fall back to gettimeofday() on MacOS. Hence this commit also introduces a check in configure.ac which determines whether clock_gettime() is available and, if it is, whether -lrt is needed. Executables are only linked with -lrt if configure found that this is necessary.
* Change copyright year to 2013.Andre Noll2013-03-25
| | | | Better late than never.
* daemon.c: daemon_set_default_log_colors() returns void.Andre Noll2012-04-24
| | | | | Remove the incorrect documentation of the (non existing) return value.
* Change year in copyright message to 2012.Andre Noll2012-01-07
|
* Always include stdbool.h.Andre Noll2011-12-18
| | | | | | | | | 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.
* Allow switching between different log methods at runtime.Andre Noll2011-11-20
| | | | | | | | | | | | | | | | | 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.
* Compilation fix for FreeBSD.Andre Noll2011-11-17
| | | | | | 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.
* daemon: Introduce parent_waits flag for daemonize().Andre Noll2011-11-13
| | | | | | | | | | | | | | | | | 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.
* Overhaul the daemon uptime functions.Andre Noll2011-09-17
| | | | | | | | | | | | | | | | | | | | | 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().
* Merge branch 't/color_cleanups'Andre Noll2011-01-29
|\
| * color: Simplify color error handling.Andre Noll2010-12-05
| | | | | | | | | | | | | | We exit on errors anyway, so get rid of the return value of color_parse() and daemon_set_log_color() and abort immediately rather than returning -1. Add the familiar "_or_die" suffix to these functions to make it clear that no error handling is necessary in the caller.
* | Replace 2010 in copyright message by 2011.Andre Noll2011-01-17
|/
* Change year in COPYRIGHT to 2010.Andre Noll2010-04-05
| | | | Hey, this is earlier than last year :)
* Implement --log-timing for server and audiod.Andre Noll2009-12-19
| | | | This adds another option to include milliseconds in the output of each log message.
* Merge branch 'maint' into nextAndre Noll2009-10-22
|\
| * daemon: Avoid using MAXLINE.Andre Noll2009-10-22
| | | | | | | | | | MAXLINE is kind of depricated. Just use a 100 byte buffer and make the scope of the buffer more local. Also, kill the pointless initialization to an empty string.
| * drop_privileges_or_die(): Check return value of setuid().Andre Noll2009-10-22
| | | | | | | | | | The call to setuid() may fail, e.g. because it brings the process over its RLIMIT_NPROC resource limit. So print an error message and exit in this case.
* | Merge branch 'master' into nextAndre Noll2009-08-21
|\|