]> xenbits.xensource.com Git - qemu-xen-4.4-testing.git/commitdiff
merge from in qemu upstream: "BSD portability fixes"
authorIan Jackson <iwj@mariner.uk.xensource.com>
Tue, 6 May 2008 14:41:22 +0000 (15:41 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 12 May 2008 11:20:11 +0000 (12:20 +0100)
From xen-unstable:

 changeset:   15970:04cc0e22a20a0bdf6ceefb016185175ee094ed30
 user:        Keir Fraser <keir@xensource.com>
 date:        Thu Sep 27 16:36:23 2007 +0100
 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
 description:
 ioemu: Fixes for BSD.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Mostly merged.  Dropped the ctype.h casts since we have those already,
and also a few things that looked wrong.

audio/mixeng.c
audio/ossaudio.c
bswap.h
cutils.c
qemu-common.h
vl.c

index b668c524e7ec0b525361cfab16279abd54aeef20..f4b800382ed66341bd315eb6acfbd6e56aa4d3e2 100644 (file)
 #undef SHIFT
 
 t_sample *mixeng_conv[2][2][2][3] = {
+#ifndef _BSD
     {
         {
             {
@@ -198,9 +199,11 @@ t_sample *mixeng_conv[2][2][2][3] = {
             }
         }
     }
+#endif /* !_BSD */
 };
 
 f_sample *mixeng_clip[2][2][2][3] = {
+#ifndef _BSD
     {
         {
             {
@@ -253,6 +256,7 @@ f_sample *mixeng_clip[2][2][2][3] = {
             }
         }
     }
+#endif /* !_BSD */
 };
 
 /*
index 2a300c21de7b3f7c9bd95e5487bfc718fee2ad1a..0bcd7f997b0fbf9ce371205cde4b02713df02aa2 100644 (file)
@@ -237,7 +237,7 @@ static int oss_open (int in, struct oss_params *req,
         goto err;
     }
 
-    if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) {
+    if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
         oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
         goto err;
     }
diff --git a/bswap.h b/bswap.h
index 970c1bbe349b16cbfbb63a200da0fbfa7be66eb3..9b96822c830640ee4ea60c303b08a1d7c667e1b1 100644 (file)
--- a/bswap.h
+++ b/bswap.h
@@ -5,6 +5,11 @@
 
 #include <inttypes.h>
 
+#ifdef _BSD
+#include <sys/endian.h>
+#include <sys/types.h>
+#else
+
 #ifdef HAVE_BYTESWAP_H
 #include <byteswap.h>
 #else
@@ -73,6 +78,8 @@ static inline void bswap64s(uint64_t *s)
     *s = bswap64(*s);
 }
 
+#endif /* _BSD */
+
 #if defined(WORDS_BIGENDIAN)
 #define be_bswap(v, size) (v)
 #define le_bswap(v, size) bswap ## size(v)
index e8e022c7ce473b52a39a90b369c9aeca940f7eb9..97d6080d0a0d9a0d8402a82419fed3e675ab7dbf 100644 (file)
--- a/cutils.c
+++ b/cutils.c
@@ -23,7 +23,7 @@
  */
 #include "qemu-common.h"
 
-void pstrcpy(char *buf, int buf_size, const char *str)
+void pstrcpy(char *buf, size_t buf_size, const char *str)
 {
     int c;
     char *q = buf;
@@ -41,7 +41,7 @@ void pstrcpy(char *buf, int buf_size, const char *str)
 }
 
 /* strcat and truncate. */
-char *pstrcat(char *buf, int buf_size, const char *s)
+char *pstrcat(char *buf, size_t buf_size, const char *s)
 {
     int len;
     len = strlen(buf);
index 66756bf7d8a294986337c1cb7369ec9bbb7bfa1a..fb5723e0b2b74779f06d9521ec53a66efe1a3887 100644 (file)
@@ -80,8 +80,8 @@ void qemu_get_timedate(struct tm *tm, int offset);
 int qemu_timedate_diff(struct tm *tm);
 
 /* cutils.c */
-void pstrcpy(char *buf, int buf_size, const char *str);
-char *pstrcat(char *buf, int buf_size, const char *s);
+void pstrcpy(char *buf, size_t buf_size, const char *str);
+char *pstrcat(char *buf, size_t buf_size, const char *s);
 int strstart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
 time_t mktimegm(struct tm *tm);
diff --git a/vl.c b/vl.c
index ec7674e8189eece82e11afbc3f0a296ecf9c4e86..925883532d4fce1c9d66e839d5032fcc165d3361 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -39,6 +39,7 @@
 #include "audio/audio.h"
 
 #include <unistd.h>
+#include <stdlib.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <time.h>
@@ -2260,7 +2261,7 @@ static CharDriverState *qemu_chr_open_stdio(void)
     return chr;
 }
 
-#if defined(__linux__) || defined(__sun__)
+#if defined(__linux__) || defined(__sun__) || defined(__NetBSD__) || defined(__OpenBSD__)
 static CharDriverState *qemu_chr_open_pty(void)
 {
     struct termios tty;
@@ -2407,12 +2408,12 @@ static CharDriverState *qemu_chr_open_tty(const char *filename)
     qemu_chr_reset(chr);
     return chr;
 }
-#else  /* ! __linux__ && ! __sun__ */
+#else  /* ! __linux__ etc. (qemu_chr_open_pty) */
 static CharDriverState *qemu_chr_open_pty(void)
 {
     return NULL;
 }
-#endif /* __linux__ || __sun__ */
+#endif  /* ! __linux__ etc. (qemu_chr_open_pty) */
 
 #if defined(__linux__)
 typedef struct {
@@ -2431,6 +2432,7 @@ static int pp_hw_mode(ParallelCharDriver *s, uint16_t mode)
     return 1;
 }
 
+#if defined(__linux__)
 static int pp_ioctl(CharDriverState *chr, int cmd, void *arg)
 {
     ParallelCharDriver *drv = chr->opaque;
@@ -3536,7 +3538,7 @@ static int parse_macaddr(uint8_t *macaddr, const char *p)
     return -1;
 }
 
-static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
+static int get_str_sep(char *buf, size_t buf_size, const char **pp, int sep)
 {
     const char *p, *p1;
     int len;
@@ -3972,18 +3974,28 @@ static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
 static int tap_open(char *ifname, int ifname_size)
 {
     int fd;
+#ifndef TAPGIFNAME
     char *dev;
     struct stat s;
+#endif
 
     TFR(fd = open("/dev/tap", O_RDWR));
     if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
         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;
@@ -4131,7 +4143,6 @@ static int tap_open(char *ifname, int ifname_size)
 
     TFR(fd = open("/dev/net/tun", O_RDWR));
     if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
         return -1;
     }
     memset(&ifr, 0, sizeof(ifr));
@@ -4195,6 +4206,8 @@ static int net_tap_init(VLANState *vlan, const char *ifname1,
     int fd;
     char ifname[128];
 
+    memset(ifname, 0, sizeof(ifname));
+
     if (ifname1 != NULL)
         pstrcpy(ifname, sizeof(ifname), ifname1);
     else
@@ -4671,7 +4684,7 @@ static const char *get_opt_value(char *buf, int buf_size, const char *p)
     return p;
 }
 
-static int get_param_value(char *buf, int buf_size,
+static int get_param_value(char *buf, size_t buf_size,
                            const char *tag, const char *str)
 {
     const char *p;
@@ -4810,6 +4823,10 @@ static int net_client_init(const char *str)
         char ifname[64];
         char setup_script[1024], down_script[1024];
         int fd;
+
+       memset(ifname, 0, sizeof(ifname));
+       memset(setup_script, 0, sizeof(setup_script));
+
         vlan->nb_host_devs++;
         if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
             fd = strtol(buf, NULL, 0);
@@ -8225,9 +8242,38 @@ int main(int argc, char **argv)
     char usb_devices[MAX_USB_CMDLINE][128];
     int usb_devices_index;
     int fds[2];
+#ifndef CONFIG_STUBDOM
+    struct rlimit rl;
+#endif
     const char *pid_file = NULL;
     VLANState *vlan;
 
+#if !defined(__sun__) && !defined(CONFIG_STUBDOM)
+    /* Maximise rlimits. Needed where default constraints are tight (*BSD). */
+    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)");
+ #endif
     QEMU_LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
     {