[Openvpn-devel] Remove --writepid file on program exit.

Message ID 20200706190030.49301-1-gert@greenie.muc.de
State Superseded
Headers show
Series [Openvpn-devel] Remove --writepid file on program exit. | expand

Commit Message

Gert Doering July 6, 2020, 9 a.m. UTC
For whatever reason, we never removed the pid file on program exit.

Not only this is unclean, but it also makes testing for "I want this
test case to FAIL" in t_client.sh more annoying to code for "is the
OpenVPN process still around?"...

Do not unlink the file if chroot() is active (might be outside the
chroot arena - testing for realpath etc. is left for someone else).

Signed-off-by: Gert Doering <gert@greenie.muc.de>
---
 src/openvpn/openvpn.c | 6 ++++++
 1 file changed, 6 insertions(+)

Patch

diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c
index dc7001dc..65029e86 100644
--- a/src/openvpn/openvpn.c
+++ b/src/openvpn/openvpn.c
@@ -335,6 +335,12 @@  openvpn_main(int argc, char *argv[])
         while (c.sig->signal_received == SIGHUP);
     }
 
+    /* if we opened a PID file and did not chroot(), unlink() it again */
+    if (c.options.writepid && !c.options.chroot_dir)
+    {
+        platform_unlink(c.options.writepid);
+    }
+
     context_gc_free(&c);
 
 #ifdef ENABLE_MANAGEMENT