Browse code

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.)

Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1500566435-29920-1-git-send-email-steffan.karger@fox-it.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15109.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Steffan Karger authored on 2017/07/21 01:00:35
Showing 7 changed files
... ...
@@ -756,7 +756,7 @@ read_incoming_link(struct context *c)
756 756
                 if (event_timeout_defined(&c->c2.explicit_exit_notification_interval))
757 757
                 {
758 758
                     msg(D_STREAM_ERRORS, "Connection reset during exit notification period, ignoring [%d]", status);
759
-                    openvpn_sleep(1);
759
+                    management_sleep(1);
760 760
                 }
761 761
                 else
762 762
 #endif
... ...
@@ -1969,7 +1969,7 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found)
1969 1969
                 /* if so, close tun, delete routes, then reinitialize tun and add routes */
1970 1970
                 msg(M_INFO, "NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.");
1971 1971
                 do_close_tun(c, true);
1972
-                openvpn_sleep(1);
1972
+                management_sleep(1);
1973 1973
                 c->c2.did_open_tun = do_open_tun(c);
1974 1974
                 update_time();
1975 1975
             }
... ...
@@ -2263,7 +2263,7 @@ socket_restart_pause(struct context *c)
2263 2263
     if (sec)
2264 2264
     {
2265 2265
         msg(D_RESTART, "Restart pause, %d second(s)", sec);
2266
-        openvpn_sleep(sec);
2266
+        management_sleep(sec);
2267 2267
     }
2268 2268
 }
2269 2269
 
... ...
@@ -3997,9 +3997,25 @@ log_history_ref(const struct log_history *h, const int index)
3997 3997
     }
3998 3998
 }
3999 3999
 
4000
+void
4001
+management_sleep(const int n)
4002
+{
4003
+    if (management)
4004
+    {
4005
+        management_event_loop_n_seconds(management, n);
4006
+    }
4007
+    else
4008
+    {
4009
+        sleep(n);
4010
+    }
4011
+}
4012
+
4000 4013
 #else  /* ifdef ENABLE_MANAGEMENT */
4001
-static void
4002
-dummy(void)
4014
+
4015
+void
4016
+management_sleep(const int n)
4003 4017
 {
4018
+    sleep(n);
4004 4019
 }
4020
+
4005 4021
 #endif /* ENABLE_MANAGEMENT */
... ...
@@ -605,4 +605,11 @@ management_bytes_server(struct management *man,
605 605
 #endif /* MANAGEMENT_DEF_AUTH */
606 606
 
607 607
 #endif /* ifdef ENABLE_MANAGEMENT */
608
+
609
+/**
610
+ * A sleep function that services the management layer for n seconds rather
611
+ * than doing nothing.
612
+ */
613
+void management_sleep(const int n);
614
+
608 615
 #endif /* ifndef MANAGE_H */
... ...
@@ -1615,19 +1615,6 @@ make_extended_arg_array(char **p, struct gc_arena *gc)
1615 1615
     }
1616 1616
 }
1617 1617
 
1618
-void
1619
-openvpn_sleep(const int n)
1620
-{
1621
-#ifdef ENABLE_MANAGEMENT
1622
-    if (management)
1623
-    {
1624
-        management_event_loop_n_seconds(management, n);
1625
-        return;
1626
-    }
1627
-#endif
1628
-    sleep(n);
1629
-}
1630
-
1631 1618
 /*
1632 1619
  * Remove security-sensitive strings from control message
1633 1620
  * so that they will not be output to log file.
... ...
@@ -292,12 +292,6 @@ bool env_safe_to_print(const char *str);
292 292
 /* returns true if environmental variable may be passed to an external program */
293 293
 bool env_allowed(const char *str);
294 294
 
295
-/*
296
- * A sleep function that services the management layer for n
297
- * seconds rather than doing nothing.
298
- */
299
-void openvpn_sleep(const int n);
300
-
301 295
 void configure_path(void);
302 296
 
303 297
 const char *sanitize_control_message(const char *str, struct gc_arena *gc);
... ...
@@ -496,7 +496,7 @@ openvpn_getaddrinfo(unsigned int flags,
496 496
                 goto done;
497 497
             }
498 498
 
499
-            openvpn_sleep(fail_wait_interval);
499
+            management_sleep(fail_wait_interval);
500 500
         }
501 501
 
502 502
         ASSERT(res);
... ...
@@ -1193,7 +1193,7 @@ socket_listen_accept(socket_descriptor_t sd,
1193 1193
 
1194 1194
         if (status <= 0)
1195 1195
         {
1196
-            openvpn_sleep(1);
1196
+            management_sleep(1);
1197 1197
             continue;
1198 1198
         }
1199 1199
 
... ...
@@ -1228,7 +1228,7 @@ socket_listen_accept(socket_descriptor_t sd,
1228 1228
                 break;
1229 1229
             }
1230 1230
         }
1231
-        openvpn_sleep(1);
1231
+        management_sleep(1);
1232 1232
     }
1233 1233
 
1234 1234
     if (!nowait && openvpn_close_socket(sd))
... ...
@@ -1374,7 +1374,7 @@ openvpn_connect(socket_descriptor_t sd,
1374 1374
 #endif
1375 1375
                     break;
1376 1376
                 }
1377
-                openvpn_sleep(1);
1377
+                management_sleep(1);
1378 1378
                 continue;
1379 1379
             }
1380 1380