From: mvs Date: Thu, 5 Oct 2023 18:46:14 +0000 (+0000) Subject: Do log output to stderr while running dhcpd(8) in foreground to make X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1e4d45b401231e852751a30830cfc1b76f182bb4;p=openbsd Do log output to stderr while running dhcpd(8) in foreground to make behaviour in accordance with man page. Introduce '-v' option to make output more verbose. Do a little refactoring to make code more consistent with other daemons like ospfd(8), httpd(8), relayd(8), etc. Feedback from bluhm benno ok bluhm --- diff --git a/usr.sbin/dhcpd/dhcpd.8 b/usr.sbin/dhcpd/dhcpd.8 index d40e3feaf68..c98a953b983 100644 --- a/usr.sbin/dhcpd/dhcpd.8 +++ b/usr.sbin/dhcpd/dhcpd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhcpd.8,v 1.33 2023/09/04 16:11:00 jmc Exp $ +.\" $OpenBSD: dhcpd.8,v 1.34 2023/10/05 18:46:14 mvs Exp $ .\" .\" Copyright (c) 1995, 1996 The Internet Software Consortium. .\" All rights reserved. @@ -36,7 +36,7 @@ .\" see ``http://www.isc.org/''. To learn more about Vixie .\" Enterprises, see ``http://www.vix.com''. .\" -.Dd $Mdocdate: September 4 2023 $ +.Dd $Mdocdate: October 5 2023 $ .Dt DHCPD 8 .Os .Sh NAME @@ -45,7 +45,7 @@ .Sh SYNOPSIS .Nm dhcpd .Bk -words -.Op Fl dfn +.Op Fl dfnv .Op Fl A Ar abandoned_ip_table .Op Fl C Ar changed_ip_table .Op Fl c Ar config-file @@ -239,6 +239,8 @@ is specified, .Nm will bind to that address; otherwise the limited broadcast address (255.255.255.255) is used as the default. +.It Fl v +Produce more verbose output. .It Fl Y Ar synctarget Add target .Ar synctarget diff --git a/usr.sbin/dhcpd/dhcpd.c b/usr.sbin/dhcpd/dhcpd.c index b3562dce34f..f5f8fd1010e 100644 --- a/usr.sbin/dhcpd/dhcpd.c +++ b/usr.sbin/dhcpd/dhcpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.c,v 1.57 2019/08/06 11:07:37 krw Exp $ */ +/* $OpenBSD: dhcpd.c,v 1.58 2023/10/05 18:46:14 mvs Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -87,7 +87,8 @@ char *leased_tab = NULL; int main(int argc, char *argv[]) { - int ch, cftest = 0, daemonize = 1, rdomain = -1, udpsockmode = 0; + int ch, cftest = 0, rdomain = -1, udpsockmode = 0; + int debug = 0, verbose = 0; char *sync_iface = NULL; char *sync_baddr = NULL; u_short sync_port = 0; @@ -98,7 +99,7 @@ main(int argc, char *argv[]) log_setverbose(1); opterr = 0; - while ((ch = getopt(argc, argv, "A:C:L:c:dfl:nu::Y:y:")) != -1) + while ((ch = getopt(argc, argv, "A:C:L:c:dfl:nu::vY:y:")) != -1) switch (ch) { case 'Y': syncsend = 1; @@ -117,7 +118,7 @@ main(int argc, char *argv[]) udpaddr.s_addr = htonl(INADDR_BROADCAST); optreset = optind = opterr = 1; - while ((ch = getopt(argc, argv, "A:C:L:c:dfl:nu::Y:y:")) != -1) + while ((ch = getopt(argc, argv, "A:C:L:c:dfl:nu::vY:y:")) != -1) switch (ch) { case 'A': abandoned_tab = optarg; @@ -132,16 +133,15 @@ main(int argc, char *argv[]) path_dhcpd_conf = optarg; break; case 'd': - daemonize = 0; - break; + /* FALLTHROUGH */ case 'f': - daemonize = 0; + debug = 1; break; case 'l': path_dhcpd_db = optarg; break; case 'n': - daemonize = 0; + debug = 1; cftest = 1; break; case 'u': @@ -152,6 +152,9 @@ main(int argc, char *argv[]) "address: %s", optarg); } break; + case 'v': + verbose = 1; + break; case 'Y': if (sync_addhost(optarg, sync_port) != 0) sync_iface = optarg; @@ -206,11 +209,11 @@ main(int argc, char *argv[]) err(1, "sync init"); } - if (daemonize) - daemon(0, 0); + log_init(debug, LOG_DAEMON); + log_setverbose(verbose); - log_init(0, LOG_DAEMON); /* stop logging to stderr */ - log_setverbose(0); + if (!debug) + daemon(0, 0); if ((pw = getpwnam("_dhcp")) == NULL) fatalx("user \"_dhcp\" not found");