Add UnixWare support to configure
diff --git a/ChangeLog b/ChangeLog
index 6f745ff..e462127 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Nov 29 16:33:04 CET 1999 Wichert Akkerman <wakkerma@debian.org>
+
+  * Merge patches from John Hughes to make configure support UnixWare
+
 Sat Nov 27 21:38:17 CET 1999 Wichert Akkerman <wakkerma@debian.org>
 
   * Enhance sys_query_module
diff --git a/README-svr4 b/README-svr4
index 8f66a7f..aaf5dff 100644
--- a/README-svr4
+++ b/README-svr4
@@ -9,13 +9,6 @@
 
 There is no thread support but it wouldn't be very difficult to add it.
 
-There is currently no configure-support yet for UnixWare system. To compile
-on UnixWare 2.1 you need to add the following to config.h yourself:
-
-    #define SVR4_MP 1
-    #define UNIXWARE 2
-    #define HAVE_POLLABLE_PROCFS 1
-
 On UnixWare using the -f option to follow forked children sometimes shows
 many "unfinished" system calls as strace bounces between each runnable child.
 A crude workaround for this is available by adding
diff --git a/acconfig.h b/acconfig.h
index 8a9a9c3..3f63ef1 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -9,6 +9,9 @@
    or a derivative like Solaris 2.x or Irix 5.x.  */
 #undef SVR4
 
+/* Define for UnixWare systems. */
+#undef UNIXWARE
+
 /* Define if this is an i386, i486 or pentium architecture.  */
 #undef I386
 
@@ -30,9 +33,18 @@
 /* Define if this is an powerpc architecture.  */
 #undef POWERPC
 
+/* Define if you have a SVR4 MP type procfs.  I.E. /dev/xxx/ctl,
+   /dev/xxx/status.  Also implies that you have the pr_lwp
+   member in prstatus. */
+#undef HAVE_MP_PROCFS
+
 /* Define if you have SVR4 and the poll system call works on /proc files.  */
 #undef HAVE_POLLABLE_PROCFS
 
+/* Define if you have SVR4_MP and you need to use the poll hack
+   to avoid unfinished system calls. */
+#undef POLL_HACK
+
 /* Define if the prstatus structure in sys/procfs.h has a pr_syscall member.  */
 #undef HAVE_PR_SYSCALL
 
diff --git a/aclocal.m4 b/aclocal.m4
index de48e66..264d5e3 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -68,6 +68,66 @@
 fi
 ])
 
+dnl ### A macro to determine if we have a "MP" type procfs
+AC_DEFUN(AC_MP_PROCFS,
+[AC_MSG_CHECKING(for MP procfs)
+AC_CACHE_VAL(ac_cv_mp_procfs,
+[AC_TRY_RUN([
+#include <stdio.h>
+#include <signal.h>
+#include <sys/procfs.h>
+
+main()
+{
+	int pid;
+	char proc[32];
+	FILE *ctl;
+	FILE *status;
+	int cmd;
+	struct pstatus pstatus;
+
+	if ((pid = fork()) == 0) {
+		pause();
+		exit(0);
+	}
+	sprintf(proc, "/proc/%d/ctl", pid);
+	if ((ctl = fopen(proc, "w")) == NULL)
+		goto fail;
+	sprintf(proc, "/proc/%d/status", pid);
+	if ((status = fopen (proc, "r")) == NULL)
+		goto fail;
+	cmd = PCSTOP;
+	if (write (fileno (ctl), &cmd, sizeof cmd) < 0)
+		goto fail;
+	if (read (fileno (status), &pstatus, sizeof pstatus) < 0)
+		goto fail;
+	kill(pid, SIGKILL);
+	exit(0);
+fail:
+	kill(pid, SIGKILL);
+	exit(1);
+}
+],
+ac_cv_mp_procfs=yes,
+ac_cv_mp_procfs=no,
+[
+# Guess or punt.
+case "$host_os" in
+svr4.2*|svr5*)
+	ac_cv_mp_procfs=yes
+	;;
+*)
+	ac_cv_mp_procfs=no
+	;;
+esac
+])])
+AC_MSG_RESULT($ac_cv_mp_procfs)
+if test "$ac_cv_mp_procfs" = yes
+then
+	AC_DEFINE(HAVE_MP_PROCFS)
+fi
+])
+
 dnl ### A macro to determine if procfs is pollable.
 AC_DEFUN(AC_POLLABLE_PROCFS,
 [AC_MSG_CHECKING(for pollable procfs)
@@ -79,6 +139,21 @@
 #include <sys/stropts.h>
 #include <poll.h>
 
+#ifdef HAVE_MP_PROCFS
+#define PIOCSTOP	PCSTOP
+#define POLLWANT	POLLWRNORM
+#define PROC		"/proc/%d/ctl"
+#define PROC_MODE	"w"
+int IOCTL (int fd, int cmd, int arg) {
+	return write (fd, &cmd, sizeof cmd);
+}
+#else
+#define POLLWANT	POLLPRI
+#define	PROC		"/proc/%d"
+#define PROC_MODE	"r+"
+#define IOCTL		ioctl
+#endif
+
 main()
 {
 	int pid;
@@ -90,16 +165,16 @@
 		pause();
 		exit(0);
 	}
-	sprintf(proc, "/proc/%d", pid);
-	if ((pfp = fopen(proc, "r+")) == NULL)
+	sprintf(proc, PROC, pid);
+	if ((pfp = fopen(proc, PROC_MODE)) == NULL)
 		goto fail;
-	if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
+	if (IOCTL(fileno(pfp), PIOCSTOP, NULL) < 0)
 		goto fail;
 	pfd.fd = fileno(pfp);
-	pfd.events = POLLPRI;
+	pfd.events = POLLWANT;
 	if (poll(&pfd, 1, 0) < 0)
 		goto fail;
-	if (!(pfd.revents & POLLPRI))
+	if (!(pfd.revents & POLLWANT))
 		goto fail;
 	kill(pid, SIGKILL);
 	exit(0);
@@ -113,7 +188,7 @@
 [
 # Guess or punt.
 case "$host_os" in
-solaris2*|irix5*)
+solaris2*|irix5*|svr4.2uw*|svr5*)
 	ac_cv_pollable_procfs=yes
 	;;
 *)
