From d5d170d3a0c8e807990e68c4316d2b8a46dea6ef Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 6 May 2008 15:41:22 +0100 Subject: [PATCH] merge from in qemu upstream: "BSD portability fixes" From xen-unstable: changeset: 15970:04cc0e22a20a0bdf6ceefb016185175ee094ed30 user: Keir Fraser 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 Mostly merged. Dropped the ctype.h casts since we have those already, and also a few things that looked wrong. --- audio/mixeng.c | 4 ++++ audio/ossaudio.c | 2 +- bswap.h | 7 ++++++ cutils.c | 4 ++-- qemu-common.h | 4 ++-- vl.c | 60 ++++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 69 insertions(+), 12 deletions(-) diff --git a/audio/mixeng.c b/audio/mixeng.c index b668c524e..f4b800382 100644 --- a/audio/mixeng.c +++ b/audio/mixeng.c @@ -146,6 +146,7 @@ #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 */ }; /* diff --git a/audio/ossaudio.c b/audio/ossaudio.c index 2a300c21d..0bcd7f997 100644 --- a/audio/ossaudio.c +++ b/audio/ossaudio.c @@ -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 970c1bbe3..9b96822c8 100644 --- a/bswap.h +++ b/bswap.h @@ -5,6 +5,11 @@ #include +#ifdef _BSD +#include +#include +#else + #ifdef HAVE_BYTESWAP_H #include #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) diff --git a/cutils.c b/cutils.c index e8e022c7c..97d6080d0 100644 --- 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); diff --git a/qemu-common.h b/qemu-common.h index 66756bf7d..fb5723e0b 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -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 ec7674e81..925883532 100644 --- a/vl.c +++ b/vl.c @@ -39,6 +39,7 @@ #include "audio/audio.h" #include +#include #include #include #include @@ -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 { -- 2.39.5