From 5b1daf072556c1fc9a00e8735fa0cdba280c2231 Mon Sep 17 00:00:00 2001 From: Diego 'Flameeyes' Pettenò Date: Wed, 1 Oct 2008 13:26:32 +0200 Subject: Fix building on OpenSolaris (without _NSIG definition). On OpenSolaris, the _NSIG macro is not defined, but NSIG is; as it's not possible to use NSIG under glibc (it would miss the SIGRT* series), define a SIGNAL_UPPER_BOUND depending on the system (and error out if the system lacks both NSIG and _NSIG). --- libdaemon/dfork.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libdaemon/dfork.c b/libdaemon/dfork.c index f1ba7c1..6b94944 100644 --- a/libdaemon/dfork.c +++ b/libdaemon/dfork.c @@ -42,6 +42,14 @@ #include "dnonblock.h" #include "dlog.h" +#if defined(_NSIG) /* On glibc NSIG does not count RT signals */ +# define SIGNAL_UPPER_BOUND _NSIG +#elif defined(NSIG) /* Solaris defines just this */ +# define SIGNAL_UPPER_BOUND NSIG +#else +# error "Unknown upper bound for signals" +#endif + static int _daemon_retval_pipe[2] = { -1, -1 }; static int _null_open(int f, int fd) { @@ -665,7 +673,7 @@ int daemon_reset_sigs(int except, ...) { int daemon_reset_sigsv(const int except[]) { int sig; - for (sig = 1; sig < _NSIG; sig++) { + for (sig = 1; sig < SIGNAL_UPPER_BOUND; sig++) { int reset = 1; switch (sig) { -- cgit From 354715db707564693698ebac1ef63aa6c4e13e77 Mon Sep 17 00:00:00 2001 From: Diego 'Flameeyes' Pettenò Date: Wed, 1 Oct 2008 13:31:00 +0200 Subject: Conditionally declare variables if their use is conditional. Reduces warnings about unused variables by not declaring them if they are under an #ifdef conditional. --- libdaemon/dfork.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libdaemon/dfork.c b/libdaemon/dfork.c index 6b94944..62469bb 100644 --- a/libdaemon/dfork.c +++ b/libdaemon/dfork.c @@ -236,7 +236,9 @@ pid_t daemon_fork(void) { goto fail; } else if (pid == 0) { +#ifdef TIOCNOTTY int tty_fd; +#endif /* Second child */ if (sigaction(SIGCHLD, &sa_old, NULL) < 0) { @@ -478,9 +480,9 @@ int daemon_close_all(int except_fd, ...) { int daemon_close_allv(const int except_fds[]) { struct rlimit rl; int fd; - int saved_errno; #ifdef __linux__ + int saved_errno; DIR *d; -- cgit From 9fd1249bbef0712047140c81a57c34b4043a8136 Mon Sep 17 00:00:00 2001 From: Diego 'Flameeyes' Pettenò Date: Wed, 1 Oct 2008 21:15:46 +0200 Subject: Add support for setting verbosity level for stdout/stderr output. --- libdaemon/dlog.c | 18 ++++++++++++++++++ libdaemon/dlog.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/libdaemon/dlog.c b/libdaemon/dlog.c index f9f6639..b9f224e 100644 --- a/libdaemon/dlog.c +++ b/libdaemon/dlog.c @@ -32,6 +32,20 @@ enum daemon_log_flags daemon_log_use = DAEMON_LOG_AUTO|DAEMON_LOG_STDERR; const char* daemon_log_ident = NULL; +static int daemon_verbosity_level = LOG_WARNING; + +void daemon_set_verbosity(int verbosity_prio) { + + /* Allow using negative verbosity levels to hide _all_ messages */ + if ( verbosity_prio > 0 && + (verbosity_prio & LOG_PRIMASK) != LOG_PRIMASK ) { + daemon_log(LOG_ERR, "The value %d is not a valid priority value", + verbosity_prio); + } + + daemon_verbosity_level = verbosity_prio & LOG_PRIMASK; +} + void daemon_logv(int prio, const char* template, va_list arglist) { int saved_errno; @@ -42,6 +56,9 @@ void daemon_logv(int prio, const char* template, va_list arglist) { vsyslog(prio | LOG_DAEMON, template, arglist); } + if ( prio > daemon_verbosity_level ) + goto end_daemon_logv; + if (daemon_log_use & DAEMON_LOG_STDERR) { vfprintf(stderr, template, arglist); fprintf(stderr, "\n"); @@ -52,6 +69,7 @@ void daemon_logv(int prio, const char* template, va_list arglist) { fprintf(stdout, "\n"); } + end_daemon_logv: errno = saved_errno; } diff --git a/libdaemon/dlog.h b/libdaemon/dlog.h index 814171f..9755df6 100644 --- a/libdaemon/dlog.h +++ b/libdaemon/dlog.h @@ -81,6 +81,20 @@ void daemon_logv(int prio, const char* t, va_list ap); */ char *daemon_ident_from_argv0(char *argv0); +/** + * @brief Setter for the verbosity level of standard output. + * + * @param verbose_level Minimum priority level for messages to output + * on standard output/error + * + * Allows to decide which messages to output on standard output/error + * streams. All messages are logged to syslog and this setting does + * not influence that. + * + * The default value is LOG_WARNING. + */ +void daemon_set_verbosity(int verbosity_prio); + #ifdef __cplusplus } #endif -- cgit From 7067029368ab389b92f5a7329899188d47f191ba Mon Sep 17 00:00:00 2001 From: Diego 'Flameeyes' Pettenò Date: Thu, 2 Oct 2008 13:40:05 +0200 Subject: Bumping version (and version info for the library). This will allow to explicitly check for support of the new extensions (like verbosity). --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 0eb0114..a185464 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ AC_PREREQ(2.62) -AC_INIT([libdaemon],[0.13],[mzqnrzba (at) 0pointer (dot) de]) +AC_INIT([libdaemon],[0.14],[mzqnrzba (at) 0pointer (dot) de]) AC_CONFIG_SRCDIR([libdaemon/dfork.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) @@ -30,7 +30,7 @@ AM_INIT_AUTOMAKE([foreign 1.9 -Wall]) AC_SUBST(PACKAGE_URL, [http://0pointer.de/lennart/projects/libdaemon/]) -AC_SUBST(LIBDAEMON_VERSION_INFO, [4:0:4]) +AC_SUBST(LIBDAEMON_VERSION_INFO, [5:0:5]) if type -p stow > /dev/null && test -d /usr/local/stow ; then AC_MSG_NOTICE([*** Found /usr/local/stow: default install prefix set to /usr/local/stow/${PACKAGE_NAME}-${PACKAGE_VERSION} ***]) -- cgit