[Openvpn-devel,S] Change in openvpn[master]: WIP print child exit code

Message ID f63815f62b09c7b4ff26937ab9200d8b032b407a-HTML@gerrit.openvpn.net
State Superseded
Headers show
Series [Openvpn-devel,S] Change in openvpn[master]: WIP print child exit code | expand

Commit Message

plaisthos (Code Review) Sept. 24, 2024, 8:26 a.m. UTC
Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/767?usp=email

to review the following change.


Change subject: WIP print child exit code
......................................................................

WIP print child exit code

Change-Id: I188923efc0f72b2038f1470740415ce50d07580b
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
M src/openvpn/tun_afunix.c
1 file changed, 30 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/67/767/1

Patch

diff --git a/src/openvpn/tun_afunix.c b/src/openvpn/tun_afunix.c
index a2d8552..e26e1d8 100644
--- a/src/openvpn/tun_afunix.c
+++ b/src/openvpn/tun_afunix.c
@@ -48,6 +48,31 @@ 
 #include <stdlib.h>
 
 static void
+child_handler(int sig)
+{
+    int status;
+    pid_t pid;
+
+    /* EEEEXTEERMINAAATE! */
+    while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
+    {
+        msg(M_INFO, "Child process PID %d died with status code %d", pid, status);
+    }
+}
+
+static void
+enable_signal_handler(void)
+{
+    /* Establish handler. */
+    struct sigaction sa;
+    sigemptyset(&sa.sa_mask);
+    sa.sa_flags = 0;
+    sa.sa_handler = child_handler;
+
+    sigaction(SIGCHLD, &sa, NULL);
+}
+
+static void
 tun_afunix_exec_child(const char *dev_node, struct tuntap *tt, struct env_set *env)
 {
     struct argv argv = argv_new();
@@ -59,10 +84,13 @@ 
     argv_printf(&argv, "%s", program);
 
     argv_msg(M_INFO, &argv);
+
+    enable_signal_handler();
     tt->afunix.childprocess = openvpn_execve_check(&argv, env, S_NOWAITPID,
                                                    "ERROR: failure executing "
                                                    "process for tun");
     argv_free(&argv);
+
 }
 
 void
@@ -120,6 +148,8 @@ 
     gc_free(&gc);
 }
 
+
+
 void
 close_tun_afunix(struct tuntap *tt)
 {