From fbfa6f980d7460b3e12b0ce88ed3b6018edf4711 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 11 Feb 2018 21:25:11 +1300 Subject: Move signal compat code into bsd-signal.{c,h} --- openbsd-compat/bsd-misc.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 29f6ad38c..9f6dc8af2 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -104,16 +104,6 @@ const char *strerror(int e) } #endif -#if !defined(HAVE_STRSIGNAL) -char *strsignal(int sig) -{ - static char buf[16]; - - (void)snprintf(buf, sizeof(buf), "%d", sig); - return buf; -} -#endif - #ifndef HAVE_UTIMES int utimes(char *filename, struct timeval *tvp) { @@ -221,33 +211,6 @@ tcsendbreak(int fd, int duration) } #endif /* HAVE_TCSENDBREAK */ -mysig_t -mysignal(int sig, mysig_t act) -{ -#ifdef HAVE_SIGACTION - struct sigaction sa, osa; - - if (sigaction(sig, NULL, &osa) == -1) - return (mysig_t) -1; - if (osa.sa_handler != act) { - memset(&sa, 0, sizeof(sa)); - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; -#ifdef SA_INTERRUPT - if (sig == SIGALRM) - sa.sa_flags |= SA_INTERRUPT; -#endif - sa.sa_handler = act; - if (sigaction(sig, &sa, NULL) == -1) - return (mysig_t) -1; - } - return (osa.sa_handler); -#else - #undef signal - return (signal(sig, act)); -#endif -} - #ifndef HAVE_STRDUP char * strdup(const char *str) -- cgit v1.2.3 From a9004425a032d7a7141a5437cfabfd02431e2a74 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 24 Feb 2018 20:25:22 +1100 Subject: Check for bzero and supply if needed. Since explicit_bzero uses it via an indirect it needs to be a function not just a macro. --- configure.ac | 3 +++ openbsd-compat/bsd-misc.c | 8 ++++++++ openbsd-compat/bsd-misc.h | 4 ++++ 3 files changed, 15 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/configure.ac b/configure.ac index e81e3eccd..e23540e63 100644 --- a/configure.ac +++ b/configure.ac @@ -1695,6 +1695,7 @@ AC_CHECK_FUNCS([ \ bcrypt_pbkdf \ bindresvport_sa \ blf_enc \ + bzero \ cap_rights_limit \ clock \ closefrom \ @@ -1800,6 +1801,8 @@ AC_CHECK_FUNCS([ \ warn \ ]) +AC_CHECK_DECLS([bzero]) + dnl Wide character support. AC_CHECK_FUNCS([mblen mbtowc nl_langinfo wcwidth]) diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 9f6dc8af2..3e8f74b72 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -282,3 +282,11 @@ llabs(long long j) return (j < 0 ? -j : j); } #endif + +#ifndef HAVE_BZERO +void +bzero(void *b, size_t n) +{ + (void)memset(b, 0, n); +} +#endif diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 2cfd5dae6..bf5fad188 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -133,4 +133,8 @@ void warn(const char *, ...) __attribute__((format(printf, 1, 2))); long long llabs(long long); #endif +#ifndef HAVE_DECL_BZERO +void bzero(void *, size_t); +#endif + #endif /* _BSD_MISC_H */ -- cgit v1.2.3 From 6c8c9a615b6d31db8a87bc25033f053d5b0a831e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 24 Feb 2018 20:46:37 +1100 Subject: Check for raise and supply if needed. --- configure.ac | 1 + openbsd-compat/bsd-misc.c | 8 ++++++++ openbsd-compat/bsd-misc.h | 4 ++++ 3 files changed, 13 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/configure.ac b/configure.ac index e23540e63..7342dcb77 100644 --- a/configure.ac +++ b/configure.ac @@ -1744,6 +1744,7 @@ AC_CHECK_FUNCS([ \ poll \ prctl \ pstat \ + raise \ readpassphrase \ reallocarray \ recvmsg \ diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3e8f74b72..af58f3bd2 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -290,3 +290,11 @@ bzero(void *b, size_t n) (void)memset(b, 0, n); } #endif + +#ifndef HAVE_RAISE +int +raise(int sig) +{ + kill(getpid(), sig); +} +#endif diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index bf5fad188..3cb912d28 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -137,4 +137,8 @@ long long llabs(long long); void bzero(void *, size_t); #endif +#ifndef HAVE_RAISE +int raise(int); +#endif + #endif /* _BSD_MISC_H */ -- cgit v1.2.3 From b39593a6de5290650a01adf8699c6460570403c2 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 25 Feb 2018 13:25:15 +1100 Subject: Add no-op getsid implmentation. --- configure.ac | 1 + openbsd-compat/bsd-misc.c | 10 ++++++++++ openbsd-compat/bsd-misc.h | 4 ++++ 3 files changed, 15 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/configure.ac b/configure.ac index e9762ba68..f96c70bcd 100644 --- a/configure.ac +++ b/configure.ac @@ -1739,6 +1739,7 @@ AC_CHECK_FUNCS([ \ getpgrp \ _getpty \ getrlimit \ + getsid \ getttyent \ glob \ group_from_gid \ diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index af58f3bd2..a2f750558 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -298,3 +298,13 @@ raise(int sig) kill(getpid(), sig); } #endif + +#ifndef HAVE_GETSID +pid_t +getsid(pid_t pid) +{ + errno = ENOSYS; + return -1; +} +#endif + diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 3cb912d28..af2ccdae2 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -141,4 +141,8 @@ void bzero(void *, size_t); int raise(int); #endif +#ifndef HAVE_GETSID +pid_t getsid(pid_t); +#endif + #endif /* _BSD_MISC_H */ -- cgit v1.2.3 From c7b5a47e3b9db9a0f0198f9c90c705f6307afc2b Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 25 Feb 2018 23:55:41 +1100 Subject: Invert sense of getpgrp test. AC_FUNC_GETPGRP tests if getpgrp(0) works, which it does if it's not declared. Instead, test if the zero-arg version we want to use works. --- configure.ac | 12 ++++++++++-- openbsd-compat/bsd-misc.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/configure.ac b/configure.ac index f96c70bcd..d3deac832 100644 --- a/configure.ac +++ b/configure.ac @@ -1736,7 +1736,6 @@ AC_CHECK_FUNCS([ \ getpeereid \ getpeerucred \ getpgid \ - getpgrp \ _getpty \ getrlimit \ getsid \ @@ -2413,7 +2412,16 @@ static void sighandler(int sig) { _exit(1); } ) fi -AC_FUNC_GETPGRP +AC_CHECK_FUNCS([getpgrp],[ + AC_MSG_CHECKING([if getpgrp accepts zero args]) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[$ac_includes_default]], [[ getpgrp(); ]])], + [ AC_MSG_RESULT([yes]) + AC_DEFINE([GETPGRP_VOID], [1], [getpgrp takes zero args])], + [ AC_MSG_RESULT([no]) + AC_DEFINE([GETPGRP_VOID], [0], [getpgrp takes one arg])] + ) +]) # Search for OpenSSL saved_CPPFLAGS="$CPPFLAGS" diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index a2f750558..f7187daf8 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -238,7 +238,7 @@ isblank(int c) pid_t getpgid(pid_t pid) { -#if defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) +#if defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) && GETPGRP_VOID == 0 return getpgrp(pid); #elif defined(HAVE_GETPGRP) if (pid == 0) -- cgit v1.2.3 From 58fd4c5c0140f6636227ca7acbb149ab0c2509b9 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 5 Mar 2018 19:28:08 +1100 Subject: Check for and work around buggy fflush(NULL). Some really old platforms (eg SunOS4) segfault on fflush(NULL) so check for and work around. With klausz at haus-gisela.de. --- configure.ac | 10 ++++++++++ openbsd-compat/bsd-misc.c | 16 ++++++++++++++++ openbsd-compat/bsd-misc.h | 4 ++++ 3 files changed, 30 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/configure.ac b/configure.ac index 70e72be77..d2fb4469c 100644 --- a/configure.ac +++ b/configure.ac @@ -2059,6 +2059,16 @@ AC_CHECK_FUNCS([realpath], [ ) ]) +AC_MSG_CHECKING([for working fflush(NULL)]) +AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[#include ]], [[fflush(NULL); exit(0);]])], + AC_MSG_RESULT([yes]), + [AC_MSG_RESULT([no]) + AC_DEFINE([FFLUSH_NULL_BUG], [1], + [define if fflush(NULL) does not work])], + AC_MSG_WARN([cross compiling: assuming working]) +) + dnl Checks for time functions AC_CHECK_FUNCS([gettimeofday time]) dnl Checks for utmp functions diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index f7187daf8..3daf61071 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -308,3 +308,19 @@ getsid(pid_t pid) } #endif +#ifdef FFLUSH_NULL_BUG +#undef fflush +int _ssh_compat_fflush(FILE *f) +{ + int r1, r2, r3; + + if (f == NULL) { + r2 = fflush(stdout); + r3 = fflush(stderr); + if (r1 == -1 || r2 == -1 || r3 == -1) + return -1; + return 0; + } + return fflush(f); +} +#endif diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index fb81e6c72..52ec52853 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -153,4 +153,8 @@ pid_t getsid(pid_t); int flock(int, int); #endif +#ifdef FFLUSH_NULL_BUG +# define fflush(x) (_ssh_compat_fflush(x)) +#endif + #endif /* _BSD_MISC_H */ -- cgit v1.2.3