ia64/xen-unstable

changeset 15994:04cc0e22a20a

ioemu: Fixes for BSD.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir@xensource.com>
date Thu Sep 27 16:36:23 2007 +0100 (2007-09-27)
parents 98d97e3ad29a
children 9c567284436e
files tools/ioemu/audio/audio.c tools/ioemu/audio/mixeng.c tools/ioemu/audio/ossaudio.c tools/ioemu/block-raw.c tools/ioemu/block-vvfat.c tools/ioemu/bswap.h tools/ioemu/cutils.c tools/ioemu/monitor.c tools/ioemu/osdep.h tools/ioemu/target-i386-dm/exec-dm.c tools/ioemu/usb-linux.c tools/ioemu/vl.c tools/ioemu/vl.h tools/ioemu/vnc.c
line diff
     1.1 --- a/tools/ioemu/audio/audio.c	Thu Sep 27 15:22:29 2007 +0100
     1.2 +++ b/tools/ioemu/audio/audio.c	Thu Sep 27 16:36:23 2007 +0100
     1.3 @@ -207,7 +207,7 @@ static char *audio_alloc_prefix (const c
     1.4          strcat (r, s);
     1.5  
     1.6          for (i = 0; i < len; ++i) {
     1.7 -            u[i] = toupper (u[i]);
     1.8 +            u[i] = toupper ((uint8_t)u[i]);
     1.9          }
    1.10      }
    1.11      return r;
    1.12 @@ -446,7 +446,7 @@ static void audio_process_options (const
    1.13  
    1.14          /* copy while upper-casing, including trailing zero */
    1.15          for (i = 0; i <= preflen; ++i) {
    1.16 -            optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]);
    1.17 +            optname[i + sizeof (qemu_prefix) - 1] = toupper ((uint8_t)prefix[i]);
    1.18          }
    1.19          strcat (optname, "_");
    1.20          strcat (optname, opt->name);
     2.1 --- a/tools/ioemu/audio/mixeng.c	Thu Sep 27 15:22:29 2007 +0100
     2.2 +++ b/tools/ioemu/audio/mixeng.c	Thu Sep 27 16:36:23 2007 +0100
     2.3 @@ -102,6 +102,7 @@
     2.4  #undef SHIFT
     2.5  
     2.6  t_sample *mixeng_conv[2][2][2][2] = {
     2.7 +#ifndef _BSD
     2.8      {
     2.9          {
    2.10              {
    2.11 @@ -146,9 +147,11 @@ t_sample *mixeng_conv[2][2][2][2] = {
    2.12              }
    2.13          }
    2.14      }
    2.15 +#endif /* !_BSD */
    2.16  };
    2.17  
    2.18  f_sample *mixeng_clip[2][2][2][2] = {
    2.19 +#ifndef _BSD
    2.20      {
    2.21          {
    2.22              {
    2.23 @@ -193,6 +196,7 @@ f_sample *mixeng_clip[2][2][2][2] = {
    2.24              }
    2.25          }
    2.26      }
    2.27 +#endif /* !_BSD */
    2.28  };
    2.29  
    2.30  /*
     3.1 --- a/tools/ioemu/audio/ossaudio.c	Thu Sep 27 15:22:29 2007 +0100
     3.2 +++ b/tools/ioemu/audio/ossaudio.c	Thu Sep 27 16:36:23 2007 +0100
     3.3 @@ -21,10 +21,15 @@
     3.4   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     3.5   * THE SOFTWARE.
     3.6   */
     3.7 +#include <stdlib.h>
     3.8  #include <sys/mman.h>
     3.9  #include <sys/types.h>
    3.10  #include <sys/ioctl.h>
    3.11 +#if defined(__OpenBSD__)
    3.12 +#include <soundcard.h>
    3.13 +#else
    3.14  #include <sys/soundcard.h>
    3.15 +#endif
    3.16  #include "vl.h"
    3.17  
    3.18  #define AUDIO_CAP "oss"
    3.19 @@ -231,7 +236,7 @@ static int oss_open (int in, struct oss_
    3.20          goto err;
    3.21      }
    3.22  
    3.23 -    if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) {
    3.24 +    if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
    3.25          oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
    3.26          goto err;
    3.27      }
     4.1 --- a/tools/ioemu/block-raw.c	Thu Sep 27 15:22:29 2007 +0100
     4.2 +++ b/tools/ioemu/block-raw.c	Thu Sep 27 16:36:23 2007 +0100
     4.3 @@ -53,9 +53,14 @@
     4.4  #include <linux/cdrom.h>
     4.5  #include <linux/fd.h>
     4.6  #endif
     4.7 -#ifdef __FreeBSD__
     4.8 +#if defined(__FreeBSD__)
     4.9  #include <sys/disk.h>
    4.10  #endif
    4.11 +#if defined(__OpenBSD__)
    4.12 +#include <sys/ioctl.h>
    4.13 +#include <sys/disklabel.h>
    4.14 +#include <sys/dkio.h>
    4.15 +#endif
    4.16  
    4.17  //#define DEBUG_FLOPPY
    4.18  
    4.19 @@ -496,6 +501,23 @@ static int raw_truncate(BlockDriverState
    4.20      return 0;
    4.21  }
    4.22  
    4.23 +#ifdef __OpenBSD__
    4.24 +static int64_t  raw_getlength(BlockDriverState *bs)
    4.25 +{
    4.26 +	int fd = ((BDRVRawState*)bs->opaque)->fd;
    4.27 +	struct stat st;
    4.28 +	if(fstat(fd, &st))
    4.29 +	  return -1;
    4.30 +	if(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)){
    4.31 +	  struct disklabel dl;
    4.32 +	  if(ioctl(fd, DIOCGDINFO, &dl))
    4.33 +	    return -1;
    4.34 +	  return (uint64_t)dl.d_secsize *
    4.35 +		dl.d_partitions[DISKPART(st.st_rdev)].p_size;
    4.36 +	}else
    4.37 +	  return st.st_size;
    4.38 +}
    4.39 +#else /* !__OpenBSD__ */
    4.40  static int64_t  raw_getlength(BlockDriverState *bs)
    4.41  {
    4.42      BDRVRawState *s = bs->opaque;
    4.43 @@ -542,6 +564,7 @@ static int64_t  raw_getlength(BlockDrive
    4.44      }
    4.45      return size;
    4.46  }
    4.47 +#endif
    4.48  
    4.49  static int raw_create(const char *filename, int64_t total_size,
    4.50                        const char *backing_file, int flags)
     5.1 --- a/tools/ioemu/block-vvfat.c	Thu Sep 27 15:22:29 2007 +0100
     5.2 +++ b/tools/ioemu/block-vvfat.c	Thu Sep 27 16:36:23 2007 +0100
     5.3 @@ -1017,7 +1017,7 @@ DLOG(if (stderr == NULL) {
     5.4  
     5.5      i = strrchr(dirname, ':') - dirname;
     5.6      assert(i >= 3);
     5.7 -    if (dirname[i-2] == ':' && isalpha(dirname[i-1]))
     5.8 +    if (dirname[i-2] == ':' && isalpha((uint8_t)dirname[i-1]))
     5.9  	/* workaround for DOS drive names */
    5.10  	dirname += i-1;
    5.11      else
     6.1 --- a/tools/ioemu/bswap.h	Thu Sep 27 15:22:29 2007 +0100
     6.2 +++ b/tools/ioemu/bswap.h	Thu Sep 27 16:36:23 2007 +0100
     6.3 @@ -5,6 +5,11 @@
     6.4  
     6.5  #include <inttypes.h>
     6.6  
     6.7 +#ifdef _BSD
     6.8 +#include <sys/endian.h>
     6.9 +#include <sys/types.h>
    6.10 +#else
    6.11 +
    6.12  #ifdef HAVE_BYTESWAP_H
    6.13  #include <byteswap.h>
    6.14  #else
    6.15 @@ -73,6 +78,8 @@ static inline void bswap64s(uint64_t *s)
    6.16      *s = bswap64(*s);
    6.17  }
    6.18  
    6.19 +#endif /* _BSD */
    6.20 +
    6.21  #if defined(WORDS_BIGENDIAN)
    6.22  #define be_bswap(v, size) (v)
    6.23  #define le_bswap(v, size) bswap ## size(v)
     7.1 --- a/tools/ioemu/cutils.c	Thu Sep 27 15:22:29 2007 +0100
     7.2 +++ b/tools/ioemu/cutils.c	Thu Sep 27 16:36:23 2007 +0100
     7.3 @@ -23,7 +23,7 @@
     7.4   */
     7.5  #include "vl.h"
     7.6  
     7.7 -void pstrcpy(char *buf, int buf_size, const char *str)
     7.8 +void pstrcpy(char *buf, size_t buf_size, const char *str)
     7.9  {
    7.10      int c;
    7.11      char *q = buf;
    7.12 @@ -41,7 +41,7 @@ void pstrcpy(char *buf, int buf_size, co
    7.13  }
    7.14  
    7.15  /* strcat and truncate. */
    7.16 -char *pstrcat(char *buf, int buf_size, const char *s)
    7.17 +char *pstrcat(char *buf, size_t buf_size, const char *s)
    7.18  {
    7.19      int len;
    7.20      len = strlen(buf);
    7.21 @@ -72,7 +72,7 @@ int stristart(const char *str, const cha
    7.22      p = str;
    7.23      q = val;
    7.24      while (*q != '\0') {
    7.25 -        if (toupper(*p) != toupper(*q))
    7.26 +        if (toupper((uint8_t)*p) != toupper((uint8_t)*q))
    7.27              return 0;
    7.28          p++;
    7.29          q++;
     8.1 --- a/tools/ioemu/monitor.c	Thu Sep 27 15:22:29 2007 +0100
     8.2 +++ b/tools/ioemu/monitor.c	Thu Sep 27 16:36:23 2007 +0100
     8.3 @@ -1698,7 +1698,7 @@ static void next(void)
     8.4  {
     8.5      if (pch != '\0') {
     8.6          pch++;
     8.7 -        while (isspace(*pch))
     8.8 +        while (isspace((uint8_t)*pch))
     8.9              pch++;
    8.10      }
    8.11  }
    8.12 @@ -1756,7 +1756,7 @@ static target_long expr_unary(void)
    8.13                      *q++ = *pch;
    8.14                  pch++;
    8.15              }
    8.16 -            while (isspace(*pch))
    8.17 +            while (isspace((uint8_t)*pch))
    8.18                  pch++;
    8.19              *q = 0;
    8.20              ret = get_monitor_def(&n, buf);
    8.21 @@ -1780,7 +1780,7 @@ static target_long expr_unary(void)
    8.22              expr_error("invalid char in expression");
    8.23          }
    8.24          pch = p;
    8.25 -        while (isspace(*pch))
    8.26 +        while (isspace((uint8_t)*pch))
    8.27              pch++;
    8.28          break;
    8.29      }
    8.30 @@ -1874,7 +1874,7 @@ static int get_expr(target_long *pval, c
    8.31          *pp = pch;
    8.32          return -1;
    8.33      }
    8.34 -    while (isspace(*pch))
    8.35 +    while (isspace((uint8_t)*pch))
    8.36          pch++;
    8.37      *pval = expr_sum();
    8.38      *pp = pch;
    8.39 @@ -1890,7 +1890,7 @@ static int get_str(char *buf, int buf_si
    8.40  
    8.41      q = buf;
    8.42      p = *pp;
    8.43 -    while (isspace(*p))
    8.44 +    while (isspace((uint8_t)*p))
    8.45          p++;
    8.46      if (*p == '\0') {
    8.47      fail:
    8.48 @@ -1935,7 +1935,7 @@ static int get_str(char *buf, int buf_si
    8.49          }
    8.50          p++;
    8.51      } else {
    8.52 -        while (*p != '\0' && !isspace(*p)) {
    8.53 +        while (*p != '\0' && !isspace((uint8_t)*p)) {
    8.54              if ((q - buf) < buf_size - 1) {
    8.55                  *q++ = *p;
    8.56              }
    8.57 @@ -1975,12 +1975,12 @@ static void monitor_handle_command(const
    8.58      /* extract the command name */
    8.59      p = cmdline;
    8.60      q = cmdname;
    8.61 -    while (isspace(*p))
    8.62 +    while (isspace((uint8_t)*p))
    8.63          p++;
    8.64      if (*p == '\0')
    8.65          return;
    8.66      pstart = p;
    8.67 -    while (*p != '\0' && *p != '/' && !isspace(*p))
    8.68 +    while (*p != '\0' && *p != '/' && !isspace((uint8_t)*p))
    8.69          p++;
    8.70      len = p - pstart;
    8.71      if (len > sizeof(cmdname) - 1)
    8.72 @@ -2016,7 +2016,7 @@ static void monitor_handle_command(const
    8.73                  int ret;
    8.74                  char *str;
    8.75                  
    8.76 -                while (isspace(*p)) 
    8.77 +                while (isspace((uint8_t)*p)) 
    8.78                      p++;
    8.79                  if (*typestr == '?') {
    8.80                      typestr++;
    8.81 @@ -2058,15 +2058,15 @@ static void monitor_handle_command(const
    8.82              {
    8.83                  int count, format, size;
    8.84                  
    8.85 -                while (isspace(*p))
    8.86 +                while (isspace((uint8_t)*p))
    8.87                      p++;
    8.88                  if (*p == '/') {
    8.89                      /* format found */
    8.90                      p++;
    8.91                      count = 1;
    8.92 -                    if (isdigit(*p)) {
    8.93 +                    if (isdigit((uint8_t)*p)) {
    8.94                          count = 0;
    8.95 -                        while (isdigit(*p)) {
    8.96 +                        while (isdigit((uint8_t)*p)) {
    8.97                              count = count * 10 + (*p - '0');
    8.98                              p++;
    8.99                          }
   8.100 @@ -2105,7 +2105,7 @@ static void monitor_handle_command(const
   8.101                          }
   8.102                      }
   8.103                  next:
   8.104 -                    if (*p != '\0' && !isspace(*p)) {
   8.105 +                    if (*p != '\0' && !isspace((uint8_t)*p)) {
   8.106                          term_printf("invalid char in format: '%c'\n", *p);
   8.107                          goto fail;
   8.108                      }
   8.109 @@ -2138,7 +2138,7 @@ static void monitor_handle_command(const
   8.110          case 'l':
   8.111              {
   8.112                  target_long val;
   8.113 -                while (isspace(*p)) 
   8.114 +                while (isspace((uint8_t)*p)) 
   8.115                      p++;
   8.116                  if (*typestr == '?' || *typestr == '.') {
   8.117                      if (*typestr == '?') {
   8.118 @@ -2149,7 +2149,7 @@ static void monitor_handle_command(const
   8.119                      } else {
   8.120                          if (*p == '.') {
   8.121                              p++;
   8.122 -                            while (isspace(*p)) 
   8.123 +                            while (isspace((uint8_t)*p)) 
   8.124                                  p++;
   8.125                              has_arg = 1;
   8.126                          } else {
   8.127 @@ -2195,7 +2195,7 @@ static void monitor_handle_command(const
   8.128                  c = *typestr++;
   8.129                  if (c == '\0')
   8.130                      goto bad_type;
   8.131 -                while (isspace(*p)) 
   8.132 +                while (isspace((uint8_t)*p)) 
   8.133                      p++;
   8.134                  has_option = 0;
   8.135                  if (*p == '-') {
   8.136 @@ -2225,7 +2225,7 @@ static void monitor_handle_command(const
   8.137          }
   8.138      }
   8.139      /* check that all arguments were parsed */
   8.140 -    while (isspace(*p))
   8.141 +    while (isspace((uint8_t)*p))
   8.142          p++;
   8.143      if (*p != '\0') {
   8.144          term_printf("%s: extraneous characters at the end of line\n", 
   8.145 @@ -2364,7 +2364,7 @@ static void parse_cmdline(const char *cm
   8.146      p = cmdline;
   8.147      nb_args = 0;
   8.148      for(;;) {
   8.149 -        while (isspace(*p))
   8.150 +        while (isspace((uint8_t)*p))
   8.151              p++;
   8.152          if (*p == '\0')
   8.153              break;
   8.154 @@ -2398,7 +2398,7 @@ void readline_find_completion(const char
   8.155      /* if the line ends with a space, it means we want to complete the
   8.156         next arg */
   8.157      len = strlen(cmdline);
   8.158 -    if (len > 0 && isspace(cmdline[len - 1])) {
   8.159 +    if (len > 0 && isspace((uint8_t)cmdline[len - 1])) {
   8.160          if (nb_args >= MAX_ARGS)
   8.161              return;
   8.162          args[nb_args++] = qemu_strdup("");
     9.1 --- a/tools/ioemu/osdep.h	Thu Sep 27 15:22:29 2007 +0100
     9.2 +++ b/tools/ioemu/osdep.h	Thu Sep 27 16:36:23 2007 +0100
     9.3 @@ -2,6 +2,10 @@
     9.4  #define QEMU_OSDEP_H
     9.5  
     9.6  #include <stdarg.h>
     9.7 +#ifdef __OpenBSD__
     9.8 +#include <sys/types.h>
     9.9 +#include <sys/signal.h>
    9.10 +#endif
    9.11  
    9.12  #define qemu_printf printf
    9.13  
    10.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Thu Sep 27 15:22:29 2007 +0100
    10.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Thu Sep 27 16:36:23 2007 +0100
    10.3 @@ -168,8 +168,8 @@ void cpu_set_log_filename(const char *fi
    10.4  #else
    10.5      setvbuf(logfile, NULL, _IOLBF, 0);
    10.6  #endif
    10.7 -    stdout = logfile;
    10.8 -    stderr = logfile;
    10.9 +    dup2(fileno(logfile), 1);
   10.10 +    dup2(fileno(logfile), 2);
   10.11  }
   10.12  
   10.13  /* mask must never be zero, except for A20 change call */
    11.1 --- a/tools/ioemu/usb-linux.c	Thu Sep 27 15:22:29 2007 +0100
    11.2 +++ b/tools/ioemu/usb-linux.c	Thu Sep 27 16:36:23 2007 +0100
    11.3 @@ -268,7 +268,7 @@ static int get_tag_value(char *buf, int 
    11.4      if (!p)
    11.5          return -1;
    11.6      p += strlen(tag);
    11.7 -    while (isspace(*p))
    11.8 +    while (isspace((uint8_t)*p))
    11.9          p++;
   11.10      q = buf;
   11.11      while (*p != '\0' && !strchr(stopchars, *p)) {
    12.1 --- a/tools/ioemu/vl.c	Thu Sep 27 15:22:29 2007 +0100
    12.2 +++ b/tools/ioemu/vl.c	Thu Sep 27 16:36:23 2007 +0100
    12.3 @@ -24,6 +24,7 @@
    12.4  #include "vl.h"
    12.5  
    12.6  #include <unistd.h>
    12.7 +#include <stdlib.h>
    12.8  #include <fcntl.h>
    12.9  #include <signal.h>
   12.10  #include <time.h>
   12.11 @@ -38,22 +39,29 @@
   12.12  #include <sys/poll.h>
   12.13  #include <sys/mman.h>
   12.14  #include <sys/ioctl.h>
   12.15 +#include <sys/resource.h>
   12.16  #include <sys/socket.h>
   12.17  #include <netinet/in.h>
   12.18 +#include <net/if.h>
   12.19 +#if defined(__NetBSD__)
   12.20 +#include <net/if_tap.h>
   12.21 +#endif
   12.22 +#if defined(__linux__) || defined(__Linux__)
   12.23 +#include <linux/if_tun.h>
   12.24 +#endif
   12.25  #include <arpa/inet.h>
   12.26  #include <dirent.h>
   12.27  #include <netdb.h>
   12.28  #ifdef _BSD
   12.29  #include <sys/stat.h>
   12.30 -#ifndef __APPLE__
   12.31 +#ifndef _BSD
   12.32  #include <libutil.h>
   12.33 +#else
   12.34 +#include <util.h>
   12.35  #endif
   12.36  #else
   12.37  #ifndef __sun__
   12.38 -#include <linux/if.h>
   12.39 -#include <linux/if_tun.h>
   12.40  #include <pty.h>
   12.41 -#include <malloc.h>
   12.42  #include <linux/rtc.h>
   12.43  #include <linux/ppdev.h>
   12.44  #endif
   12.45 @@ -65,7 +73,6 @@
   12.46  #endif
   12.47  
   12.48  #ifdef _WIN32
   12.49 -#include <malloc.h>
   12.50  #include <sys/timeb.h>
   12.51  #include <windows.h>
   12.52  #define getopt_long_only getopt_long
   12.53 @@ -91,7 +98,11 @@
   12.54  
   12.55  #include <xen/hvm/params.h>
   12.56  #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
   12.57 +#ifdef _BSD
   12.58 +#define DEFAULT_BRIDGE "bridge0"
   12.59 +#else 
   12.60  #define DEFAULT_BRIDGE "xenbr0"
   12.61 +#endif
   12.62  #ifdef __sun__
   12.63  #define SMBD_COMMAND "/usr/sfw/sbin/smbd"
   12.64  #else
   12.65 @@ -1794,7 +1805,7 @@ static int store_dev_info(char *devName,
   12.66      return 0;
   12.67  }
   12.68  
   12.69 -#if defined(__linux__)
   12.70 +#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__)
   12.71  static CharDriverState *qemu_chr_open_pty(void)
   12.72  {
   12.73      struct termios tty;
   12.74 @@ -1949,6 +1960,7 @@ static CharDriverState *qemu_chr_open_tt
   12.75      return chr;
   12.76  }
   12.77  
   12.78 +#if defined(__linux__)
   12.79  static int pp_ioctl(CharDriverState *chr, int cmd, void *arg)
   12.80  {
   12.81      int fd = (int)chr->opaque;
   12.82 @@ -2013,13 +2025,14 @@ static CharDriverState *qemu_chr_open_pp
   12.83  
   12.84      return chr;
   12.85  }
   12.86 +#endif /* __linux__ */
   12.87  
   12.88  #else
   12.89  static CharDriverState *qemu_chr_open_pty(void)
   12.90  {
   12.91      return NULL;
   12.92  }
   12.93 -#endif
   12.94 +#endif /* __linux__ || __NetBSD__ || __OpenBSD__ */
   12.95  
   12.96  #endif /* !defined(_WIN32) */
   12.97  
   12.98 @@ -2958,7 +2971,7 @@ static int parse_macaddr(uint8_t *macadd
   12.99      return 0;
  12.100  }
  12.101  
  12.102 -static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
  12.103 +static int get_str_sep(char *buf, size_t buf_size, const char **pp, int sep)
  12.104  {
  12.105      const char *p, *p1;
  12.106      int len;
  12.107 @@ -3031,7 +3044,7 @@ int parse_host_port(struct sockaddr_in *
  12.108      if (buf[0] == '\0') {
  12.109          saddr->sin_addr.s_addr = 0;
  12.110      } else {
  12.111 -        if (isdigit(buf[0])) {
  12.112 +        if (isdigit((uint8_t)buf[0])) {
  12.113              if (!inet_aton(buf, &saddr->sin_addr))
  12.114                  return -1;
  12.115          } else {
  12.116 @@ -3373,18 +3386,30 @@ static TAPState *net_tap_fd_init(VLANSta
  12.117  static int tap_open(char *ifname, int ifname_size)
  12.118  {
  12.119      int fd;
  12.120 +#ifndef TAPGIFNAME
  12.121      char *dev;
  12.122      struct stat s;
  12.123 +#endif
  12.124 +    struct ifreq ifr;
  12.125  
  12.126      fd = open("/dev/tap", O_RDWR);
  12.127      if (fd < 0) {
  12.128 -        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
  12.129 +        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation %s\n", strerror(errno));
  12.130          return -1;
  12.131      }
  12.132  
  12.133 +#ifdef TAPGIFNAME
  12.134 +    if (ioctl (fd, TAPGIFNAME, (void*)&ifr) < 0) {
  12.135 +       fprintf(stderr, "warning: could not open get tap name: %s\n",
  12.136 +           strerror(errno));
  12.137 +       return -1;
  12.138 +    }
  12.139 +    pstrcpy(ifname, ifname_size, ifr.ifr_name);
  12.140 +#else
  12.141      fstat(fd, &s);
  12.142      dev = devname(s.st_rdev, S_IFCHR);
  12.143      pstrcpy(ifname, ifname_size, dev);
  12.144 +#endif
  12.145  
  12.146      fcntl(fd, F_SETFL, O_NONBLOCK);
  12.147      return fd;
  12.148 @@ -3435,6 +3460,8 @@ static int net_tap_init(VLANState *vlan,
  12.149      char **parg;
  12.150      char ifname[128];
  12.151  
  12.152 +    memset(ifname, 0, sizeof(ifname));
  12.153 +
  12.154      if (ifname1 != NULL)
  12.155          pstrcpy(ifname, sizeof(ifname), ifname1);
  12.156      else
  12.157 @@ -3611,7 +3638,7 @@ static int net_socket_mcast_create(struc
  12.158  
  12.159      val = 1;
  12.160      ret=setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 
  12.161 -                   (const char *)&val, sizeof(val));
  12.162 +                   (const char *)&val, sizeof(char));
  12.163      if (ret < 0) {
  12.164  	perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)");
  12.165  	goto fail;
  12.166 @@ -3893,7 +3920,7 @@ static int net_socket_mcast_init(VLANSta
  12.167  
  12.168  }
  12.169  
  12.170 -static int get_param_value(char *buf, int buf_size,
  12.171 +static int get_param_value(char *buf, size_t buf_size,
  12.172                             const char *tag, const char *str)
  12.173  {
  12.174      const char *p;
  12.175 @@ -4019,6 +4046,10 @@ static int net_client_init(const char *s
  12.176          char setup_script[1024];
  12.177          char bridge[16];
  12.178          int fd;
  12.179 +
  12.180 +	memset(ifname, 0, sizeof(ifname));
  12.181 +	memset(setup_script, 0, sizeof(setup_script));
  12.182 +
  12.183          if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
  12.184              fd = strtol(buf, NULL, 0);
  12.185              ret = -1;
  12.186 @@ -6914,7 +6945,6 @@ static int qemu_map_cache_init(void)
  12.187      nr_buckets = (((MAX_MCACHE_SIZE >> PAGE_SHIFT) +
  12.188                     (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1) >>
  12.189                    (MCACHE_BUCKET_SHIFT - PAGE_SHIFT));
  12.190 -    fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets);
  12.191  
  12.192      /*
  12.193       * Use mmap() directly: lets us allocate a big hash table with no up-front
  12.194 @@ -6923,8 +6953,9 @@ static int qemu_map_cache_init(void)
  12.195       */
  12.196      size = nr_buckets * sizeof(struct map_cache);
  12.197      size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
  12.198 +    fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx size %lu\n", nr_buckets, size);
  12.199      mapcache_entry = mmap(NULL, size, PROT_READ|PROT_WRITE,
  12.200 -                          MAP_SHARED|MAP_ANONYMOUS, 0, 0);
  12.201 +                          MAP_SHARED|MAP_ANON, -1, 0);
  12.202      if (mapcache_entry == MAP_FAILED) {
  12.203          errno = ENOMEM;
  12.204          return -1;
  12.205 @@ -7061,6 +7092,7 @@ int main(int argc, char **argv)
  12.206      unsigned long ioreq_pfn;
  12.207      extern void *shared_page;
  12.208      extern void *buffered_io_page;
  12.209 +    struct rlimit rl;
  12.210  #ifdef __ia64__
  12.211      unsigned long nr_pages;
  12.212      xen_pfn_t *page_array;
  12.213 @@ -7070,6 +7102,30 @@ int main(int argc, char **argv)
  12.214      char qemu_dm_logfilename[128];
  12.215      const char *direct_pci = NULL;
  12.216  
  12.217 +    /* Maximise rlimits. Needed where default constraints are tight (*BSD). */
  12.218 +    if (getrlimit(RLIMIT_STACK, &rl) != 0) {
  12.219 +       perror("getrlimit(RLIMIT_STACK)");
  12.220 +       exit(1);
  12.221 +    }
  12.222 +    rl.rlim_cur = rl.rlim_max;
  12.223 +    if (setrlimit(RLIMIT_STACK, &rl) != 0)
  12.224 +       perror("setrlimit(RLIMIT_STACK)");
  12.225 +    if (getrlimit(RLIMIT_DATA, &rl) != 0) {
  12.226 +       perror("getrlimit(RLIMIT_DATA)");
  12.227 +       exit(1);
  12.228 +    }
  12.229 +    rl.rlim_cur = rl.rlim_max;
  12.230 +    if (setrlimit(RLIMIT_DATA, &rl) != 0)
  12.231 +       perror("setrlimit(RLIMIT_DATA)");
  12.232 +    rl.rlim_cur = RLIM_INFINITY;
  12.233 +    rl.rlim_max = RLIM_INFINITY;
  12.234 +    if (setrlimit(RLIMIT_RSS, &rl) != 0)
  12.235 +       perror("setrlimit(RLIMIT_RSS)");
  12.236 +    rl.rlim_cur = RLIM_INFINITY;
  12.237 +    rl.rlim_max = RLIM_INFINITY;
  12.238 +    if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0)
  12.239 +       perror("setrlimit(RLIMIT_MEMLOCK)");
  12.240 +
  12.241      /* Ensure that SIGUSR2 is blocked by default when a new thread is created,
  12.242         then only the threads that use the signal unblock it -- this fixes a
  12.243         race condition in Qcow support where the AIO signal is misdelivered.  */
    13.1 --- a/tools/ioemu/vl.h	Thu Sep 27 15:22:29 2007 +0100
    13.2 +++ b/tools/ioemu/vl.h	Thu Sep 27 16:36:23 2007 +0100
    13.3 @@ -103,8 +103,8 @@ static inline char *realpath(const char 
    13.4  #endif
    13.5  
    13.6  /* cutils.c */
    13.7 -void pstrcpy(char *buf, int buf_size, const char *str);
    13.8 -char *pstrcat(char *buf, int buf_size, const char *s);
    13.9 +void pstrcpy(char *buf, size_t buf_size, const char *str);
   13.10 +char *pstrcat(char *buf, size_t buf_size, const char *s);
   13.11  int strstart(const char *str, const char *val, const char **ptr);
   13.12  int stristart(const char *str, const char *val, const char **ptr);
   13.13  
    14.1 --- a/tools/ioemu/vnc.c	Thu Sep 27 15:22:29 2007 +0100
    14.2 +++ b/tools/ioemu/vnc.c	Thu Sep 27 16:36:23 2007 +0100
    14.3 @@ -24,6 +24,9 @@
    14.4   * THE SOFTWARE.
    14.5   */
    14.6  
    14.7 +#include <sys/stat.h>
    14.8 +#include <sys/socket.h>
    14.9 +#include <netinet/in.h>
   14.10  #include "vl.h"
   14.11  #include "qemu_socket.h"
   14.12  #include <assert.h>