Commit Diff
Diff:
f199772ae75419e09da38055b9611e6a0bab8882
1b77673cb35200927c99dbf091bc8546a72579a6
Commit:
1b77673cb35200927c99dbf091bc8546a72579a6
Tree:
ca5ecded0a6f9c3708abc0f9c459c84b9b14036e
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Tue Jul 14 16:14:35 2020 UTC
Message:
move two shared memory segments into the forward child, leaving one global. This one is then unmapped in tcp and udp parsers unless the OS is OpenBSD because OpenBSD already has minherit'ed the the closure of this in parser childs.
blob - f4303a0b0feb1cd0707435f32566aefe249961ff
blob + a923bf195fe9f59c80fef7bc33724b52cdd84f0a
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: delphinusdnsd.c,v 1.125 2020/07/14 14:46:23 pjp Exp $
+ * $Id: delphinusdnsd.c,v 1.126 2020/07/14 16:14:35 pjp Exp $
*/
@@ -1011,6 +1011,8 @@ main(int argc, char *argv[], char *environ[])
/* start our forwarding process */
if (forward) {
+ /* initialize the only global shared memory segment */
+
shsize = 16 + (SHAREDMEMSIZE * sizeof(struct sf_imsg));
shptr = mmap(NULL, shsize, PROT_READ | PROT_WRITE, MAP_SHARED |\
@@ -1029,42 +1031,7 @@ main(int argc, char *argv[], char *environ[])
cfg->shptr = shptr;
cfg->shptrsize = shsize;
- shsize = 16 + (SHAREDMEMSIZE * sizeof(struct rr_imsg));
- shptr = mmap(NULL, shsize, PROT_READ | PROT_WRITE, MAP_SHARED |\
- MAP_ANON, -1, 0);
-
- if (shptr == MAP_FAILED) {
- dolog(LOG_ERR, "failed to setup mmap segment, exit\n");
- exit(1);
- }
-
- /* initialize */
- for (ri = (struct rr_imsg *)&shptr[0], j = 0; j < SHAREDMEMSIZE; j++, ri++) {
- pack32((char *)&ri->u.s.read, 1);
- }
-
- cfg->shptr2 = shptr;
- cfg->shptr2size = shsize;
-
- shsize = 16 + (SHAREDMEMSIZE3 * sizeof(struct pkt_imsg));
-
- shptr = mmap(NULL, shsize, PROT_READ | PROT_WRITE, MAP_SHARED |\
- MAP_ANON, -1, 0);
-
- if (shptr == MAP_FAILED) {
- dolog(LOG_ERR, "failed to setup mmap segment, exit\n");
- exit(1);
- }
-
- /* initialize */
- for (pi = (struct pkt_imsg *)&shptr[0], j = 0; j < SHAREDMEMSIZE3; j++, pi++) {
- pack32((char *)&pi->pkt_s.read, 1);
- }
-
- cfg->shptr3 = shptr;
- cfg->shptr3size = shsize;
-
switch (pid = fork()) {
case -1:
dolog(LOG_ERR, "fork() failed: %s\n", strerror(errno));
@@ -1077,6 +1044,43 @@ main(int argc, char *argv[], char *environ[])
exit(1);
}
+ /* initialize shared memory for forward here */
+ shsize = 16 + (SHAREDMEMSIZE * sizeof(struct rr_imsg));
+
+ shptr = mmap(NULL, shsize, PROT_READ | PROT_WRITE, MAP_SHARED |\
+ MAP_ANON, -1, 0);
+
+ if (shptr == MAP_FAILED) {
+ dolog(LOG_ERR, "failed to setup mmap segment, exit\n");
+ exit(1);
+ }
+
+ /* initialize */
+ for (ri = (struct rr_imsg *)&shptr[0], j = 0; j < SHAREDMEMSIZE; j++, ri++) {
+ pack32((char *)&ri->u.s.read, 1);
+ }
+
+ cfg->shptr2 = shptr;
+ cfg->shptr2size = shsize;
+
+ shsize = 16 + (SHAREDMEMSIZE3 * sizeof(struct pkt_imsg));
+
+ shptr = mmap(NULL, shsize, PROT_READ | PROT_WRITE, MAP_SHARED |\
+ MAP_ANON, -1, 0);
+
+ if (shptr == MAP_FAILED) {
+ dolog(LOG_ERR, "failed to setup mmap segment, exit\n");
+ exit(1);
+ }
+
+ /* initialize */
+ for (pi = (struct pkt_imsg *)&shptr[0], j = 0; j < SHAREDMEMSIZE3; j++, pi++) {
+ pack32((char *)&pi->pkt_s.read, 1);
+ }
+
+ cfg->shptr3 = shptr;
+ cfg->shptr3size = shsize;
+
/* chroot to the drop priv user home directory */
#ifdef DEFAULT_LOCATION
if (drop_privs(DEFAULT_LOCATION, pw) < 0) {
@@ -1587,10 +1591,6 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
#if __OpenBSD__
minherit(cfg->shptr, cfg->shptrsize,
MAP_INHERIT_NONE);
- minherit(cfg->shptr2, cfg->shptr2size,
- MAP_INHERIT_NONE);
- minherit(cfg->shptr3, cfg->shptr3size,
- MAP_INHERIT_NONE);
#endif
}
@@ -1610,10 +1610,6 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
#if __OpenBSD__
minherit(cfg->shptr, cfg->shptrsize,
MAP_INHERIT_NONE);
- minherit(cfg->shptr2, cfg->shptr2size,
- MAP_INHERIT_NONE);
- minherit(cfg->shptr3, cfg->shptr3size,
- MAP_INHERIT_NONE);
#endif
}
@@ -1649,6 +1645,14 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
dolog(LOG_ERR, "fork(): %s\n", strerror(errno));
exit(1);
case 0:
+#ifndef __OpenBSD__
+ /* OpenBSD has minherit() */
+ if (munmap(cfg->shptr, cfg->shptrsize) == -1) {
+ dolog(LOG_INFO, "unmapping shptr failed: %s\n", \
+ strerror(errno));
+ }
+#endif
+ cfg->shptrsize = 0;
/* close udp decriptors */
for (i = 0; i < cfg->sockcount; i++) {
close(cfg->udp[i]);
@@ -2676,6 +2680,14 @@ tcploop(struct cfg *cfg, struct imsgbuf *ibuf, struct
dolog(LOG_ERR, "fork(): %s\n", strerror(errno));
exit(1);
case 0:
+#ifndef __OpenBSD__
+ /* OpenBSD has minherit() */
+ if (munmap(cfg->shptr, cfg->shptrsize) == -1) {
+ dolog(LOG_INFO, "unmapping shptr failed: %s\n", \
+ strerror(errno));
+ }
+#endif
+ cfg->shptrsize = 0;
for (i = 0; i < cfg->sockcount; i++) {
close(cfg->tcp[i]);
}
blob - e5c168e55b55084931d925c4e59bc27742d60964
blob + 45282ebe3840eea91c195dd0cee23400a6fa61b5
--- forward.c
+++ forward.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: forward.c,v 1.23 2020/07/14 14:46:23 pjp Exp $
+ * $Id: forward.c,v 1.24 2020/07/14 16:14:35 pjp Exp $
*/
#include <sys/types.h>
@@ -340,6 +340,15 @@ forwardloop(ddDB *db, struct cfg *cfg, struct imsgbuf
ddd_shutdown();
exit(1);
case 0:
+#ifndef __OpenBSD__
+ /* OpenBSD has minherit() */
+ if (munmap(cfg->shptr, cfg->shptrsize) == -1) {
+ dolog(LOG_INFO, "unmapping shptr failed: %s\n", \
+ strerror(errno));
+ }
+#endif
+ cfg->shptrsize = 0;
+
for (i = 0; i < cfg->sockcount; i++)
close(cfg->dup[i]);
repomaster@centroid.eu