summaryrefslogtreecommitdiff
path: root/llmnrd.c
diff options
context:
space:
mode:
authorDiego Santa Cruz <Diego.SantaCruz@spinetix.com>2020-09-09 16:16:49 +0000
committerTobias Klauser <tobias.klauser@gmail.com>2020-09-10 11:53:38 +0200
commite496036b592c7c6d1bc419b5683a6a25bf46e193 (patch)
treee944870ae085aa99ce785f9fcfd9c0f6945f8864 /llmnrd.c
parenta06a6349436ccddb2909715f495b53fe9a0f8969 (diff)
llmnrd: add command line option to log to syslog instead of stdio
When llmnrd daemonizes stdout and stderr are redirected to /dev/null and all logs are lost. This adds a cli option -s / --syslog to send the logs to syslog instead. Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>
Diffstat (limited to 'llmnrd.c')
-rw-r--r--llmnrd.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/llmnrd.c b/llmnrd.c
index 92cd738..1ea241f 100644
--- a/llmnrd.c
+++ b/llmnrd.c
@@ -49,13 +49,14 @@ static int llmnrd_sock_ipv4 = -1;
static int llmnrd_sock_ipv6 = -1;
static int llmnrd_fd_hostname = -1;
-static const char *short_opts = "H:i:p:6dhV";
+static const char *short_opts = "H:i:p:6dshV";
static const struct option long_opts[] = {
{ "hostname", required_argument, NULL, 'H' },
{ "interface", required_argument, NULL, 'i' },
{ "port", required_argument, NULL, 'p' },
{ "ipv6", no_argument, NULL, '6' },
{ "daemonize", no_argument, NULL, 'd' },
+ { "syslog", no_argument, NULL, 's' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 },
@@ -70,6 +71,7 @@ static void __noreturn usage_and_exit(int status)
" -p, --port NUM set port number to listen on (default: %d)\n"
" -6, --ipv6 enable LLMNR name resolution over IPv6\n"
" -d, --daemonize run as daemon in the background\n"
+ " -s, --syslog send all log output to syslog\n"
" -h, --help show this help and exit\n"
" -V, --version show version information and exit\n",
LLMNR_UDP_PORT);
@@ -167,6 +169,10 @@ int main(int argc, char **argv)
case 'd':
daemonize = true;
break;
+ case 's':
+ openlog("llmnrd", LOG_PID, LOG_DAEMON);
+ log_to_syslog();
+ break;
case 'H':
hostname = xstrdup(optarg);
break;