Module Name: src Committed By: pooka Date: Sun Nov 18 19:29:41 UTC 2012
Modified Files: src/lib/librumpuser: rumpuser.c rumpuser_daemonize.c rumpuser_port.h sp_common.c Log Message: Fixes for Solarisa. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/lib/librumpuser/rumpuser.c cvs rdiff -u -r1.3 -r1.4 src/lib/librumpuser/rumpuser_daemonize.c \ src/lib/librumpuser/rumpuser_port.h cvs rdiff -u -r1.33 -r1.34 src/lib/librumpuser/sp_common.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/librumpuser/rumpuser.c diff -u src/lib/librumpuser/rumpuser.c:1.22 src/lib/librumpuser/rumpuser.c:1.23 --- src/lib/librumpuser/rumpuser.c:1.22 Wed Nov 14 09:22:58 2012 +++ src/lib/librumpuser/rumpuser.c Sun Nov 18 19:29:40 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.c,v 1.22 2012/11/14 09:22:58 pooka Exp $ */ +/* $NetBSD: rumpuser.c,v 1.23 2012/11/18 19:29:40 pooka Exp $ */ /* * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser.c,v 1.22 2012/11/14 09:22:58 pooka Exp $"); +__RCSID("$NetBSD: rumpuser.c,v 1.23 2012/11/18 19:29:40 pooka Exp $"); #endif /* !lint */ #include <sys/ioctl.h> @@ -46,9 +46,9 @@ __RCSID("$NetBSD: rumpuser.c,v 1.22 2012 #endif #include <assert.h> -#include <err.h> #include <errno.h> #include <fcntl.h> +#include <netdb.h> #include <poll.h> #include <signal.h> #include <stdarg.h> @@ -291,6 +291,11 @@ rumpuser_filemmap(int fd, off_t offset, } } +/* it's implicit */ +#if defined(__sun__) && !defined(MAP_FILE) +#define MAP_FILE 0 +#endif + mmflags = MAP_FILE; if (flags & RUMPUSER_FILEMMAP_SHARED) mmflags |= MAP_SHARED; @@ -343,7 +348,14 @@ rumpuser_open(const char *path, int rufl #define TESTSET(_ru_, _h_) if (ruflags & _ru_) flags |= _h_; TESTSET(RUMPUSER_OPEN_CREATE, O_CREAT); TESTSET(RUMPUSER_OPEN_EXCL, O_EXCL); +#ifdef O_DIRECT TESTSET(RUMPUSER_OPEN_DIRECT, O_DIRECT); +#else + if (ruflags & RUMPUSER_OPEN_DIRECT) { + *error = EOPNOTSUPP; + return -1; + } +#endif #undef TESTSET DOCALL_KLOCK(int, (open(path, flags, 0644))); @@ -535,10 +547,10 @@ rumpuser_gethostname(char *name, size_t char tmp[MAXHOSTNAMELEN]; if (gethostname(tmp, sizeof(tmp)) == -1) { - snprintf(name, namelen, "rump-%05d.rumpdomain", getpid()); + snprintf(name, namelen, "rump-%05d.rumpdomain", (int)getpid()); } else { snprintf(name, namelen, "rump-%05d.%s.rumpdomain", - getpid(), tmp); + (int)getpid(), tmp); } *error = 0; @@ -743,6 +755,9 @@ rumpuser_getnhostcpu(void) free(line); fclose(fp); } +#elif __sun__ + /* XXX: this is just a rough estimate ... */ + ncpu = sysconf(_SC_NPROCESSORS_ONLN); #endif return ncpu; Index: src/lib/librumpuser/rumpuser_daemonize.c diff -u src/lib/librumpuser/rumpuser_daemonize.c:1.3 src/lib/librumpuser/rumpuser_daemonize.c:1.4 --- src/lib/librumpuser/rumpuser_daemonize.c:1.3 Fri Jul 27 09:09:05 2012 +++ src/lib/librumpuser/rumpuser_daemonize.c Sun Nov 18 19:29:40 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser_daemonize.c,v 1.3 2012/07/27 09:09:05 pooka Exp $ */ +/* $NetBSD: rumpuser_daemonize.c,v 1.4 2012/11/18 19:29:40 pooka Exp $ */ /* * Copyright (c) 2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser_daemonize.c,v 1.3 2012/07/27 09:09:05 pooka Exp $"); +__RCSID("$NetBSD: rumpuser_daemonize.c,v 1.4 2012/11/18 19:29:40 pooka Exp $"); #endif /* !lint */ #include <sys/types.h> @@ -36,10 +36,15 @@ __RCSID("$NetBSD: rumpuser_daemonize.c,v #include <errno.h> #include <fcntl.h> -#include <paths.h> #include <stdio.h> #include <unistd.h> +#ifdef __sun__ +#define _PATH_DEVNULL "/dev/null" +#else +#include <paths.h> +#endif + static int isdaemonizing; static int daemonpipe[2]; Index: src/lib/librumpuser/rumpuser_port.h diff -u src/lib/librumpuser/rumpuser_port.h:1.3 src/lib/librumpuser/rumpuser_port.h:1.4 --- src/lib/librumpuser/rumpuser_port.h:1.3 Mon Sep 3 11:33:35 2012 +++ src/lib/librumpuser/rumpuser_port.h Sun Nov 18 19:29:40 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser_port.h,v 1.3 2012/09/03 11:33:35 pooka Exp $ */ +/* $NetBSD: rumpuser_port.h,v 1.4 2012/11/18 19:29:40 pooka Exp $ */ /* * Portability header for non-NetBSD platforms. @@ -15,6 +15,10 @@ #ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ #define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ +#ifdef __sun__ +typedef long register_t; +#endif + #ifdef __NetBSD__ #include <sys/cdefs.h> #include <sys/param.h> @@ -49,7 +53,7 @@ #include <sys/types.h> #include <sys/param.h> -#if defined(__linux__) +#if defined(__linux__) || defined(__sun__) #include <errno.h> #include <stdlib.h> #include <string.h> @@ -74,6 +78,21 @@ getenv_r(const char *name, char *buf, si } #endif +/* Solarisa 10 has memalign() but no posix_memalign() */ +#if defined(__sun__) +#include <stdlib.h> + +static inline int +posix_memalign(void **ptr, size_t align, size_t size) +{ + + *ptr = memalign(align, size); + if (*ptr == NULL) + return ENOMEM; + return 0; +} +#endif /* __sun__ */ + #ifndef __RCSID #define __RCSID(a) #endif @@ -86,7 +105,7 @@ getenv_r(const char *name, char *buf, si #define _DIAGASSERT(_p_) #endif -#ifdef __linux__ +#if defined(__linux__) || defined(__sun__) #define SA_SETLEN(a,b) #else /* BSD */ #define SA_SETLEN(_sa_, _len_) ((struct sockaddr *)_sa_)->sa_len = _len_ @@ -121,7 +140,7 @@ getenv_r(const char *name, char *buf, si #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_)) #endif -#ifdef __linux__ +#if defined(__linux__) || defined(__sun__) #define arc4random() random() #endif @@ -129,11 +148,24 @@ getenv_r(const char *name, char *buf, si #define __NetBSD_Prereq__(a,b,c) 0 #endif -#if !defined(__CMSG_ALIGN) #include <sys/socket.h> + +#if !defined(__CMSG_ALIGN) #ifdef CMSG_ALIGN #define __CMSG_ALIGN(a) CMSG_ALIGN(a) #endif #endif +#ifndef PF_LOCAL +#define PF_LOCAL PF_UNIX +#endif +#ifndef AF_LOCAL +#define AF_LOCAL AF_UNIX +#endif + +/* pfft, but what are you going to do? */ +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */ Index: src/lib/librumpuser/sp_common.c diff -u src/lib/librumpuser/sp_common.c:1.33 src/lib/librumpuser/sp_common.c:1.34 --- src/lib/librumpuser/sp_common.c:1.33 Fri Sep 21 14:33:03 2012 +++ src/lib/librumpuser/sp_common.c Sun Nov 18 19:29:40 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: sp_common.c,v 1.33 2012/09/21 14:33:03 pooka Exp $ */ +/* $NetBSD: sp_common.c,v 1.34 2012/11/18 19:29:40 pooka Exp $ */ /* * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. @@ -86,8 +86,10 @@ mydprintf(const char *fmt, ...) #define host_setsockopt setsockopt #endif -#define IOVPUT(_io_, _b_) _io_.iov_base = &_b_; _io_.iov_len = sizeof(_b_); -#define IOVPUT_WITHSIZE(_io_, _b_, _l_) _io_.iov_base = _b_; _io_.iov_len = _l_; +#define IOVPUT(_io_, _b_) _io_.iov_base = \ + (void *)&_b_; _io_.iov_len = sizeof(_b_); +#define IOVPUT_WITHSIZE(_io_, _b_, _l_) _io_.iov_base = \ + (void *)(_b_); _io_.iov_len = _l_; #define SENDIOV(_spc_, _iov_) dosend(_spc_, _iov_, __arraycount(_iov_)) /* @@ -346,7 +348,8 @@ dosend(struct spclient *spc, struct iove _DIAGASSERT(n == 0); break; } else { - iov[0].iov_base = (uint8_t *)iov[0].iov_base + n; + iov[0].iov_base = + (void *)((uint8_t *)iov[0].iov_base + n); iov[0].iov_len -= n; } } @@ -630,11 +633,11 @@ static char parsedurl[256]; static int unix_parse(const char *addr, struct sockaddr **sa, int allow_wildcard) { - struct sockaddr_un sun; + struct sockaddr_un s_un; size_t slen; int savepath = 0; - if (strlen(addr) >= sizeof(sun.sun_path)) + if (strlen(addr) >= sizeof(s_un.sun_path)) return ENAMETOOLONG; /* @@ -644,8 +647,8 @@ unix_parse(const char *addr, struct sock * one and the server does a chdir() between now than the * cleanup. */ - memset(&sun, 0, sizeof(sun)); - sun.sun_family = AF_LOCAL; + memset(&s_un, 0, sizeof(s_un)); + s_un.sun_family = AF_LOCAL; if (*addr != '/') { char mywd[PATH_MAX]; @@ -653,30 +656,31 @@ unix_parse(const char *addr, struct sock fprintf(stderr, "warning: cannot determine cwd, " "omitting socket cleanup\n"); } else { - if (strlen(addr)+strlen(mywd)+1 >= sizeof(sun.sun_path)) + if (strlen(addr)+strlen(mywd)+1 + >= sizeof(s_un.sun_path)) return ENAMETOOLONG; - strcpy(sun.sun_path, mywd); - strcat(sun.sun_path, "/"); + strcpy(s_un.sun_path, mywd); + strcat(s_un.sun_path, "/"); savepath = 1; } } - strcat(sun.sun_path, addr); -#ifdef __linux__ - slen = sizeof(sun); + strcat(s_un.sun_path, addr); +#if defined(__linux__) || defined(__sun__) + slen = sizeof(s_un); #else - sun.sun_len = SUN_LEN(&sun); - slen = sun.sun_len+1; /* get the 0 too */ + s_un.sun_len = SUN_LEN(&s_un); + slen = s_un.sun_len+1; /* get the 0 too */ #endif if (savepath && *parsedurl == '\0') { snprintf(parsedurl, sizeof(parsedurl), - "unix://%s", sun.sun_path); + "unix://%s", s_un.sun_path); } *sa = malloc(slen); if (*sa == NULL) return errno; - memcpy(*sa, &sun, slen); + memcpy(*sa, &s_un, slen); return 0; } @@ -684,13 +688,13 @@ unix_parse(const char *addr, struct sock static void unix_cleanup(struct sockaddr *sa) { - struct sockaddr_un *sun = (void *)sa; + struct sockaddr_un *s_sun = (void *)sa; /* * cleanup only absolute paths. see unix_parse() above */ - if (*sun->sun_path == '/') { - unlink(sun->sun_path); + if (*s_sun->sun_path == '/') { + unlink(s_sun->sun_path); } }