$NetBSD: patch-ar,v 1.1.1.1 2006/10/19 22:58:21 bouyer Exp $

--- ioemu/vl.c.orig	2006-10-15 14:22:03.000000000 +0200
+++ ioemu/vl.c	2006-10-20 00:33:18.000000000 +0200
@@ -37,14 +37,17 @@
 #include <sys/poll.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
+#include <sys/resource.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <net/if.h>
+#include <net/if_tap.h>
 #include <arpa/inet.h>
 #include <dirent.h>
 #include <netdb.h>
 #ifdef _BSD
 #include <sys/stat.h>
-#ifndef __APPLE__
+#ifndef _BSD
 #include <libutil.h>
 #endif
 #else
@@ -88,8 +91,8 @@
 
 #include "exec-all.h"
 
-#define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
-#define DEFAULT_BRIDGE "xenbr0"
+#define DEFAULT_NETWORK_SCRIPT "@XENDCONFDIR@/scripts/qemu-ifup"
+#define DEFAULT_BRIDGE "bridge0"
 
 //#define DEBUG_UNUSED_IOPORT
 //#define DEBUG_IOPORT
@@ -1603,7 +1606,7 @@
     return 0;
 }
 
-#if defined(__linux__)
+#if defined(__linux__) || defined(__NetBSD__)
 CharDriverState *qemu_chr_open_pty(void)
 {
     struct termios tty;
@@ -1755,7 +1758,7 @@
     chr->chr_ioctl = tty_serial_ioctl;
     return chr;
 }
-
+#if defined(__linux__)
 static int pp_ioctl(CharDriverState *chr, int cmd, void *arg)
 {
     int fd = (int)chr->opaque;
@@ -1818,13 +1821,14 @@
     chr->chr_ioctl = pp_ioctl;
     return chr;
 }
+#endif /* __linux__ */
 
 #else
 CharDriverState *qemu_chr_open_pty(void)
 {
     return NULL;
 }
-#endif
+#endif /* __linux__ || __NetBSD__ */
 
 #endif /* !defined(_WIN32) */
 
@@ -3064,7 +3068,7 @@
     fclose(f);
     atexit(smb_exit);
 
-    snprintf(smb_cmdline, sizeof(smb_cmdline), "/usr/sbin/smbd -s %s",
+    snprintf(smb_cmdline, sizeof(smb_cmdline), "@PREFIX@/sbin/smbd -s %s",
              smb_conf);
     
     slirp_add_exec(0, smb_cmdline, 4, 139);
@@ -3128,16 +3132,26 @@
     int fd;
     char *dev;
     struct stat s;
+    struct ifreq ifr;
 
     fd = open("/dev/tap", O_RDWR);
     if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
+        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation: %s\n", strerror(errno));
         return -1;
     }
 
+#ifdef TAPGIFNAME
+    if (ioctl (fd, TAPGIFNAME, (void*)&ifr) < 0) {
+	fprintf(stderr, "warning: could not open get tap name: %s\n",
+	    strerror(errno));
+	return -1;
+    }
+    pstrcpy(ifname, ifname_size, ifr.ifr_name);
+#else
     fstat(fd, &s);
     dev = devname(s.st_rdev, S_IFCHR);
     pstrcpy(ifname, ifname_size, dev);
+#endif
 
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
@@ -5855,9 +5869,36 @@
     xen_pfn_t *page_array;
     extern void *shared_page;
     extern void *buffered_io_page;
+    struct rlimit rl;
 
     char qemu_dm_logfilename[64];
 
+    /* XXX required for now */
+    if (setenv("PTHREAD_DIAGASSERT", "A", 1) != 0)
+	perror("setenv");
+    if (getrlimit(RLIMIT_STACK, &rl) != 0) {
+	perror("getrlimit(RLIMIT_STACK)");
+	exit(1);
+    }
+    rl.rlim_cur = rl.rlim_max;
+    if (setrlimit(RLIMIT_STACK, &rl) != 0)
+	perror("setrlimit(RLIMIT_STACK)");
+    if (getrlimit(RLIMIT_DATA, &rl) != 0) {
+	perror("getrlimit(RLIMIT_DATA)");
+	exit(1);
+    }
+    rl.rlim_cur = rl.rlim_max;
+    if (setrlimit(RLIMIT_DATA, &rl) != 0)
+	perror("setrlimit(RLIMIT_DATA)");
+    rl.rlim_cur = RLIM_INFINITY;
+    rl.rlim_max = RLIM_INFINITY;
+    if (setrlimit(RLIMIT_RSS, &rl) != 0)
+	perror("setrlimit(RLIMIT_RSS)");
+    rl.rlim_cur = RLIM_INFINITY;
+    rl.rlim_max = RLIM_INFINITY;
+    if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0)
+	perror("setrlimit(RLIMIT_MEMLOCK)");
+
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
     {
