diff options
-rwxr-xr-x | Win32Build/mingw/CHANGES-libevent | 80 | ||||
-rwxr-xr-x | Win32Build/mingw/README | 8 | ||||
-rwxr-xr-x | Win32Build/mingw/libevent-1.1b-mingw-custom.diff | 338 | ||||
-rw-r--r-- | configure.in | 72 | ||||
-rw-r--r-- | src/common/compat.c | 72 | ||||
-rw-r--r-- | src/common/compat.h | 19 | ||||
-rw-r--r-- | src/or/config.c | 2 | ||||
-rw-r--r-- | src/or/cpuworker.c | 2 | ||||
-rw-r--r-- | src/or/dns.c | 2 | ||||
-rw-r--r-- | src/or/main.c | 5 |
10 files changed, 561 insertions, 39 deletions
diff --git a/Win32Build/mingw/CHANGES-libevent b/Win32Build/mingw/CHANGES-libevent new file mode 100755 index 000000000..3d24c1843 --- /dev/null +++ b/Win32Build/mingw/CHANGES-libevent @@ -0,0 +1,80 @@ +Changes related to compilation under MinGW/any sane win32 gcc
+=============================================================
+
+* event.c
+- If gcc include "WIN32-Code/misc.h" instead of "misc.h"
+
+* WIN32-Code/misc.h
+- Add struct prototypes for timeval and timezone
+
+* buffer.c
+- changed type of "i" from "u_int" to "unsigned int". My MinGW wasn't
+ recognizing it. (u_int is normally typedef'ed to unsigned int, right?)
+
+* evbuffer.c
+- removed incorrect win32 error checking, see bufferevent_writecb().
+ (this needs to be fixed by anyone planning to use evbuffer on win32)
+
+* log.c
+- If gcc include "WIN32-Code/misc.h" instead of "misc.h"
+
+* WIN32-Code/misc.c
+- if gcc, include "misc.h"
+- added newline at end of file to shut up gcc
+
+* WIN32-Code/win32.c
+- Altered the prototypes of win32_*() so their argument types didn't conflict
+ with the function definitions.
+- Casted types of win32_* to void inside win32ops so that it didn't conflict
+ with the definition of eventops (gcc doesn't like this)
+- Altered prototype of signal_handler to be static since definition is static
+ (why wasn't it like this before)
+- Casted the second argument of signal() to be void*, some reason my MinGW
+ doesn't have sighandler_t typedef'ed.
+
+* configure.in
+- some code to check if we are compiling for WIN32.
+
+* Makefile.am
+- if BUILD_WIN32 is defined, include WIN32-Code/misc.c and
+ WIN32-Code/win32.c as source files.
+- if WIN32, do not build test stuff. (not windows friendly)
+- if WIN32, explicitly link to ws2_32.dll
+
+Notes
+-----
+- We assume that if __GNUC__ is undefined we are building with MSVC
+- If the user wishes to build a dll, they are on their own, the syntax is
+ compiler specific.
+- Getting this warning from libtool, no idea why
+ "libtool: link: warning: undefined symbols not allowed in i686-pc-mingw32
+ shared libraries"
+
+
+Changes related to "custom eventops"
+====================================
+
+* configure.in
+- add argument --enable-custom-eventops, sets USE_CUSTOM_EVENTOPS in config.h
+- add argument --enable-custom-code, sets USE_CUSTOM_CODE in Makefile
+
+* Makefile.am
+- if USE_CUSTOM_CODE, include custom/custom.c as a source file.
+ (I can't think of a way to pass a string to Makefile.am, so I'm stuck naming
+ the new source file custom.c. It just seems simpler this way, but I'm open
+ to suggestions)
+
+* event.c
+- if USE_CUSTOM_EVENTOPS, use eventops as defined in custom-eventops.h
+
+Notes
+-----
+Just in case it isn't completely obvious, the goal of "custom eventops" is to
+allow the user to include their own event processing system without requiring a
+fork. This is accomplished through two parts. Firstly, by allowing the user to
+redefine eventops. (for example, the user may wish to use epoll() exclusively).
+Secondly, by allowing the user to include their own code to support a private
+eventop (note, this may not be necessary, as the user may choose to include
+already defined eventop's.
+
+
diff --git a/Win32Build/mingw/README b/Win32Build/mingw/README new file mode 100755 index 000000000..67e75cd27 --- /dev/null +++ b/Win32Build/mingw/README @@ -0,0 +1,8 @@ +The current SVN version of Tor should compile with MinGW. + +OpenSSL and libz both compile on MinGW out of the box. + +libevent 1.1b will not build unless you apply the diff in this directory. + + + diff --git a/Win32Build/mingw/libevent-1.1b-mingw-custom.diff b/Win32Build/mingw/libevent-1.1b-mingw-custom.diff new file mode 100755 index 000000000..350586e35 --- /dev/null +++ b/Win32Build/mingw/libevent-1.1b-mingw-custom.diff @@ -0,0 +1,338 @@ +Only in libevent-1.1b: CHANGES +Only in libevent-1.1b: Makefile +diff -uwr libevent-1.1b-old/Makefile.am libevent-1.1b/Makefile.am +--- libevent-1.1b-old/Makefile.am Wed Aug 9 22:16:35 2006 ++++ libevent-1.1b/Makefile.am Sat Sep 2 03:49:26 2006 +@@ -1,6 +1,5 @@ + AUTOMAKE_OPTIONS = foreign no-dependencies + +-SUBDIRS = . sample test + + EXTRA_DIST = acconfig.h event.h event-internal.h log.h evsignal.h event.3 \ + kqueue.c epoll_sub.c epoll.c select.c rtsig.c poll.c signal.c \ +@@ -20,8 +19,29 @@ + + lib_LTLIBRARIES = libevent.la + +-libevent_la_SOURCES = event.c buffer.c evbuffer.c log.c +-libevent_la_LIBADD = @LTLIBOBJS@ ++ ++if BUILD_WIN32 ++ ++SUBDIRS = . sample ++SYS_LIBS = -lws2_32 ++SYS_SRC = WIN32-Code/misc.c WIN32-Code/win32.c ++ ++else ++ ++SUBDIRS = . sample test ++SYS_LIBS = ++SYS_SRC = ++ ++endif ++ ++if USE_CUSTOM_CODE ++CUST_SRC = custom/custom.c ++else ++CUST_SRC = ++endif ++ ++libevent_la_SOURCES = event.c buffer.c evbuffer.c log.c $(CUST_SRC) $(SYS_SRC) ++libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS) + libevent_la_LDFLAGS = -release @VERSION@ -version-info 1:2:0 + + include_HEADERS = event.h +Only in libevent-1.1b: Makefile.in +diff -uwr libevent-1.1b-old/WIN32-Code/misc.c libevent-1.1b/WIN32-Code/misc.c +--- libevent-1.1b-old/WIN32-Code/misc.c Wed Aug 9 21:01:14 2006 ++++ libevent-1.1b/WIN32-Code/misc.c Fri Sep 1 22:21:31 2006 +@@ -4,6 +4,12 @@ + #include <sys/timeb.h> + #include <time.h> + ++#ifdef __GNUC__ ++/*our prototypes for timeval and timezone are in here, just in case the above ++ headers don't have them*/ ++#include "misc.h" ++#endif ++ + /**************************************************************************** + * + * Function: gettimeofday(struct timeval *, struct timezone *) +diff -uwr libevent-1.1b-old/WIN32-Code/misc.h libevent-1.1b/WIN32-Code/misc.h +--- libevent-1.1b-old/WIN32-Code/misc.h Wed Aug 9 21:01:14 2006 ++++ libevent-1.1b/WIN32-Code/misc.h Fri Sep 1 18:47:09 2006 +@@ -1,6 +1,9 @@ + #ifndef MISC_H + #define MISC_H + ++struct timezone; ++struct timeval; ++ + int gettimeofday(struct timeval *,struct timezone *); + + #endif +diff -uwr libevent-1.1b-old/WIN32-Code/win32.c libevent-1.1b/WIN32-Code/win32.c +--- libevent-1.1b-old/WIN32-Code/win32.c Wed Aug 9 21:25:48 2006 ++++ libevent-1.1b/WIN32-Code/win32.c Sat Sep 2 00:45:55 2006 +@@ -60,7 +60,8 @@ + /* MSDN says this is required to handle SIGFPE */ + volatile double SIGFPE_REQ = 0.0f; + +-int signal_handler(int sig); ++static int signal_handler(int sig); ++ + void signal_process(void); + int signal_recalc(void); + +@@ -77,20 +78,21 @@ + }; + + void *win32_init (void); +-int win32_insert (void *, struct event *); +-int win32_del (void *, struct event *); ++int win32_insert (struct win32op *, struct event *); ++int win32_del (struct win32op *, struct event *); + int win32_recalc (struct event_base *base, void *, int); +-int win32_dispatch (struct event_base *base, void *, struct timeval *); ++int win32_dispatch (struct event_base *base, struct win32op *, struct timeval *); + + struct eventop win32ops = { + "win32", + win32_init, +- win32_insert, +- win32_del, ++ (int (*) (void*, struct event*)) win32_insert, ++ (int (*) (void*, struct event*)) win32_del, + win32_recalc, +- win32_dispatch ++ (int (*) (struct event_base*, void*, struct timeval*)) win32_dispatch + }; + ++ + #define FD_SET_ALLOC_SIZE(n) ((sizeof(struct win_fd_set) + ((n)-1)*sizeof(SOCKET))) + + static int +@@ -213,7 +215,13 @@ + if (ev->ev_events & (EV_READ|EV_WRITE)) + event_errx(1, "%s: EV_SIGNAL incompatible use", + __func__); ++ ++#ifndef __GNUC__ + if((int)signal(EVENT_SIGNAL(ev), signal_handler) == -1) ++#else ++ if((int)signal(EVENT_SIGNAL(ev), (void*) signal_handler) == -1) ++#endif ++ + return (-1); + + return (0); +@@ -382,8 +390,13 @@ + + /* Reinstall our signal handler. */ + TAILQ_FOREACH(ev, &signalqueue, ev_signal_next) { ++#ifndef __GNUC__ + if((int)signal(EVENT_SIGNAL(ev), signal_handler) == -1) ++#else ++ if((int)signal(EVENT_SIGNAL(ev), (void*) signal_handler) == -1) ++#endif + return (-1); ++ + } + return (0); + } +Only in libevent-1.1b-old/: aclocal.m4 +Only in libevent-1.1b: autom4te.cache +diff -uwr libevent-1.1b-old/buffer.c libevent-1.1b/buffer.c +--- libevent-1.1b-old/buffer.c Wed Aug 9 22:01:40 2006 ++++ libevent-1.1b/buffer.c Fri Sep 1 18:52:56 2006 +@@ -197,7 +197,7 @@ + u_char *data = EVBUFFER_DATA(buffer); + size_t len = EVBUFFER_LENGTH(buffer); + char *line; +- u_int i; ++ unsigned int i; + + for (i = 0; i < len; i++) { + if (data[i] == '\r' || data[i] == '\n') +Only in libevent-1.1b: config.guess +Only in libevent-1.1b: config.h +diff -uwr libevent-1.1b-old/config.h.in libevent-1.1b/config.h.in +--- libevent-1.1b-old/config.h.in Wed Aug 9 21:27:37 2006 ++++ libevent-1.1b/config.h.in Sat Sep 2 02:23:17 2006 +@@ -223,6 +223,9 @@ + /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ + #undef TIME_WITH_SYS_TIME + ++/* Define to 1 if you want to use a custom eventops variable */ ++#undef USE_CUSTOM_EVENTOPS ++ + /* Version number of package */ + #undef VERSION + +@@ -232,11 +235,9 @@ + /* Define to empty if `const' does not conform to ANSI C. */ + #undef const + +-/* Define to `__inline__' or `__inline' if that's what the C compiler +- calls it, or to nothing if 'inline' is not supported under any name. */ +-#ifndef __cplusplus ++/* Define as `__inline' if that's what the C compiler calls it, or to nothing ++ if it is not supported. */ + #undef inline +-#endif + + /* Define to `int' if <sys/types.h> does not define. */ + #undef pid_t +Only in libevent-1.1b: config.h.in~ +Only in libevent-1.1b: config.log +Only in libevent-1.1b: config.status +Only in libevent-1.1b: configure +diff -uwr libevent-1.1b-old/configure.in libevent-1.1b/configure.in +--- libevent-1.1b-old/configure.in Wed Aug 9 22:05:17 2006 ++++ libevent-1.1b/configure.in Sat Sep 2 03:40:15 2006 +@@ -21,6 +21,18 @@ + CFLAGS="$CFLAGS -Wall" + fi + ++AC_ARG_ENABLE(custom-eventops, ++ [ --enable-custom-eventops Use custom eventops variable], ++ AC_DEFINE([USE_CUSTOM_EVENTOPS],[1], ++ [Define to 1 to use a custom eventops variable]) ++ ,) ++AC_ARG_ENABLE(custom-code, ++ [ --enable-custom-code Use custom code from custom/], ++ customcodev=true, ++ customcodev=false) ++ ++AM_CONDITIONAL(USE_CUSTOM_CODE, test x$customcodev = xtrue) ++ + AC_PROG_LIBTOOL + + dnl Uncomment "AC_DISABLE_SHARED" to make shared librraries not get +@@ -110,6 +122,22 @@ + AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no) + ) + fi ++ ++dnl - check if the macro WIN32 is defined on this compiler. ++dnl - (this is how we check for a windows version of GCC) ++AC_MSG_CHECKING(for WIN32) ++AC_TRY_COMPILE(, ++ [ ++ #ifndef WIN32 ++ #error ++ #endif ++ ], ++ bwin32=true; AC_MSG_RESULT(yes), ++ bwin32=false; AC_MSG_RESULT(no), ++) ++ ++AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue) ++ + + dnl Checks for typedefs, structures, and compiler characteristics. + AC_C_CONST +diff -uwr libevent-1.1b-old/evbuffer.c libevent-1.1b/evbuffer.c +--- libevent-1.1b-old/evbuffer.c Wed Aug 9 21:01:14 2006 ++++ libevent-1.1b/evbuffer.c Fri Sep 1 19:18:13 2006 +@@ -154,12 +154,20 @@ + if (EVBUFFER_LENGTH(bufev->output)) { + res = evbuffer_write(bufev->output, fd); + if (res == -1) { ++#ifndef WIN32 ++/*todo. evbuffer uses WriteFile when WIN32 is set. WIN32 system calls do not ++ *set errno. thus this error checking is not portable*/ + if (errno == EAGAIN || + errno == EINTR || + errno == EINPROGRESS) + goto reschedule; + /* error case */ + what |= EVBUFFER_ERROR; ++ ++#else ++ goto reschedule; ++#endif ++ + } else if (res == 0) { + /* eof case */ + what |= EVBUFFER_EOF; +@@ -181,6 +189,7 @@ + return; + + reschedule: ++ + if (EVBUFFER_LENGTH(bufev->output) != 0) + bufferevent_add(&bufev->ev_write, bufev->timeout_write); + return; +diff -uwr libevent-1.1b-old/event.c libevent-1.1b/event.c +--- libevent-1.1b-old/event.c Wed Aug 9 21:25:48 2006 ++++ libevent-1.1b/event.c Sat Sep 2 04:22:05 2006 +@@ -30,8 +30,14 @@ + #define WIN32_LEAN_AND_MEAN + #include <windows.h> + #undef WIN32_LEAN_AND_MEAN ++ ++#ifdef __GNUC__ ++#include "WIN32-Code/misc.h" ++#else + #include "misc.h" + #endif ++ ++#endif + #include <sys/types.h> + #include <sys/tree.h> + #ifdef HAVE_SYS_TIME_H +@@ -53,6 +59,7 @@ + #include "event-internal.h" + #include "log.h" + ++ + #ifdef HAVE_SELECT + extern const struct eventop selectops; + #endif +@@ -75,6 +82,8 @@ + extern const struct eventop win32ops; + #endif + ++#ifndef USE_CUSTOM_EVENTOPS ++ + /* In order of preference */ + const struct eventop *eventops[] = { + #ifdef HAVE_WORKING_KQUEUE +@@ -101,6 +110,11 @@ + NULL + }; + ++#else ++#include "custom-eventops.h" ++#endif //USE_CUSTOM_EVENTOPS ++ ++ + /* Global state */ + struct event_list signalqueue; + +Only in libevent-1.1b: libtool +diff -uwr libevent-1.1b-old/log.c libevent-1.1b/log.c +--- libevent-1.1b-old/log.c Wed Aug 9 21:01:14 2006 ++++ libevent-1.1b/log.c Fri Sep 1 19:09:45 2006 +@@ -45,8 +45,14 @@ + #define WIN32_LEAN_AND_MEAN + #include <windows.h> + #undef WIN32_LEAN_AND_MEAN ++ ++#ifdef __GNUC__ ++#include "WIN32-Code/misc.h" ++#else + #include "misc.h" + #endif ++ ++#endif + #include <sys/types.h> + #include <sys/tree.h> + #ifdef HAVE_SYS_TIME_H +Only in libevent-1.1b/sample: Makefile +Only in libevent-1.1b/sample: Makefile.in +Only in libevent-1.1b: stamp-h1 +Only in libevent-1.1b/test: Makefile +Only in libevent-1.1b/test: Makefile.in diff --git a/configure.in b/configure.in index 0a699ecd7..9f1877647 100644 --- a/configure.in +++ b/configure.in @@ -74,6 +74,36 @@ AC_PROG_CC AC_PROG_MAKE_SET AC_PROG_RANLIB + +# If WIN32 is defined and non-zero, we are building for win32 +AC_MSG_CHECKING([for win32]) +AC_TRY_COMPILE(, +[ +#ifdef WIN32 +#if WIN32 +//all is well +#else +#error +#endif +#else +#error +#endif +], +bwin32=true; AC_MSG_RESULT([yes]), +bwin32=false; AC_MSG_RESULT([no]) +) + + +if test $bwin32 = true; then + +AC_DEFINE(MS_WINDOWS,1, [Define to 1 if we are building for a Windows platform.]) + +if test $eventdns = true; then +AC_MSG_ERROR([tor+eventdns not yet supported on Windows.]) +fi + +fi + # The big search for OpenSSL # copied from openssh's configure.ac tryssldir="" @@ -133,8 +163,13 @@ AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [ le_found=no for ledir in $trylibeventdir "" $prefix /usr/local ; do LDFLAGS="$saved_LDFLAGS" - LIBS="$saved_LIBS -levent" - + + if test $bwin32 = true; then + LIBS="$saved_LIBS -levent -lws2_32" + else + LIBS="$saved_LIBS -levent" + fi + # Skip the directory if it isn't there. if test ! -z "$ledir" -a ! -d "$ledir" ; then continue; @@ -173,7 +208,12 @@ AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [ AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir]) fi ]) + +if test $bwin32 = true; then +LIBS="$LIBS -levent -lws2_32" +else LIBS="$LIBS -levent" +fi if test $ac_cv_libevent_dir != "(system)"; then if test -d "$ac_cv_libevent_dir/lib" ; then LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS" @@ -233,8 +273,13 @@ AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssl_dir, [ ssl_found=no for ssldir in $tryssldir "" $prefix /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /usr/pkg /opt /opt/openssl ; do LDFLAGS="$saved_LDFLAGS" - LIBS="$saved_LIBS -lssl -lcrypto" - + + if test $bwin32 = true; then + LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32" + else + LIBS="$LIBS -lssl -lcrypto" + fi + # Skip the directory if it isn't there. if test ! -z "$ssldir" -a ! -d "$ssldir" ; then continue; @@ -272,7 +317,13 @@ AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssl_dir, [ AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir]) fi ]) + +if test $bwin32 = true; then +LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32" +else LIBS="$LIBS -lssl -lcrypto" +fi + if test "$ac_cv_openssl_dir" != "(system)"; then if test -d "$ac_cv_openssl_dir/lib" ; then LDFLAGS="-L$ac_cv_openssl_dir/lib $LDFLAGS" @@ -359,7 +410,18 @@ dnl The warning message here is no longer strictly accurate. AC_CHECK_HEADERS(unistd.h string.h signal.h netdb.h ctype.h sys/stat.h sys/types.h fcntl.h sys/fcntl.h sys/ioctl.h sys/socket.h sys/time.h netinet/in.h arpa/inet.h errno.h assert.h time.h pwd.h grp.h, , AC_MSG_WARN(some headers were not found, compilation may fail)) -AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.)) +# if the user doesn't have timeval this will generate a nasty warning. if +# timeval isn't provided, define one +AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.), +[#ifdef HAVE_SYS_TIME_H + #include <sys/time.h> + #else + struct timeval { + long tv_sec; + long tv_usec; + } + #endif] +) AC_CHECK_HEADERS(zlib.h, , AC_MSG_ERROR(Zlib header (zlib.h) not found. Tor requires zlib to build. You may need to install a zlib development package.)) diff --git a/src/common/compat.c b/src/common/compat.c index e1b7837d0..12608bde2 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -163,47 +163,56 @@ typedef struct win_mmap_t { tor_mmap_t * tor_mmap_file(const char *filename) { - win_mmap_t *res = tor_malloc_zero(sizeof(win_mmap_t)); + struct win_mmap_t *res = tor_malloc_zero(sizeof(struct win_mmap_t)); res->mmap_handle = res->file_handle = INVALID_HANDLE_VALUE; - res->file_handle = CreateFileForMapping(filename, - GENERIC_READ, - 0, NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, 0); + res->file_handle = CreateFile(filename, + GENERIC_READ, + 0, NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + 0); + + if (res->file_handle == INVALID_HANDLE_VALUE) + goto err; + res->base.size = GetFileSize(res->file_handle, NULL); res->mmap_handle = CreateFileMapping(res->file_handle, NULL, PAGE_READONLY, - (size >> 32), - (size & 0xfffffffful), + 0, + res->base.size, NULL); if (res->mmap_handle != INVALID_HANDLE_VALUE) goto err; res->base.data = (char*) MapViewOfFile(res->mmap_handle, - access, + FILE_MAP_READ, 0, 0, 0); - if (!res->data) + if (!res->base.data) goto err; return &(res->base); err: - tor_munmap_file(res); + tor_munmap_file(&res->base); return NULL; } void tor_munmap_file(tor_mmap_t *handle) { - win_mmap_t *h = (win_mmap_t*) - (((char*)handle) - STRUCT_OFFSET(win_mmap_t, base)); + struct win_mmap_t *h = (struct win_mmap_t*) + (((char*)handle) - STRUCT_OFFSET(struct win_mmap_t, base)); if (handle->data) - UnmapViewOfFile(handle->data); - if (res->mmap_handle != INVALID_HANDLE_VALUE) - CloseHandle(res->mmap_handle); - if (res->file_handle != INVALID_HANDLE_VALUE) - CloseHandle(self->file_handle); - tor_free(res); + + /*this is an ugly cast, but without it, "data" in struct tor_mmap_t would + have to be redefined as const*/ + UnmapViewOfFile( (LPVOID) handle->data); + + if (h->mmap_handle != INVALID_HANDLE_VALUE) + CloseHandle(h->mmap_handle); + if (h->file_handle != INVALID_HANDLE_VALUE) + CloseHandle(h->file_handle); + tor_free(h); } #else tor_mmap_t * @@ -417,8 +426,8 @@ void set_socket_nonblocking(int socket) { #ifdef MS_WINDOWS - int nonblocking = 1; - ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking); + unsigned long nonblocking = 1; + ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking); #else fcntl(socket, F_SETFL, O_NONBLOCK); #endif @@ -444,7 +453,8 @@ set_socket_nonblocking(int socket) int tor_socketpair(int family, int type, int protocol, int fd[2]) { -#ifdef HAVE_SOCKETPAIR +//don't use win32 socketpairs (they are always bad) +#if defined(HAVE_SOCKETPAIR) && !defined(MS_WINDOWS) int r; r = socketpair(family, type, protocol, fd); return r < 0 ? -errno : r; @@ -562,7 +572,7 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap) log_fn(LOG_INFO, LD_NET, "This platform is missing getrlimit(). Proceeding."); if (limit < cap) { - log_info(LD_CONFIG, "ConnLimit must be at most %d. Using that.", cap); + log_info(LD_CONFIG, "ConnLimit must be at most %d. Using that.", (int) cap); limit = cap; } #else @@ -799,6 +809,8 @@ static int uname_result_is_set = 0; const char * get_uname(void) { + + #ifdef HAVE_UNAME struct utsname u; #endif @@ -852,7 +864,7 @@ get_uname(void) memset(&info, 0, sizeof(info)); info.dwOSVersionInfoSize = sizeof(info); if (! GetVersionEx((LPOSVERSIONINFO)&info)) { - int err = GetLastError(); + strlcpy(uname_result, "Bizarre version of Windows where GetVersionEx" " doesn't work.", sizeof(uname_result)); uname_result_is_set = 1; @@ -954,7 +966,7 @@ tor_pthread_helper_fn(void *_data) * running. */ int -spawn_func(int (*func)(void *), void *data) +spawn_func(void (*func)(void *), void *data) { #if defined(USE_WIN32_THREADS) int rv; @@ -992,11 +1004,16 @@ spawn_func(int (*func)(void *), void *data) /** End the current thread/process. */ + void spawn_exit(void) { #if defined(USE_WIN32_THREADS) _endthread(); + //we should never get here. my compiler thinks that _endthread returns, this + //is an attempt to fool it. + tor_assert(0); + _exit(0); #elif defined(USE_PTHREADS) pthread_exit(NULL); #else @@ -1004,6 +1021,7 @@ spawn_exit(void) * call _exit, not exit, from child processes. */ _exit(0); #endif + } /** Set *timeval to the current time of day. On error, log and terminate. @@ -1143,7 +1161,7 @@ tor_mutex_acquire(tor_mutex_t *m) tor_assert(0); break; case WAIT_FAILED: - log_warn(LD_GENERAL, "Failed to acquire mutex: %d", GetLastError()); + log_warn(LD_GENERAL, "Failed to acquire mutex: %d", (int) GetLastError()); } } void @@ -1152,7 +1170,7 @@ tor_mutex_release(tor_mutex_t *m) BOOL r; r = ReleaseMutex(m->handle); if (!r) { - log_warn(LD_GENERAL, "Failed to release mutex: %d", GetLastError()); + log_warn(LD_GENERAL, "Failed to release mutex: %d", (int) GetLastError()); } } unsigned long diff --git a/src/common/compat.h b/src/common/compat.h index f0757d577..0aff0775e 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -273,7 +273,7 @@ int switch_id(char *user, char *group); char *get_user_homedir(const char *username); #endif -int spawn_func(int (*func)(void *), void *data); +int spawn_func(void (*func)(void *), void *data); void spawn_exit(void) ATTR_NORETURN; #if defined(ENABLE_THREADS) && defined(MS_WINDOWS) @@ -306,5 +306,22 @@ unsigned long tor_get_thread_id(void); #define tor_get_thread_id() (1UL) #endif +/*for some reason my compiler doesn't have these version flags defined + a nice homework assignment for someone one day is to define the rest*/ +//these are the values as given on MSDN +#ifdef MS_WINDOWS + +#ifndef VER_SUITE_EMBEDDEDNT +#define VER_SUITE_EMBEDDEDNT 0x00000040 +#endif + +#ifndef VER_SUITE_SINGLEUSERTS +#define VER_SUITE_SINGLEUSERTS 0x00000100 +#endif + + +#endif + + #endif diff --git a/src/or/config.c b/src/or/config.c index 29f41ee3b..146107ead 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2757,11 +2757,11 @@ options_init_from_torrc(int argc, char **argv) if (using_default_torrc) { /* didn't find one, try CONFDIR */ const char *dflt = get_default_conf_file(); - char *fn = NULL; if (dflt && file_status(dflt) == FN_FILE) { fname = tor_strdup(dflt); } else { #ifndef MS_WINDOWS + char *fn; fn = expand_filename("~/.torrc"); if (fn && file_status(fn) == FN_FILE) { fname = fn; diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index 66827bf20..daab7d296 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -333,7 +333,7 @@ spawn_cpuworker(void) tor_assert(fdarray[1] >= 0); fd = fdarray[0]; - spawn_func(cpuworker_main, (void*)fdarray); + spawn_func((void*) cpuworker_main, (void*)fdarray); log_debug(LD_OR,"just spawned a cpu worker."); #ifndef TOR_IS_MULTITHREADED tor_close_socket(fdarray[1]); /* don't need the worker's side of the pipe */ diff --git a/src/or/dns.c b/src/or/dns.c index 43459f2c5..19947e076 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -1108,7 +1108,7 @@ spawn_dnsworker(void) fd = fdarray[0]; /* We copy this out here, since dnsworker_main may free * fdarray */ - spawn_func(dnsworker_main, (void*)fdarray); + spawn_func((void*) dnsworker_main, (void*)fdarray); log_debug(LD_EXIT,"just spawned a dns worker."); #ifndef TOR_IS_MULTITHREADED tor_close_socket(fdarray[1]); /* don't need the worker's side of the pipe */ diff --git a/src/or/main.c b/src/or/main.c index cc9999a0c..118a82c9a 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1778,7 +1778,7 @@ nt_service_main(void) if (!StartServiceCtrlDispatcher(table)) { result = GetLastError(); errmsg = nt_strerror(result); - printf("Service error %d : %s\n", result, errmsg); + printf("Service error %d : %s\n", (int) result, errmsg); LocalFree(errmsg); if (result == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { if (tor_init(backup_argc, backup_argv) < 0) @@ -1902,7 +1902,7 @@ nt_service_stop(SC_HANDLE hService) } else { errmsg = nt_strerror(GetLastError()); - printf("Service failed to stop : %s\n"); + printf("Service failed to stop : %s\n",errmsg); LocalFree(errmsg); } } @@ -2015,7 +2015,6 @@ nt_service_remove(void) { SC_HANDLE hSCManager = NULL; SC_HANDLE hService = NULL; - BOOL result = FALSE; char *errmsg; if ((hSCManager = nt_service_open_scm()) == NULL) { |