aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-05-17 13:24:20 +0200
committerDr. David von Oheimb <dev@ddvo.net>2021-05-18 14:49:33 +0200
commit9be5f9a8698b0d902ef1281716eda73a4d8478ed (patch)
tree9a6fae021f6d21482b78768b97105da1495e613a
parent78c44e4f819721eb80ad95fddc360a34f9e93118 (diff)
downloadopenssl-9be5f9a8698b0d902ef1281716eda73a4d8478ed.zip
openssl-9be5f9a8698b0d902ef1281716eda73a4d8478ed.tar.gz
openssl-9be5f9a8698b0d902ef1281716eda73a4d8478ed.tar.bz2
Move ossl_sleep() to e_os.h and use it in apps
Fixes #15304 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15308)
-rw-r--r--apps/cmp.c2
-rw-r--r--apps/lib/http_server.c6
-rw-r--r--apps/s_server.c8
-rw-r--r--crypto/bio/bio_lib.c1
-rw-r--r--crypto/cmp/cmp_client.c1
-rw-r--r--e_os.h48
-rw-r--r--include/internal/cryptlib.h48
-rw-r--r--test/helpers/ssltestlib.c3
8 files changed, 56 insertions, 61 deletions
diff --git a/apps/cmp.c b/apps/cmp.c
index 70ca9a3..f289943 100644
--- a/apps/cmp.c
+++ b/apps/cmp.c
@@ -2705,7 +2705,7 @@ int cmp_main(int argc, char **argv)
prog, opt_port, 0, 0);
if (ret == 0) { /* no request yet */
if (retry) {
- sleep(1);
+ ossl_sleep(1000);
retry = 0;
continue;
}
diff --git a/apps/lib/http_server.c b/apps/lib/http_server.c
index e7e84fa..b39f218 100644
--- a/apps/lib/http_server.c
+++ b/apps/lib/http_server.c
@@ -96,7 +96,7 @@ static void killall(int ret, pid_t *kidpids)
if (kidpids[i] != 0)
(void)kill(kidpids[i], SIGTERM);
OPENSSL_free(kidpids);
- sleep(1);
+ ossl_sleep(1000);
exit(ret);
}
@@ -166,7 +166,7 @@ void spawn_loop(const char *prog)
WCOREDUMP(status) ? " (core dumped)" :
# endif
"");
- sleep(1);
+ ossl_sleep(1000);
}
break;
} else if (errno != EINTR) {
@@ -180,7 +180,7 @@ void spawn_loop(const char *prog)
switch (fpid = fork()) {
case -1: /* error */
/* System critically low on memory, pause and try again later */
- sleep(30);
+ ossl_sleep(30000);
break;
case 0: /* child */
OPENSSL_free(kidpids);
diff --git a/apps/s_server.c b/apps/s_server.c
index 80c8a08..292ffbe 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -3057,9 +3057,7 @@ static int www_body(int s, int stype, int prot, unsigned char *context)
continue;
}
#endif
-#if !defined(OPENSSL_SYS_MSDOS)
- sleep(1);
-#endif
+ ossl_sleep(1000);
continue;
}
} else if (i == 0) { /* end of input */
@@ -3486,9 +3484,7 @@ static int rev_body(int s, int stype, int prot, unsigned char *context)
continue;
}
#endif
-#if !defined(OPENSSL_SYS_MSDOS)
- sleep(1);
-#endif
+ ossl_sleep(1000);
continue;
}
} else if (i == 0) { /* end of input */
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
index 5751076..3fa8ff4 100644
--- a/crypto/bio/bio_lib.c
+++ b/crypto/bio/bio_lib.c
@@ -11,7 +11,6 @@
#include <errno.h>
#include <openssl/crypto.h>
#include "bio_local.h"
-#include "internal/cryptlib.h"
/*
* Helper macro for the callback to determine whether an operator expects a
diff --git a/crypto/cmp/cmp_client.c b/crypto/cmp/cmp_client.c
index 54c8f50..dce7d0c 100644
--- a/crypto/cmp/cmp_client.c
+++ b/crypto/cmp/cmp_client.c
@@ -11,6 +11,7 @@
#include "cmp_local.h"
#include "internal/cryptlib.h"
+#include "e_os.h" /* ossl_sleep() */
/* explicit #includes not strictly needed since implied by the above: */
#include <openssl/bio.h>
diff --git a/e_os.h b/e_os.h
index 8bfc1dc..56ea62d 100644
--- a/e_os.h
+++ b/e_os.h
@@ -303,6 +303,54 @@ struct servent *getservbyname(const char *name, const char *proto);
# endif
/* end vxworks */
+/* system-specific variants defining ossl_sleep() */
+#ifdef OPENSSL_SYS_UNIX
+# include <unistd.h>
+static ossl_inline void ossl_sleep(unsigned long millis)
+{
+# ifdef OPENSSL_SYS_VXWORKS
+ struct timespec ts;
+ ts.tv_sec = (long int) (millis / 1000);
+ ts.tv_nsec = (long int) (millis % 1000) * 1000000ul;
+ nanosleep(&ts, NULL);
+# elif defined(__TANDEM)
+# if !defined(_REENTRANT)
+# include <cextdecs.h(PROCESS_DELAY_)>
+ /* HPNS does not support usleep for non threaded apps */
+ PROCESS_DELAY_(millis * 1000);
+# elif defined(_SPT_MODEL_)
+# include <spthread.h>
+# include <spt_extensions.h>
+ usleep(millis * 1000);
+# else
+ usleep(millis * 1000);
+# endif
+# else
+ usleep(millis * 1000);
+# endif
+}
+#elif defined(_WIN32)
+# include <windows.h>
+static ossl_inline void ossl_sleep(unsigned long millis)
+{
+ Sleep(millis);
+}
+#else
+/* Fallback to a busy wait */
+static ossl_inline void ossl_sleep(unsigned long millis)
+{
+ struct timeval start, now;
+ unsigned long elapsedms;
+
+ gettimeofday(&start, NULL);
+ do {
+ gettimeofday(&now, NULL);
+ elapsedms = (((now.tv_sec - start.tv_sec) * 1000000)
+ + now.tv_usec - start.tv_usec) / 1000;
+ } while (elapsedms < millis);
+}
+#endif /* defined OPENSSL_SYS_UNIX */
+
/* ----------------------------- HP NonStop -------------------------------- */
/* Required to support platform variant without getpid() and pid_t. */
# if defined(__TANDEM) && defined(_GUARDIAN_TARGET)
diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h
index 966c8f2..3499025 100644
--- a/include/internal/cryptlib.h
+++ b/include/internal/cryptlib.h
@@ -218,54 +218,6 @@ const void *ossl_bsearch(const void *key, const void *base, int num,
int size, int (*cmp) (const void *, const void *),
int flags);
-/* system-specific variants defining ossl_sleep() */
-#ifdef OPENSSL_SYS_UNIX
-# include <unistd.h>
-static ossl_inline void ossl_sleep(unsigned long millis)
-{
-# ifdef OPENSSL_SYS_VXWORKS
- struct timespec ts;
- ts.tv_sec = (long int) (millis / 1000);
- ts.tv_nsec = (long int) (millis % 1000) * 1000000ul;
- nanosleep(&ts, NULL);
-# elif defined(__TANDEM)
-# if !defined(_REENTRANT)
-# include <cextdecs.h(PROCESS_DELAY_)>
- /* HPNS does not support usleep for non threaded apps */
- PROCESS_DELAY_(millis * 1000);
-# elif defined(_SPT_MODEL_)
-# include <spthread.h>
-# include <spt_extensions.h>
- usleep(millis * 1000);
-# else
- usleep(millis * 1000);
-# endif
-# else
- usleep(millis * 1000);
-# endif
-}
-#elif defined(_WIN32)
-# include <windows.h>
-static ossl_inline void ossl_sleep(unsigned long millis)
-{
- Sleep(millis);
-}
-#else
-/* Fallback to a busy wait */
-static ossl_inline void ossl_sleep(unsigned long millis)
-{
- struct timeval start, now;
- unsigned long elapsedms;
-
- gettimeofday(&start, NULL);
- do {
- gettimeofday(&now, NULL);
- elapsedms = (((now.tv_sec - start.tv_sec) * 1000000)
- + now.tv_usec - start.tv_usec) / 1000;
- } while (elapsedms < millis);
-}
-#endif /* defined OPENSSL_SYS_UNIX */
-
char *ossl_sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text,
const char *sep, size_t max_len);
char *ossl_ipaddr_to_asc(unsigned char *p, int len);
diff --git a/test/helpers/ssltestlib.c b/test/helpers/ssltestlib.c
index daa0416..52b1799 100644
--- a/test/helpers/ssltestlib.c
+++ b/test/helpers/ssltestlib.c
@@ -10,10 +10,9 @@
#include <string.h>
#include "internal/nelem.h"
-#include "internal/cryptlib.h" /* for ossl_sleep() */
#include "ssltestlib.h"
#include "../testutil.h"
-#include "e_os.h"
+#include "e_os.h" /* for ossl_sleep() etc. */
#ifdef OPENSSL_SYS_UNIX
# include <unistd.h>