Skip to contentSkip to conversation

Move openvpn_sleep() to manage.c

PATCH In review Steffan Karger 3 participants 4 messages Jul 20, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Move openvpn_sleep() to manage.c

openvpn_sleep() is basically "service the management interface for x seconds, then return". Therefore, manage.c is a more suitable location than the random collection of unrelated stuff called misc.c.

(I think we should find a better place for everything currently in misc.c, and get rid of it all together. This patch is part of that effort.)

---
 src/openvpn/forward.c |  2 +-
 src/openvpn/init.c    |  4 ++--
 src/openvpn/manage.c  | 20 ++++++++++++++++++--
 src/openvpn/manage.h  |  7 +++++++
 src/openvpn/misc.c    | 13 -------------
 src/openvpn/misc.h    |  6 ------
 src/openvpn/socket.c  |  8 ++++----
 7 files changed, 32 insertions(+), 28 deletions(-)
src/openvpn/forward.c +1 -1
index 371ddca..c45d125 100644
@@ -756,7 +756,7 @@ read_incoming_link(struct context *c)
                 if (event_timeout_defined(&c->c2.explicit_exit_notification_interval))
                 {
                     msg(D_STREAM_ERRORS, "Connection reset during exit notification period, ignoring [%d]", status);
-                    openvpn_sleep(1);
+                    management_sleep(1);
                 }
                 else
 #endif
src/openvpn/init.c +2 -2
index a54307a..bc3b81e 100644
@@ -1969,7 +1969,7 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found)
                 /* if so, close tun, delete routes, then reinitialize tun and add routes */
                 msg(M_INFO, "NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.");
                 do_close_tun(c, true);
-                openvpn_sleep(1);
+                management_sleep(1);
                 c->c2.did_open_tun = do_open_tun(c);
                 update_time();
             }
@@ -2263,7 +2263,7 @@ socket_restart_pause(struct context *c)
     if (sec)
     {
         msg(D_RESTART, "Restart pause, %d second(s)", sec);
-        openvpn_sleep(sec);
+        management_sleep(sec);
     }
 }
 
src/openvpn/manage.c +18 -2
index 2b85d25..13be6f6 100644
@@ -3997,9 +3997,25 @@ log_history_ref(const struct log_history *h, const int index)
     }
 }
 
+void
+management_sleep(const int n)
+{
+    if (management)
+    {
+        management_event_loop_n_seconds(management, n);
+    }
+    else
+    {
+        sleep(n);
+    }
+}
+
 #else  /* ifdef ENABLE_MANAGEMENT */
-static void
-dummy(void)
+
+void
+management_sleep(const int n)
 {
+    sleep(n);
 }
+
 #endif /* ENABLE_MANAGEMENT */
src/openvpn/manage.h +7 -0
index 542cc07..676be64 100644
@@ -605,4 +605,11 @@ management_bytes_server(struct management *man,
 #endif /* MANAGEMENT_DEF_AUTH */
 
 #endif /* ifdef ENABLE_MANAGEMENT */
+
+/**
+ * A sleep function that services the management layer for n seconds rather
+ * than doing nothing.
+ */
+void management_sleep(const int n);
+
 #endif /* ifndef MANAGE_H */
src/openvpn/misc.c +0 -13
index f6d6c6a..ae96aa6 100644
@@ -1615,19 +1615,6 @@ make_extended_arg_array(char **p, struct gc_arena *gc)
     }
 }
 
-void
-openvpn_sleep(const int n)
-{
-#ifdef ENABLE_MANAGEMENT
-    if (management)
-    {
-        management_event_loop_n_seconds(management, n);
-        return;
-    }
-#endif
-    sleep(n);
-}
-
 /*
  * Remove security-sensitive strings from control message
  * so that they will not be output to log file.
src/openvpn/misc.h +0 -6
index bc267d7..32b64e8 100644
@@ -292,12 +292,6 @@ bool env_safe_to_print(const char *str);
 /* returns true if environmental variable may be passed to an external program */
 bool env_allowed(const char *str);
 
