aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2014-05-06 15:26:41 +0200
committerGravatar Christian Hesse <mail@eworm.de>2014-05-06 15:26:41 +0200
commit70f1aa530fd7953c66248a4002d5ba42f5f5e6e9 (patch)
treeb40c9d3d500b75bcf743438037abc5f92ee63e38
parent1bcb85a645e15a1e9e2809e5af7d71f20c4ea2d6 (diff)
downloaddyndhcpd-70f1aa530fd7953c66248a4002d5ba42f5f5e6e9.tar.gz
dyndhcpd-70f1aa530fd7953c66248a4002d5ba42f5f5e6e9.tar.zst
start dhcpd with different pid and leases file
-rw-r--r--config.def.h6
-rw-r--r--dyndhcpd.c14
2 files changed, 18 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h
index 22216e6..8f6e7ec 100644
--- a/config.def.h
+++ b/config.def.h
@@ -13,7 +13,11 @@
/* pathes for config file, first is read, second is written */
#define CONFIG_TEMPLATE "/etc/dyndhcpd/dhcpd.conf"
-#define CONFIG_OUTPUT "/tmp/dhcpd_%s.conf"
+#define CONFIG_OUTPUT "/run/dhcpd-%s.conf"
+
+/* pathes for pid and leases file, these are passed to dhcpd */
+#define PIDFILE "/run/dhcpd-%s.pid"
+#define LEASESFILE "/var/lib/dhcp/dhcp-%s.leases"
#endif /* _CONFIG_H */
diff --git a/dyndhcpd.c b/dyndhcpd.c
index 20f043f..8e3a24b 100644
--- a/dyndhcpd.c
+++ b/dyndhcpd.c
@@ -80,6 +80,7 @@ int main(int argc, char ** argv) {
char * config = NULL;
char * filename = NULL;
FILE * configfile;
+ char * pidfile = NULL, * leasesfile = NULL;
printf("Starting dyndhcpd/" VERSION " (compiled: " __DATE__ ", " __TIME__ ")\n");
@@ -255,10 +256,17 @@ int main(int argc, char ** argv) {
fputs(config, configfile);
fclose(configfile);
+ /* get names for pid and leases file */
+ pidfile = malloc(strlen(PIDFILE) + strlen(interface) + 1);
+ sprintf(pidfile, PIDFILE, interface);
+ leasesfile = malloc(strlen(LEASESFILE) + strlen(interface) + 1);
+ sprintf(leasesfile, LEASESFILE, interface);
+
/* execute dhcp daemon, replace the current process
* dyndhcpd is cleared from memory here and code below is not execuded if
* everything goes well */
- execlp("/usr/bin/dhcpd", "dhcpd", "-f", "-d", "-q", "-4", "-cf", filename, interface, NULL);
+ execlp("/usr/bin/dhcpd", "dhcpd", "-f", "-d", "-q", "-4",
+ "-pf", pidfile, "-lf", leasesfile, "-cf", filename, interface, NULL);
rc = EXIT_SUCCESS;
goto out;
@@ -274,6 +282,10 @@ int main(int argc, char ** argv) {
out:
/* free memory */
+ if (leasesfile != NULL)
+ free(leasesfile);
+ if (pidfile != NULL)
+ free(pidfile);
if (filename != NULL)
free(filename);
if (config != NULL)