$NetBSD: patch-am,v 1.1.1.1 2006/07/02 16:49:31 bouyer Exp $

--- console/daemon/io.c.orig	2006-04-13 19:48:38.000000000 +0200
+++ console/daemon/io.c	2006-05-07 23:26:36.000000000 +0200
@@ -24,7 +24,11 @@
 #include "io.h"
 #include <xenctrl.h>
 #include <xs.h>
+#ifdef __NetBSD__
+#include <xen/NetBSD/xenio3.h>
+#else
 #include <xen/linux/evtchn.h>
+#endif
 #include <xen/io/console.h>
 
 #include <malloc.h>
@@ -155,22 +159,26 @@
 	int master;
 	bool success;
 
-	if ((master = getpt()) == -1 ||
-	    grantpt(master) == -1 || unlockpt(master) == -1) {
-		dolog(LOG_ERR, "Failed to create tty for domain-%d",
-		      dom->domid);
-		master = -1;
-	} else {
+	if ((master = posix_openpt(O_RDWR)) == -1) {
+		dolog(LOG_ERR, "Failed to create tty for domain-%d: %s",
+		    dom->domid, strerror(errno));
+		return -1;
+	}
+	if (grantpt(master) == -1) {
+		dolog(LOG_ERR, "Failed to grant tty for domain-%d: %s",
+		    dom->domid, strerror(errno));
+		goto out;
+	}
+	if (unlockpt(master) == -1) {
+		dolog(LOG_ERR, "Failed to unlock tty for domain-%d: %s",
+		    dom->domid, strerror(errno));
+		goto out;
+	}
+	{
 		const char *slave = ptsname(master);
-		struct termios term;
 		char *data;
 		unsigned int len;
 
-		if (tcgetattr(master, &term) != -1) {
-			cfmakeraw(&term);
-			tcsetattr(master, TCSAFLUSH, &term);
-		}
-
 		success = asprintf(&path, "%s/limit", dom->conspath) != -1;
 		if (!success)
 			goto out;
@@ -263,7 +271,11 @@
 
 	/* Opening evtchn independently for each console is a bit
 	 * wasteful, but that's how the code is structured... */
+#ifdef __NetBSD__
+	dom->evtchn_fd = open("/dev/xenevt", O_RDWR);
+#else
 	dom->evtchn_fd = open("/dev/xen/evtchn", O_RDWR);
+#endif
 	if (dom->evtchn_fd == -1) {
 		err = errno;
 		goto out;
@@ -278,7 +290,11 @@
 		dom->evtchn_fd = -1;
 		goto out;
 	}
+#ifdef __NetBSD__
+	dom->local_port = bind.port;
+#else
 	dom->local_port = rc;
+#endif
 
 	if (dom->tty_fd == -1) {
 		dom->tty_fd = domain_create_tty(dom);