-/*
- * A sleep function that services the management layer for n
- * seconds rather than doing nothing.
- */
-void openvpn_sleep(const int n);
-
 void configure_path(void);
 
 const char *sanitize_control_message(const char *str, struct gc_arena *gc);
src/openvpn/socket.c +4 -4
index 846df04..6e01fe1 100644
@@ -496,7 +496,7 @@ openvpn_getaddrinfo(unsigned int flags,
                 goto done;
             }
 
-            openvpn_sleep(fail_wait_interval);
+            management_sleep(fail_wait_interval);
         }
 
         ASSERT(res);
@@ -1193,7 +1193,7 @@ socket_listen_accept(socket_descriptor_t sd,
 
         if (status <= 0)
         {
-            openvpn_sleep(1);
+            management_sleep(1);
             continue;
         }
 
@@ -1228,7 +1228,7 @@ socket_listen_accept(socket_descriptor_t sd,
                 break;
             }
         }
-        openvpn_sleep(1);
+        management_sleep(1);
     }
 
     if (!nowait && openvpn_close_socket(sd))
@@ -1374,7 +1374,7 @@ openvpn_connect(socket_descriptor_t sd,
 #endif
                     break;
                 }
-                openvpn_sleep(1);
+                management_sleep(1);
                 continue;
             }
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 fixup: also change missed openvpn_sleep() occurrences

45b2af9c missed some openvpn_sleep() occurrences in platform-specific code in tun.c - fix that.

---
 src/openvpn/tun.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/openvpn/tun.c +4 -4
index 68fb488..3639718 100644
@@ -1862,7 +1862,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
     if (oldtunfd >=0 && android_method == ANDROID_OPEN_AFTER_CLOSE)
     {
         close(oldtunfd);
-        openvpn_sleep(2);
+        management_sleep(2);
     }
 
     if (oldtunfd >=0  && android_method == ANDROID_KEEP_OLD_TUN)
@@ -4999,7 +4999,7 @@ netsh_command(const struct argv *a, int n, int msglevel)
     for (i = 0; i < n; ++i)
     {
         bool status;
-        openvpn_sleep(1);
+        management_sleep(1);
         netcmd_semaphore_lock();
         argv_msg_prefix(M_INFO, a, "NETSH");
         status = openvpn_execve_check(a, NULL, 0, "ERROR: netsh command failed");
@@ -5008,7 +5008,7 @@ netsh_command(const struct argv *a, int n, int msglevel)
         {
             return;
         }
-        openvpn_sleep(4);
+        management_sleep(4);
     }
     msg(msglevel, "NETSH: command failed");
 }
@@ -5991,7 +5991,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
         if (s > 0)
         {
             msg(M_INFO, "Sleeping for %d seconds...", s);
-            openvpn_sleep(s);
+            management_sleep(s);
         }
     }
 
Signature · 1 line
2.7.4
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: fixup: also change missed openvpn_sleep() occurrences

ACK.

Your patch has been applied to the master and release/2.4 branch.

commit cdb262a6c78a29349789b7cf1813feaf7cc6e8c8 (master) commit 4a04be8b53df37cac0cd4df4d23a1e2210902232 (release/2.4)

Author: Steffan Karger
Date:   Thu Jul 20 21:17:02 2017 +0200
     fixup: also change missed openvpn_sleep() occurrences

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg15111.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw
In reply to Steffan Karger

ACK.

Your patch has been applied to the master and release/2.4 branch.

commit 45b2af9c7719d9a40c6c2b9d0693e4db0d917a04 (master) commit 80ece420966b21b9a6cee2a36a19e3d200dcd3e7 (release/2.4)

Author: Steffan Karger
Date:   Thu Jul 20 18:00:35 2017 +0200
     Move openvpn_sleep() to manage.c

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg15109.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering