@@ -3615,32 +3615,23 @@
}
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
/*
* Process the management event loop for sec seconds
*/
void
-management_event_loop_n_seconds(struct management *man, int sec)
+management_event_loop_n_seconds(struct management *man, unsigned int sec)
{
if (man_standalone_ok(man))
{
volatile int signal_received = 0;
const bool standalone_disabled_save = man->persist.standalone_disabled;
- time_t expire = 0;
+ time_t expire = now + sec;
/* This is so M_CLIENT messages will be correctly passed through msg() */
man->persist.standalone_disabled = false;
/* set expire time */
update_time();
- if (sec >= 0)
- {
- expire = now + sec;
- }
/* if no client connection, wait for one */
man_wait_for_client_connection(man, &signal_received, expire, 0);
@@ -3662,7 +3653,7 @@
return;
}
update_time();
- } while (expire && expire > now);
+ } while (expire > now);
/* revert state */
man->persist.standalone_disabled = standalone_disabled_save;
@@ -4026,7 +4017,7 @@
* Return true if the caller should not sleep for an additional time interval.
*/
bool
-management_hold(struct management *man, int holdtime)
+management_hold(struct management *man, unsigned int holdtime)
{
if (management_would_hold(man))
{
@@ -4044,7 +4035,7 @@
if (!signal_received)
{
struct buffer out = alloc_buf_gc(128, &gc);
- buf_printf(&out, ">HOLD:Waiting for hold release:%d", holdtime);
+ buf_printf(&out, ">HOLD:Waiting for hold release:%u", holdtime);
man->persist.special_state_msg = BSTR(&out);
msg(M_CLIENT, "%s", man->persist.special_state_msg);
@@ -4244,8 +4235,9 @@
log_history_obj_init(struct log_history *h, int capacity)
{
CLEAR(*h);
+ ASSERT(capacity > 0);
h->capacity = capacity;
- ALLOC_ARRAY_CLEAR(h->array, struct log_entry, capacity);
+ ALLOC_ARRAY_CLEAR(h->array, struct log_entry, (size_t)capacity);
}
struct log_history *
@@ -4332,34 +4324,6 @@
}
void
-management_sleep(const int n)
-{
- if (n < 0)
- {
- return;
- }
- else if (management)
- {
- management_event_loop_n_seconds(management, n);
- }
- else
- {
-#ifdef _WIN32
- win32_sleep(n);
-#else
- if (n > 0)
- {
- sleep(n);
- }
-#endif
- }
-}
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
-void
management_check_bytecount_client(struct context *c, struct management *man, struct timeval *timeval)
{
if (man->persist.callback.flags & MCF_SERVER)
@@ -4490,30 +4454,28 @@
gc_free(&gc);
return false;
}
-#else /* ifdef ENABLE_MANAGEMENT */
+#endif /* ENABLE_MANAGEMENT */
#include "win32.h"
-#if !defined(_WIN32) && (defined(__GNUC__) || defined(__clang__))
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
void
-management_sleep(const int n)
+management_sleep(const unsigned int n)
{
-#ifdef _WIN32
- win32_sleep(n);
-#else
- if (n > 0)
+#ifdef ENABLE_MANAGEMENT
+ if (management)
{
- sleep(n);
+ management_event_loop_n_seconds(management, n);
}
-#endif /* ifdef _WIN32 */
-}
-
-#if !defined(_WIN32) && (defined(__GNUC__) || defined(__clang__))
-#pragma GCC diagnostic pop
+ else
#endif
-
-#endif /* ENABLE_MANAGEMENT */
+ {
+#ifdef _WIN32
+ win32_sleep(n);
+#else
+ if (n > 0)
+ {
+ sleep(n);
+ }
+#endif
+ }
+}
@@ -387,9 +387,9 @@
bool management_would_hold(struct management *man);
-bool management_hold(struct management *man, int holdtime);
+bool management_hold(struct management *man, unsigned int holdtime);
-void management_event_loop_n_seconds(struct management *man, int sec);
+void management_event_loop_n_seconds(struct management *man, unsigned int sec);
void management_up_down(const struct management *man, const char *updown, const struct env_set *es);
@@ -522,6 +522,6 @@
* A sleep function that services the management layer for n seconds rather
* than doing nothing.
*/
-void management_sleep(const int n);
+void management_sleep(const unsigned int n);
#endif /* ifndef MANAGE_H */
@@ -161,13 +161,13 @@
}
status = getaddrinfo(hostname, servname, &hints, res);
-
- if (status != 0) /* parse as numeric address failed? */
+ /* parse as numeric address failed? */
+ if (status != 0)
{
- const int fail_wait_interval = 5; /* seconds */
+ const unsigned int fail_wait_interval = 5; /* seconds */
/* Add +4 to cause integer division rounding up (1 + 4) = 5, (0+4)/5=0 */
int resolve_retries =
- (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
+ (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / (int)fail_wait_interval);
const char *fmt;
msglvl_t level = 0;
@@ -1533,13 +1533,8 @@
}
void
-win32_sleep(const int n)
+win32_sleep(const unsigned int n)
{
- if (n < 0)
- {
- return;
- }
-
/* Sleep() is not interruptible. Use a WAIT_OBJECT to catch signal */
if (!HANDLE_DEFINED(win32_signal.in.read))
@@ -323,7 +323,7 @@
int openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags);
/* Sleep that can be interrupted by signals and exit event */
-void win32_sleep(const int n);
+void win32_sleep(const unsigned int n);
/**
* @brief Fetches a registry value for OpenVPN registry key.
@@ -59,6 +59,6 @@
#endif
void
-management_sleep(const int n)
+management_sleep(const unsigned int n)
{
}