chiark / gitweb /
polypath: Log pid of long-running interface monitor
[secnet.git] / polypath.c
index 770ffc2a3d81879681f6bf72042b81e15e3578cf..82492077e9620e827bdfad014d23855bda308631 100644 (file)
@@ -463,7 +463,8 @@ static void child_monitor(struct polypath *st, int childfd)
 }
 
 static void start_subproc(struct polypath *st, void (*make_fdpair)(int[2]),
-                         void (*child)(struct polypath *st, int childfd))
+                         void (*child)(struct polypath *st, int childfd),
+                         const char *desc)
 {
     int pfds[2];
 
@@ -475,6 +476,7 @@ static void start_subproc(struct polypath *st, void (*make_fdpair)(int[2]),
     pid_t pid=fork();
     if (!pid) {
        afterfork();
+       close(pfds[0]);
        child(st,pfds[1]);
        abort();
     }
@@ -486,12 +488,15 @@ static void start_subproc(struct polypath *st, void (*make_fdpair)(int[2]),
     st->monitor_pid=pid;
     st->monitor_fd=pfds[0];
     setnonblock(st->monitor_fd);
+
+    lg_perror(LG,M_NOTICE,0, "%s: spawning %s [pid %ld]",
+             st->uc.cc.cl.description, desc, (long)st->monitor_pid);
 }
 
 static void polypath_phase_startmonitor(void *sst, uint32_t newphase)
 {
     struct polypath *st=sst;
-    start_subproc(st,pipe_cloexec,child_monitor);
+    start_subproc(st,pipe_cloexec,child_monitor,"interface monitor");
     register_for_poll(st,polypath_beforepoll,
                      polypath_afterpoll_monitor,"polypath");
 }
@@ -505,6 +510,15 @@ static void polypath_phase_shutdown(void *sst, uint32_t newphase)
     }
 }
 
+static void polypath_phase_childpersist(void *sst, uint32_t newphase)
+{
+    struct polypath *st=sst;
+    struct interf *interf;
+
+    LIST_FOREACH(interf,&st->interfs,entry)
+       udp_socks_childpersist(&st->uc,&interf->socks);
+}
+
 #undef BAD
 #undef BADE
 
@@ -545,6 +559,7 @@ static list_t *polypath_apply(closure_t *self, struct cloc loc,
 
     add_hook(PHASE_RUN,         polypath_phase_startmonitor,st);
     add_hook(PHASE_SHUTDOWN,    polypath_phase_shutdown,    st);
+    add_hook(PHASE_CHILDPERSIST,polypath_phase_childpersist,st);
 
     return new_closure(&cc->cl);
 }