Gert Doering has uploaded a new patch set (#3) to the change originally created by Frank Lichtenheld. ( https://gerrit.openvpn.net/c/openvpn/+/2200?usp=email )
The following approvals got outdated and were removed: Code-Review+2 by Răzvan Cojocaru Change subject: manage: Switch all sleep methods to unsigned ...................................................................... manage: Switch all sleep methods to unsigned That is consistent with sleep(3). Change-Id: I34dd7d46c9bc15e32f233741c525759715bb847c Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: Razvan Cojocaru <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2200 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg41512.html Signed-off-by: Gert Doering <[email protected]> --- M src/openvpn/manage.c M src/openvpn/manage.h M src/openvpn/resolve.c M src/openvpn/win32.c M src/openvpn/win32.h M tests/unit_tests/openvpn/mock_management.c 6 files changed, 34 insertions(+), 77 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/00/2200/3 diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index ae30930..86c498e 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -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 + } +} diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index 82c0caa..697f830 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -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 */ diff --git a/src/openvpn/resolve.c b/src/openvpn/resolve.c index b8d9899..544e5ea 100644 --- a/src/openvpn/resolve.c +++ b/src/openvpn/resolve.c @@ -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; diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index 079869f..f10c16d 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -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)) diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index 39ff7d8..8152e71 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -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. diff --git a/tests/unit_tests/openvpn/mock_management.c b/tests/unit_tests/openvpn/mock_management.c index f572dbb..aea43da 100644 --- a/tests/unit_tests/openvpn/mock_management.c +++ b/tests/unit_tests/openvpn/mock_management.c @@ -59,6 +59,6 @@ #endif void -management_sleep(const int n) +management_sleep(const unsigned int n) { } -- To view, visit https://gerrit.openvpn.net/c/openvpn/+/2200?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.openvpn.net/settings?usp=email Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I34dd7d46c9bc15e32f233741c525759715bb847c Gerrit-Change-Number: 2200 Gerrit-PatchSet: 3 Gerrit-Owner: Frank Lichtenheld <[email protected]> Gerrit-Reviewer: Arne Schwabe <[email protected]> Gerrit-Reviewer: Răzvan Cojocaru <[email protected]> Gerrit-CC: openvpn-devel <[email protected]>
_______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
