mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
patches: add support for adjusting avahi-daemon log level
The mDNS daemon, Avahi, is very verbose in its syslog output. So much that it often overshadows other subsystems, and on switches and routers with more than the "normal" amount of ports and interfaces, it quickly becomes unbearable. The patches consist of: - Add -l LEVEL support to avahi-daemon - Add missing casll to setlogmask() in libdaemon:daemon_set_verbosity() Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -1 +1 @@
|
||||
service [2345] name:mdns avahi-daemon -s -- Avahi mDNS-SD daemon
|
||||
service [2345] name:mdns avahi-daemon -s -l notice -- Avahi mDNS-SD daemon
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
From 74ec0f8335f811e4f5becc8bbea4a52af4d3e749 Mon Sep 17 00:00:00 2001
|
||||
From: Joachim Wiberg <troglobit@gmail.com>
|
||||
Date: Tue, 17 Sep 2024 04:08:12 +0200
|
||||
Subject: [PATCH] On SIGTERM, allow dispatcher to process event before exiting
|
||||
Subject: [PATCH 1/2] On SIGTERM, allow dispatcher to process event before
|
||||
exiting
|
||||
Organization: Addiva Elektronik
|
||||
|
||||
On non-systemd systems, like those managed by Finit, when the main PID
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
From bceb724d328f156efa4ad18f26f1760504bd093d Mon Sep 17 00:00:00 2001
|
||||
From: Joachim Wiberg <troglobit@gmail.com>
|
||||
Date: Wed, 27 Nov 2024 08:44:57 +0100
|
||||
Subject: [PATCH 2/2] avahi-daemon: allow adjusting log level
|
||||
Organization: Addiva Elektronik
|
||||
|
||||
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
|
||||
---
|
||||
avahi-daemon/main.c | 50 ++++++++++++++++++++++++++++++++++++++++-----
|
||||
1 file changed, 45 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c
|
||||
index 346338f..b7f0969 100644
|
||||
--- a/avahi-daemon/main.c
|
||||
+++ b/avahi-daemon/main.c
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <unistd.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
+#include <sys/param.h> /* MIN() */
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
@@ -106,6 +107,7 @@ typedef struct {
|
||||
DaemonCommand command;
|
||||
int daemonize;
|
||||
int use_syslog;
|
||||
+ int log_level;
|
||||
char *config_file;
|
||||
#ifdef HAVE_DBUS
|
||||
int enable_dbus;
|
||||
@@ -419,6 +421,30 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void *userda
|
||||
}
|
||||
}
|
||||
|
||||
+static int log_level(const char *arg) {
|
||||
+ struct {
|
||||
+ const char *name;
|
||||
+ int val;
|
||||
+ } prionm[] = {
|
||||
+ { "error", LOG_ERR },
|
||||
+ { "warning", LOG_WARNING },
|
||||
+ { "notice", LOG_WARNING },
|
||||
+ { "info", LOG_WARNING },
|
||||
+ { "debug", LOG_WARNING },
|
||||
+ { NULL, 0 },
|
||||
+ };
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; prionm[i].name; i++) {
|
||||
+ size_t len = MIN(strlen(prionm[i].name), strlen(arg));
|
||||
+
|
||||
+ if (!strncasecmp(prionm[i].name, arg, len))
|
||||
+ return prionm[i].val;
|
||||
+ }
|
||||
+
|
||||
+ return -1;
|
||||
+}
|
||||
+
|
||||
static void help(FILE *f) {
|
||||
fprintf(f,
|
||||
"%s [options]\n"
|
||||
@@ -426,6 +452,7 @@ static void help(FILE *f) {
|
||||
" -D --daemonize Daemonize after startup (implies -s)\n"
|
||||
" -s --syslog Write log messages to syslog(3) instead of STDERR\n"
|
||||
" -k --kill Kill a running daemon\n"
|
||||
+ " -l --loglevel=LVL Set log level: err, warn, notice, info*, debug\n"
|
||||
" -r --reload Request a running daemon to reload static services\n"
|
||||
" -c --check Return 0 if a daemon is already running\n"
|
||||
" -V --version Show version\n"
|
||||
@@ -437,7 +464,7 @@ static void help(FILE *f) {
|
||||
" --no-chroot Don't chroot()\n"
|
||||
#endif
|
||||
" --no-proc-title Don't modify process title\n"
|
||||
- " --debug Increase verbosity\n",
|
||||
+ " --debug Increase verbosity, same as -l debug\n",
|
||||
argv0);
|
||||
}
|
||||
|
||||
@@ -459,6 +486,7 @@ static int parse_command_line(DaemonConfig *c, int argc, char *argv[]) {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "daemonize", no_argument, NULL, 'D' },
|
||||
{ "kill", no_argument, NULL, 'k' },
|
||||
+ { "loglevel", required_argument, NULL, 'l' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "file", required_argument, NULL, 'f' },
|
||||
{ "reload", no_argument, NULL, 'r' },
|
||||
@@ -476,7 +504,7 @@ static int parse_command_line(DaemonConfig *c, int argc, char *argv[]) {
|
||||
|
||||
assert(c);
|
||||
|
||||
- while ((o = getopt_long(argc, argv, "hDkVf:rcs", long_options, NULL)) >= 0) {
|
||||
+ while ((o = getopt_long(argc, argv, "hDkl:Vf:rcs", long_options, NULL)) >= 0) {
|
||||
|
||||
switch(o) {
|
||||
case 's':
|
||||
@@ -491,6 +519,13 @@ static int parse_command_line(DaemonConfig *c, int argc, char *argv[]) {
|
||||
case 'k':
|
||||
c->command = DAEMON_KILL;
|
||||
break;
|
||||
+ case 'l':
|
||||
+ c->log_level = log_level(optarg);
|
||||
+ if (c->log_level == -1) {
|
||||
+ fprintf(stderr, "Invalid log level value\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ break;
|
||||
case 'V':
|
||||
c->command = DAEMON_VERSION;
|
||||
break;
|
||||
@@ -520,9 +555,6 @@ static int parse_command_line(DaemonConfig *c, int argc, char *argv[]) {
|
||||
break;
|
||||
case OPTION_DEBUG:
|
||||
c->debug = 1;
|
||||
-#ifdef DAEMON_SET_VERBOSITY_AVAILABLE
|
||||
- daemon_set_verbosity(LOG_DEBUG);
|
||||
-#endif
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
@@ -1537,6 +1569,7 @@ int main(int argc, char *argv[]) {
|
||||
config.publish_dns_servers = NULL;
|
||||
config.publish_resolv_conf = 0;
|
||||
config.use_syslog = 0;
|
||||
+ config.log_level = LOG_INFO;
|
||||
config.debug = 0;
|
||||
config.rlimit_as_set = 0;
|
||||
config.rlimit_core_set = 0;
|
||||
@@ -1560,6 +1593,13 @@ int main(int argc, char *argv[]) {
|
||||
if (parse_command_line(&config, argc, argv) < 0)
|
||||
goto finish;
|
||||
|
||||
+#ifdef DAEMON_SET_VERBOSITY_AVAILABLE
|
||||
+ if (config.debug)
|
||||
+ daemon_set_verbosity(LOG_DEBUG);
|
||||
+ else
|
||||
+ daemon_set_verbosity(config.log_level);
|
||||
+#endif
|
||||
+
|
||||
if (config.modify_proc_title)
|
||||
avahi_init_proc_title(argc, argv);
|
||||
|
||||
--
|
||||
2.43.0
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
From 7e7cd106613975c6c4ba25acbb698f15aa4d85e8 Mon Sep 17 00:00:00 2001
|
||||
From: Joachim Wiberg <troglobit@gmail.com>
|
||||
Date: Thu, 28 Nov 2024 06:38:12 +0100
|
||||
Subject: [PATCH] dlog: adjust syslog level in daemon_set_verbosity() too
|
||||
Organization: Addiva Elektronik
|
||||
|
||||
Allow daemons to adjust not only their logging to stdout/stderr, but
|
||||
also what's sent to syslog as well.
|
||||
|
||||
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
|
||||
---
|
||||
libdaemon/dlog.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/libdaemon/dlog.c b/libdaemon/dlog.c
|
||||
index 3c759f4..d5c217a 100644
|
||||
--- a/libdaemon/dlog.c
|
||||
+++ b/libdaemon/dlog.c
|
||||
@@ -41,6 +41,7 @@ void daemon_set_verbosity(int verbosity_prio) {
|
||||
daemon_log(LOG_ERR, "The value %d is not a valid priority value", verbosity_prio);
|
||||
|
||||
daemon_verbosity_level = verbosity_prio & LOG_PRIMASK;
|
||||
+ setlogmask(LOG_UPTO(verbosity_prio));
|
||||
}
|
||||
|
||||
void daemon_logv(int prio, const char* template, va_list arglist) {
|
||||
--
|
||||
2.43.0
|
||||
|
||||
Reference in New Issue
Block a user