From ce2cd448af9a0e8f78dee45924784a19299b2882 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Thu, 19 Aug 2021 20:05:11 +0200 Subject: [PATCH] Remove some CENV_SYS_* defines. I was hoping to remove more of them: at least CENV_SYS_BSD for example which would allow removing several more. Unfortunately CENV_SYS_BSD is used in tape control behaviour checks. There is no way of checking those with configure. Worse, how well tape worked on various Unixen when the tape code was written may be totally different in later versions. For signal handling I could at least remove CENV_SYS_BSD by implementing the suggestion to use sigvec(2) (now deprecated). Falling back to plain V7-style signal(2) is probably not good enough, so that is an error case now. Fortunately that is totally unneeded on any modern Unix. --- configure.ac | 4 ++-- src/cenv.h | 13 +++---------- src/dpsup.c | 16 ++++++++++++---- src/osdsup.c | 22 ++++++++++++++++------ src/osdsup.h | 4 +++- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index fe9eec2..ad4df4f 100644 --- a/configure.ac +++ b/configure.ac @@ -131,7 +131,7 @@ AC_CHECK_HEADERS([arpa/inet.h errno.h fcntl.h limits.h netinet/in.h sgtty.h \ linux/if_tun.h linux/if_packet.h net/if_tap.h sys/mtio.h \ net/nit.h sys/dlpi.h net/if_dl.h net/if_types.h \ sys/io.h libvdeplug.h, sys/ioctl_compat.h sys/stream.h \ - sys/times.h sys/resource.h]) + sys/times.h sys/resource.h signal.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE @@ -151,7 +151,7 @@ AC_CHECK_FUNCS([alarm dup2 gettimeofday localtime_r memset socket strcasecmp \ strchr strcspn strerror strncasecmp strpbrk strrchr strtol \ getifaddrs if_nameindex sigaction nanosleep \ getrusage setitimer tcsetattr mlockall \ - setpriority times]) + setpriority times sigvec]) # Check for BSD TTY stuff as fallback for termios. AC_CHECK_MEMBER(struct tchars.t_intrc, diff --git a/src/cenv.h b/src/cenv.h index c3e11ea..9c486c2 100644 --- a/src/cenv.h +++ b/src/cenv.h @@ -109,19 +109,13 @@ #ifndef CENV_SYS_T20 /* DEC TOPS-20 */ # define CENV_SYS_T20 0 #endif -#ifndef CENV_SYS_V7 /* Basic vanilla Unix */ -# define CENV_SYS_V7 0 -#endif -#ifndef CENV_SYS_W2K /* MS W2K */ -# define CENV_SYS_W2K 0 -#endif /* If none of the above were set, try a few semi-standard checks, * but don't complain if nothing's found. */ -#if !(CENV_SYS_V7|CENV_SYS_SUN|CENV_SYS_SOLARIS|CENV_SYS_NEXT|CENV_SYS_MAC \ +#if !(CENV_SYS_SUN|CENV_SYS_SOLARIS|CENV_SYS_NEXT|CENV_SYS_MAC \ |CENV_SYS_BSDI|CENV_SYS_NETBSD|CENV_SYS_FREEBSD|CENV_SYS_OPENBSD \ - |CENV_SYS_DECOSF|CENV_SYS_LINUX|CENV_SYS_W2K) + |CENV_SYS_DECOSF|CENV_SYS_LINUX) # if defined(__osf__) && defined(__digital__) # undef CENV_SYS_DECOSF # define CENV_SYS_DECOSF 1 @@ -164,8 +158,7 @@ |CENV_SYS_XBSD|CENV_SYS_NEXT|CENV_SYS_DECOSF \ |CENV_SYS_LINUX) #endif -#define CENV_SYS_SVR4 0 /* XXX Later: (CENV_SYS_SOLARIS|CENV_SYS_DECOSF) ? */ -#define CENV_SYS_UNIX (CENV_SYS_V7|CENV_SYS_BSD|CENV_SYS_SVR4) /* Any Unix */ +#define CENV_SYS_UNIX __unix__ /* Any Unix */ /* Specific OS Feature defs This only has features of interest for KLH10 software. diff --git a/src/dpsup.c b/src/dpsup.c index 5284467..ad92038 100644 --- a/src/dpsup.c +++ b/src/dpsup.c @@ -704,11 +704,19 @@ dp_signal(int sig, void (*func)(int)) sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, sig); /* Suspend this sig during handler */ return sigaction(sig, &act, &oact); -#elif CENV_SYS_BSD - /* If really BSD, probably should use sigvec instead */ - return (signal(sig, func) == (void (*)())-1) ? -1 : 0; +#elif HAVE_SIGVEC /* untested */ + struct sigvec sv, osv; + + sv.sv_handler = func; + sv.sv_flags = SV_INTERRUPT; /* not SV_RESETHAND */ + sv.sv_mask = sigmask(sig); + if (ossa) + ossa->ossa_sig = sig; + return sigvec(sig, &sv, &osv); #else - *** ERROR *** need signal support + /* If really BSD, probably should use sigvec instead */ + *** ERROR *** need reliable signal support + return (signal(sig, func) == (void (*)())-1) ? -1 : 0; #endif } diff --git a/src/osdsup.c b/src/osdsup.c index 2148e7c..40f8394 100644 --- a/src/osdsup.c +++ b/src/osdsup.c @@ -1538,7 +1538,17 @@ osux_sigact(int sig, ossighandler_t *func, ossigact_t *ossa) if (ossa) ossa->ossa_sig = sig; return sigaction(sig, &act, (ossa ? &ossa->ossa_sa : NULL)); -#elif CENV_SYS_BSD +#elif HAVE_SIGVEC /* untested */ + struct sigvec sv; + + sv.sv_handler = func; + sv.sv_flags = 0; /* not SV_INTERRUPT, not SV_RESETHAND */ + sv.sv_mask = sigmask(sig); + if (ossa) + ossa->ossa_sig = sig; + return sigvec(sig, &act, (ossa ? &ossa->ossa_sv : NULL)); +#else +# error "Unimplemented OS routine osux_sigact()" void (*ret)(); ret = signal(sig, func); @@ -1547,8 +1557,6 @@ osux_sigact(int sig, ossighandler_t *func, ossigact_t *ossa) ossa->ossa_handler = func; } return (ret == SIG_ERR) ? -1 : 0; -#else -# error "Unimplemented OS routine osux_sigact()" #endif } @@ -1558,11 +1566,13 @@ osux_sigrestore(ossigact_t *ossa) #if HAVE_SIGACTION return sigaction(ossa->ossa_sig, &ossa->ossa_sa, (struct sigaction *)NULL); -#elif CENV_SYS_BSD - return (signal(ossa->ossa_sig, ossa->ossa_handler) == SIG_ERR) - ? -1 : 0; +#elif HAVE_SIGVEC /* untested */ + return sigvec(ossa->ossa_sig, + &ossa->ossa_sv, (struct sigvec *)NULL); #else # error "Unimplemented OS routine osux_sigrestore()" + return (signal(ossa->ossa_sig, ossa->ossa_handler) == SIG_ERR) + ? -1 : 0; #endif } diff --git a/src/osdsup.h b/src/osdsup.h index 6363328..27e8b87 100644 --- a/src/osdsup.h +++ b/src/osdsup.h @@ -92,7 +92,7 @@ extern int os_fdclose(osfd_t); /* Signal facilities. Not provided on all environments. */ -#if CENV_SYS_UNIX || CENV_SYS_MAC +#if HAVE_SIGNAL_H # include #endif @@ -136,6 +136,8 @@ typedef struct { int ossa_sig; #if HAVE_SIGACTION struct sigaction ossa_sa; +#elif HAVE_SIGVEC + struct sigvec ossa_sv; #else ossighandler_t *ossa_handler; #endif