diff --git a/configure.in b/configure.in
index b134dff..a389676 100644
--- a/configure.in
+++ b/configure.in
@@ -16,6 +16,9 @@
 sysv4*)
 	opsys=svr4
 	;;
+sysv5*)
+	opsys=svr4
+	;;
 irix[56]*)
 	opsys=svr4
 	;;
@@ -77,11 +80,20 @@
 AC_CONFIG_HEADER(config.h)
 AC_SUBST(opsys)
 AC_DEFINE_UNQUOTED($OPSYS)
+case "$host_os" in
+sysv4.2uw*)
+	AC_DEFINE(UNIXWARE, 2)
+	;;
+sysv5*)
+	AC_DEFINE(UNIXWARE, 7)
+	;;
+esac
 AC_SUBST(arch)
 AC_DEFINE_UNQUOTED($ARCH)
 AC_SUBST(osarch)
 AC_PROG_CC
 AC_PROG_HOSTCC($host_alias $host)
+AC_MP_PROCFS
 AC_POLLABLE_PROCFS
 AC_STRUCT_PR_SYSCALL
 AC_STRUCT_MSG_CONTROL
diff --git a/defs.h b/defs.h
index 56e14b2..d65fc15 100644
--- a/defs.h
+++ b/defs.h
@@ -82,7 +82,7 @@
 
 #ifdef SVR4
 #include <sys/procfs.h>
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 #include <sys/uio.h>
 #endif
 #else /* !SVR4 */
@@ -148,7 +148,7 @@
 
 
 #ifdef SVR4
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 extern int mp_ioctl (int f, int c, void *a, int s);
 #define IOCTL(f,c,a)	mp_ioctl (f, c, a, sizeof *a)
 #define IOCTL_STATUS(t) \
@@ -204,7 +204,7 @@
 	long inst[2];		/* Instructions on above */
 	int pfd;		/* proc file descriptor */
 #ifdef SVR4
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 	int pfd_stat;
 	int pfd_as;
 	pstatus_t status;
diff --git a/ioctl.c b/ioctl.c
index 24e84ba..4e6a416 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -108,7 +108,7 @@
 #endif /* !LINUX */
 		return sock_ioctl(tcp, code, arg);
 #ifdef SVR4
-#ifndef SVR4_MP
+#ifndef HAVE_MP_PROCFS
 	case 'q':
 		return proc_ioctl(tcp, code, arg);
 #endif
diff --git a/proc.c b/proc.c
index a6008f9..d4969a6 100644
--- a/proc.c
+++ b/proc.c
@@ -30,7 +30,7 @@
 #include "defs.h"
 
 #ifdef SVR4
-#ifndef SVR4_MP
+#ifndef HAVE_MP_PROCFS
 
 static struct xlat proc_status_flags[] = {
 	{ PR_STOPPED,	"PR_STOPPED"	},
@@ -183,6 +183,6 @@
 	}
 }
 
-#endif /* SVR4_MP */
+#endif /* HAVE_MP_PROCFS */
 #endif /* SVR4 */
 
diff --git a/strace.c b/strace.c
index f40f5d6..8288d2a 100644
--- a/strace.c
+++ b/strace.c
@@ -45,7 +45,7 @@
 #ifdef SVR4
 #include <sys/stropts.h>
 #include <poll.h>
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 #include <sys/uio.h>
 #endif
 #endif
@@ -108,7 +108,7 @@
 
 #endif /* !HAVE_POLLABLE_PROCFS */
 
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 #define POLLWANT	POLLWRNORM
 #else
 #define POLLWANT	POLLPRI
@@ -581,7 +581,7 @@
 	static int last_pfd;
 #endif
 
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 	/* Open the process pseudo-files in /proc. */
 	sprintf(proc, "/proc/%d/ctl", tcp->pid);
 	if ((tcp->pfd = open(proc, O_WRONLY|O_EXCL)) < 0) {
@@ -1736,7 +1736,7 @@
 	tcp_last = NULL;
 }
 
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 
 int mp_ioctl (int fd, int cmd, void *arg, int size) {
 
diff --git a/system.c b/system.c
index 14099a9..1d0c163 100644
--- a/system.c
+++ b/system.c
@@ -1356,7 +1356,7 @@
 	}
 	return 0;
 }
-#endif /* !SVR4_MP */
+#endif /* !UNIXWARE */
 
 #endif /* !MIPS */
 
diff --git a/util.c b/util.c
index 8893039..32b3fef 100644
--- a/util.c
+++ b/util.c
@@ -624,7 +624,7 @@
 #endif /* SUNOS4 */
 
 #ifdef SVR4
-#ifdef SVR4_MP
+#ifdef HAVE_MP_PROCFS
 	if (pread(tcp->pfd_as, laddr, len, addr) == -1)
 		return -1;
 #else
@@ -643,7 +643,7 @@
 	if (read(tcp->pfd, laddr, len) == -1)
 		return -1;
 #endif /* !HAVE_PREAD */
-#endif /* SVR4_MP */
+#endif /* HAVE_MP_PROCFS */
 #endif /* SVR4 */
 
 	return 0;