This is a discussion on [patch] SIGHUP to make dhcpd reload its configuration within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Hello, i've written a small rough diff against dhcpd, which adds the ability to reload dhcpd.conf upon receiving SIGHUP ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, i've written a small rough diff against dhcpd, which adds the ability to reload dhcpd.conf upon receiving SIGHUP (like done with various daemons, instead of doing pkill daemon && daemon) Currently, it only makes cfile a static instance, opened only once at the first start of the daemon, and never closed (this was needed as dhcpd chroots), and then calls readconf() upon SIGHUP. This is a first patch, which may need several improvements, as i didn't read the whole code of dhcpd, but it seems to work fine here for basic operations (i.e add a host to dhcpd.conf, kill -HUP the daemon, dhclient on the new host, it works) - i'd like people to test it, and comment about it. I don't think the same trick is to do on the lease file, as it is normally not edited by users. Am i in the right direction, or is it the wrong approach to handle this ? Thanks, Landry ? dhcp-options.cat5 ? dhcpd ? dhcpd.cat8 ? dhcpd.conf.cat5 ? dhcpd.leases.cat5 Index: confpars.c ================================================== ================= RCS file: /cvs/src/usr.sbin/dhcpd/confpars.c,v retrieving revision 1.16 diff -u -r1.16 confpars.c --- confpars.c 17 Dec 2006 18:03:33 -0000 1.16 +++ confpars.c 15 Jul 2007 14:26:41 -0000 @@ -41,6 +41,7 @@ #include "dhcpd.h" #include "dhctoken.h" +static FILE* cfile = NULL; /* conf-file :== parameters declarations EOF parameters :== <nil> | parameter | parameters parameter declarations :== <nil> | declaration | declarations declaration */ @@ -48,7 +49,6 @@ int readconf(void) { - FILE *cfile; char *val; int token; int declaration = 0; @@ -67,7 +67,7 @@ root_group.allow_booting = 1; root_group.authoritative = 1; - if ((cfile = fopen(path_dhcpd_conf, "r")) == NULL) + if (cfile == NULL && (cfile = fopen(path_dhcpd_conf, "r")) == NULL) error("Can't open %s: %m", path_dhcpd_conf); do { @@ -80,7 +80,7 @@ declaration); } while (1); token = next_token(&val, cfile); /* Clear the peek buffer */ - fclose(cfile); + /* fclose(cfile); */ return !warnings_occurred; } Index: dhcpd.c ================================================== ================= RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.c,v retrieving revision 1.32 diff -u -r1.32 dhcpd.c --- dhcpd.c 17 Feb 2007 18:27:38 -0000 1.32 +++ dhcpd.c 15 Jul 2007 14:26:41 -0000 @@ -126,6 +126,9 @@ tzset(); + /* Register a handler to reload the configuration file upon SIGHUP */ + (void) signal(SIGHUP, sighup); + time(&cur_time); if (!readconf()) error("Configuration file errors encountered"); @@ -193,6 +196,14 @@ fprintf(stderr, " [-l lease-file]\n"); fprintf(stderr, "\t[if0 [...ifN]]\n"); exit(1); +} + +void +sighup (int signal) +{ + note("Recieived SIGHUP, reloading configuration file"); + if (!readconf()) + error("Configuration file errors encountered"); } void Index: dhcpd.h ================================================== ================= RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.h,v retrieving revision 1.33 diff -u -r1.33 dhcpd.h --- dhcpd.h 22 Feb 2007 07:02:31 -0000 1.33 +++ dhcpd.h 15 Jul 2007 14:26:42 -0000 @@ -499,6 +499,7 @@ extern char *path_dhcpd_db; int main(int, char *[]); +void sighup(int); void cleanup(void); void lease_pinged(struct iaddr, u_int8_t *, int); void lease_ping_timeout(void *); |