aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2019-11-17 20:48:27 +0100
committerGilles Chehade <gilles@poolp.org>2019-11-17 20:48:27 +0100
commit8fd35cfe468c22f8cc69bce7b65c59e0779fbad9 (patch)
tree95a72444bd4d7ce89bcef1a690ea409431c01943
parentfix arc4random.c (diff)
downloadOpenSMTPD-8fd35cfe468c22f8cc69bce7b65c59e0779fbad9.tar.xz
OpenSMTPD-8fd35cfe468c22f8cc69bce7b65c59e0779fbad9.zip
conditionally build nanosec() and usleep()
-rw-r--r--configure.ac2
-rw-r--r--openbsd-compat/Makefile.am12
-rw-r--r--openbsd-compat/bsd-misc.c42
-rw-r--r--openbsd-compat/bsd-misc.h21
-rw-r--r--openbsd-compat/nanosleep.c63
-rw-r--r--openbsd-compat/openbsd-compat.h21
-rw-r--r--openbsd-compat/usleep.c43
7 files changed, 139 insertions, 65 deletions
diff --git a/configure.ac b/configure.ac
index 4cfd5cd8..ab415578 100644
--- a/configure.ac
+++ b/configure.ac
@@ -561,6 +561,7 @@ AC_CHECK_FUNCS([ \
inet_ntop \
malloc_conceal \
memmove \
+ nanosleep \
nsleep \
pidfile \
reallocarray \
@@ -589,6 +590,7 @@ AC_CHECK_FUNCS([ \
sysconf \
tcgetpgrp \
time \
+ usleep \
vasprintf \
vsnprintf \
waitpid \
diff --git a/openbsd-compat/Makefile.am b/openbsd-compat/Makefile.am
index ca21423b..2df97bed 100644
--- a/openbsd-compat/Makefile.am
+++ b/openbsd-compat/Makefile.am
@@ -86,8 +86,8 @@ if NEED_INET_NET_PTON
libopenbsd_compat_a_SOURCES += inet_net_pton.c
endif
-if NEED_SIGNAL
-libopenbsd_compat_a_SOURCES += signal.c
+if NEED_NANOSLEEP
+libopenbsd_compat_a_SOURCES += nanosleep.c
endif
if NEED_PIDFILE
@@ -114,6 +114,10 @@ if NEED_SETRESUID
libopenbsd_compat_a_SOURCES += setresuid.c
endif
+if NEED_SIGNAL
+libopenbsd_compat_a_SOURCES += signal.c
+endif
+
if NEED_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM
libopenbsd_compat_a_SOURCES += SSL_CTX_use_certificate_chain_mem.c
endif
@@ -150,6 +154,10 @@ if NEED_STRNLEN
libopenbsd_compat_a_SOURCES += strnlen.c
endif
+if NEED_USLEEP
+libopenbsd_compat_a_SOURCES += usleep.c
+endif
+
if NEED_VIS
libopenbsd_compat_a_SOURCES += vis.c
endif
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 5cf1c0e8..ccbcfa77 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -78,45 +78,3 @@ int setegid(uid_t egid)
return(setresgid(-1, egid, -1));
}
#endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
-
-#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
-int nanosleep(const struct timespec *req, struct timespec *rem)
-{
- int rc, saverrno;
- extern int errno;
- struct timeval tstart, tstop, tremain, time2wait;
-
- TIMESPEC_TO_TIMEVAL(&time2wait, req);
- (void) gettimeofday(&tstart, NULL);
- rc = select(0, NULL, NULL, NULL, &time2wait);
- if (rc == -1) {
- saverrno = errno;
- (void) gettimeofday (&tstop, NULL);
- errno = saverrno;
- tremain.tv_sec = time2wait.tv_sec -
- (tstop.tv_sec - tstart.tv_sec);
- tremain.tv_usec = time2wait.tv_usec -
- (tstop.tv_usec - tstart.tv_usec);
- tremain.tv_sec += tremain.tv_usec / 1000000L;
- tremain.tv_usec %= 1000000L;
- } else {
- tremain.tv_sec = 0;
- tremain.tv_usec = 0;
- }
- if (rem != NULL)
- TIMEVAL_TO_TIMESPEC(&tremain, rem);
-
- return(rc);
-}
-#endif
-
-#if !defined(HAVE_USLEEP)
-int usleep(unsigned int useconds)
-{
- struct timespec ts;
-
- ts.tv_sec = useconds / 1000000;
- ts.tv_nsec = (useconds % 1000000) * 1000;
- return nanosleep(&ts, NULL);
-}
-#endif
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index bfcb2763..d90653ab 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -35,25 +35,4 @@ int seteuid(uid_t);
int setegid(uid_t);
#endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
-#ifndef HAVE_STRUCT_TIMEVAL
-struct timeval {
- long tv_sec;
- long tv_usec;
-}
-#endif /* HAVE_STRUCT_TIMEVAL */
-
-#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
-#ifndef HAVE_STRUCT_TIMESPEC
-struct timespec {
- time_t tv_sec;
- long tv_nsec;
-};
-#endif
-int nanosleep(const struct timespec *, struct timespec *);
-#endif
-
-#ifndef HAVE_USLEEP
-int usleep(unsigned int useconds);
-#endif
-
#endif /* _BSD_MISC_H */
diff --git a/openbsd-compat/nanosleep.c b/openbsd-compat/nanosleep.c
new file mode 100644
index 00000000..1256c0b5
--- /dev/null
+++ b/openbsd-compat/nanosleep.c
@@ -0,0 +1,63 @@
+
+/*
+ * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "includes.h"
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+
+#include <err.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+int
+nanosleep(const struct timespec *req, struct timespec *rem)
+{
+ int rc, saverrno;
+ extern int errno;
+ struct timeval tstart, tstop, tremain, time2wait;
+
+ TIMESPEC_TO_TIMEVAL(&time2wait, req);
+ (void) gettimeofday(&tstart, NULL);
+ rc = select(0, NULL, NULL, NULL, &time2wait);
+ if (rc == -1) {
+ saverrno = errno;
+ (void) gettimeofday (&tstop, NULL);
+ errno = saverrno;
+ tremain.tv_sec = time2wait.tv_sec -
+ (tstop.tv_sec - tstart.tv_sec);
+ tremain.tv_usec = time2wait.tv_usec -
+ (tstop.tv_usec - tstart.tv_usec);
+ tremain.tv_sec += tremain.tv_usec / 1000000L;
+ tremain.tv_usec %= 1000000L;
+ } else {
+ tremain.tv_sec = 0;
+ tremain.tv_usec = 0;
+ }
+ if (rem != NULL)
+ TIMEVAL_TO_TIMESPEC(&tremain, rem);
+
+ return(rc);
+}
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index ab23a933..be9b90e1 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -290,6 +290,24 @@ char * strnlen(const char *, size_t);
#endif
+
+#ifndef HAVE_STRUCT_TIMEVAL
+struct timeval {
+ long tv_sec;
+ long tv_usec;
+}
+#endif
+
+#ifdef NEED_NANOSLEEP
+#ifndef HAVE_STRUCT_TIMESPEC
+struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+};
+#endif
+int nanosleep(const struct timespec *, struct timespec *);
+#endif
+
#ifdef NEED_SIGNAL
typedef void (*mysig_t)(int);
mysig_t mysignal(int sig, mysig_t act);
@@ -300,5 +318,8 @@ mysig_t mysignal(int sig, mysig_t act);
const char *strerror(int);
#endif
+#ifdef NEED_USLEEP
+int usleep(unsigned int useconds);
+#endif
#endif /* _OPENBSD_COMPAT_H */
diff --git a/openbsd-compat/usleep.c b/openbsd-compat/usleep.c
new file mode 100644
index 00000000..946befc9
--- /dev/null
+++ b/openbsd-compat/usleep.c
@@ -0,0 +1,43 @@
+
+/*
+ * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "includes.h"
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+
+#include <err.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+int
+usleep(unsigned int useconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = useconds / 1000000;
+ ts.tv_nsec = (useconds % 1000000) * 1000;
+ return nanosleep(&ts, NULL);
+}