--------------------- PatchSet 5446 Date: 2002/10/27 10:42:20 Author: serassio Branch: nt-2_5 Tag: (none) Log: Backport of WIN32 changes from nt branch Members: include/util.h:1.10.14.5->1.10.14.6 lib/Makefile.am:1.4.10.1->1.4.10.2 lib/getopt.c:1.1->1.1.108.1 lib/win32lib.c:1.1.32.10->1.1.32.11 src/Makefile.am:1.13.2.1.4.6->1.13.2.1.4.7 src/client.c:1.8.14.7->1.8.14.8 src/comm_select.c:1.8.10.6->1.8.10.7 src/debug.c:1.9.10.6->1.9.10.7 src/dns_internal.c:1.15.14.4->1.15.14.5 src/fd.c:1.7.16.6->1.7.16.7 src/globals.h:1.14.14.4->1.14.14.5 src/icmp.c:1.4.74.7->1.4.74.8 src/ipc.c:1.7.10.8->1.7.10.9 src/main.c:1.28.6.1.4.13->1.28.6.1.4.14 src/unlinkd.c:1.6.10.8->1.6.10.9 src/win32.c:1.5.14.12->1.5.14.13 src/auth/Makefile.am:1.2->1.2.40.1 src/fs/Makefile.am:1.2.40.2->1.2.40.3 src/fs/awin32/aiops.c:1.1.62.9->1.1.62.10 src/fs/awin32/store_dir_aufs.c:1.1.62.10->1.1.62.11 src/fs/ufs/store_dir_ufs.c:1.21.6.1.4.11->1.21.6.1.4.12 Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.10.14.5 retrieving revision 1.10.14.6 diff -u -r1.10.14.5 -r1.10.14.6 --- squid/include/util.h 12 Sep 2002 18:34:00 -0000 1.10.14.5 +++ squid/include/util.h 27 Oct 2002 10:42:43 -0000 1.10.14.6 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.10.14.5 2002/09/12 18:34:00 serassio Exp $ + * $Id: util.h,v 1.10.14.6 2002/10/27 10:42:43 serassio Exp $ * * AUTHOR: Harvest Derived * @@ -154,6 +154,8 @@ extern int setgid(gid_t); extern int setegid(gid_t); extern const char *WIN32_strerror(int); +extern void WIN32_maperror(unsigned long); +extern int WIN32_Close_FD_Socket (int); #endif #endif /* SQUID_UTIL_H */ Index: squid/lib/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/Makefile.am,v retrieving revision 1.4.10.1 retrieving revision 1.4.10.2 diff -u -r1.4.10.1 -r1.4.10.2 --- squid/lib/Makefile.am 16 Jul 2002 12:46:50 -0000 1.4.10.1 +++ squid/lib/Makefile.am 27 Oct 2002 10:42:20 -0000 1.4.10.2 @@ -13,15 +13,29 @@ else MD5SOURCE= endif +if ENABLE_WIN32SPECIFIC +LIBSSPWIN32=libsspwin32.a +else +LIBSSPWIN32= +endif + +if ENABLE_MINGW32SPECIFIC +WIN32SRC = win32lib.c +INCLUDES = -I$(top_srcdir)/port/win32/include -I$(top_srcdir)/include -I$(top_srcdir)/src +else +WIN32SRC= +INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/src +endif EXTRA_LIBRARIES = \ libdlmalloc.a \ - libregex.a + libregex.a \ + libsspwin32.a noinst_LIBRARIES = \ @LIBDLMALLOC@ \ libmiscutil.a \ libntlmauth.a \ - libsspwin32.a \ + $(LIBSSPWIN32) \ @LIBREGEX@ EXTRA_libmiscutil_a_SOURCES = \ md5.c \ @@ -46,7 +60,8 @@ Stack.c \ stub_memaccount.c \ util.c \ - uudecode.c + uudecode.c \ + $(WIN32SRC) libmiscutil_a_LIBADD = \ @LIBOBJS@ # $(top_srcdir)/include/version.h should be a dependency @@ -61,4 +76,3 @@ libsspwin32_a_SOURCES = \ sspwin32.c -INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_builddir)/src --- /dev/null Wed Feb 14 01:07:22 2007 +++ squid/lib/getopt.c Wed Feb 14 01:07:56 2007 @@ -0,0 +1,501 @@ +/* $NetBSD: getopt_long.c,v 1.12 2001/04/24 09:07:43 joda Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "cdefs.h" + +/*#include "namespace.h"*/ + +#include +#include +/*#include */ +#include +#include +#include "getopt.h" +#include +#include + +#define REPLACE_GETOPT + +#define _DIAGASSERT(x) do {} while (0) + +#ifdef REPLACE_GETOPT +#ifdef __weak_alias +__weak_alias(getopt,_getopt) +#endif +int opterr = 1; /* if error message should be printed */ +int optind = 1; /* index into parent argv vector */ +int optopt = '?'; /* character checked for validity */ +int optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ +#endif + +#ifdef __weak_alias +__weak_alias(getopt_long,_getopt_long) +#endif + +#ifndef __CYGWIN__ +#define __progname __argv[0] +#else +extern char __declspec(dllimport) *__progname; +#endif + +#define IGNORE_FIRST (*options == '-' || *options == '+') +#define PRINT_ERROR ((opterr) && ((*options != ':') \ + || (IGNORE_FIRST && options[1] != ':'))) +#if defined(__CYGWIN__) || defined(__MINGW32__) +# define IS_POSIXLY_CORRECT (1) +#else +# define IS_POSIXLY_CORRECT (getenv("POSIXLY_CORRECT") != NULL) +#endif + +#define PERMUTE (!IS_POSIXLY_CORRECT && !IGNORE_FIRST) +/* XXX: GNU ignores PC if *options == '-' */ +#define IN_ORDER (!IS_POSIXLY_CORRECT && *options == '-') + +/* return values */ +#define BADCH (int)'?' +#define BADARG ((IGNORE_FIRST && options[1] == ':') \ + || (*options == ':') ? (int)':' : (int)'?') +#define INORDER (int)1 + +#define EMSG "" + +static int getopt_internal __P((int, char * const *, const char *)); +static int gcd __P((int, int)); +static void permute_args __P((int, int, int, char * const *)); + +static const char *place = EMSG; /* option letter processing */ + +/* XXX: set optreset to 1 rather than these two */ +static int nonopt_start = -1; /* first non option argument (for permute) */ +static int nonopt_end = -1; /* first option after non options (for permute) */ + +/* Error messages */ +static const char recargchar[] = "option requires an argument -- %c"; +static const char recargstring[] = "option requires an argument -- %s"; +static const char ambig[] = "ambiguous option -- %.*s"; +static const char noarg[] = "option doesn't take an argument -- %.*s"; +static const char illoptchar[] = "unknown option -- %c"; +static const char illoptstring[] = "unknown option -- %s"; + +static void +_vwarnx(const char *fmt, va_list ap) +{ + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, "\n"); +} + +static void +warnx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + _vwarnx(fmt, ap); + va_end(ap); +} + +/* + * Compute the greatest common divisor of a and b. + */ +static int +gcd(a, b) + int a; + int b; +{ + int c; + + c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + + return b; +} + +/* + * Exchange the block from nonopt_start to nonopt_end with the block + * from nonopt_end to opt_end (keeping the same order of arguments + * in each block). + */ +static void +permute_args(nonopt_start, nonopt_end, opt_end, nargv) + int nonopt_start; + int nonopt_end; + int opt_end; + char * const *nargv; +{ + int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; + char *swap; + + _DIAGASSERT(nargv != NULL); + + /* + * compute lengths of blocks and number and size of cycles + */ + nnonopts = nonopt_end - nonopt_start; + nopts = opt_end - nonopt_end; + ncycle = gcd(nnonopts, nopts); + cyclelen = (opt_end - nonopt_start) / ncycle; + + for (i = 0; i < ncycle; i++) { + cstart = nonopt_end+i; + pos = cstart; + for (j = 0; j < cyclelen; j++) { + if (pos >= nonopt_end) + pos -= nnonopts; + else + pos += nopts; + swap = nargv[pos]; + /* LINTED const cast */ + ((char **) nargv)[pos] = nargv[cstart]; + /* LINTED const cast */ + ((char **)nargv)[cstart] = swap; + } + } +} + +/* + * getopt_internal -- + * Parse argc/argv argument vector. Called by user level routines. + * Returns -2 if -- is found (can be long option or end of options marker). + */ +static int +getopt_internal(int nargc, char *const * nargv, const char *options) +{ + char *oli; /* option letter list index */ + int optchar; + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(options != NULL); + + optarg = NULL; + + /* + * XXX Some programs (like rsyncd) expect to be able to + * XXX re-initialize optind to 0 and have getopt_long(3) + * XXX properly function again. Work around this braindamage. + */ + if (optind == 0 && optreset == 0) + optind = 1; + + if (optreset) + nonopt_start = nonopt_end = -1; +start: + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc) { /* end of argument vector */ + place = EMSG; + if (nonopt_end != -1) { + /* do permutation, if we have to */ + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + else if (nonopt_start != -1) { + /* + * If we skipped non-options, set optind + * to the first of them. + */ + optind = nonopt_start; + } + nonopt_start = nonopt_end = -1; + return -1; + } + if ((*(place = nargv[optind]) != '-') + || (place[1] == '\0')) { /* found non-option */ + place = EMSG; + if (IN_ORDER) { + /* + * GNU extension: + * return non-option as argument to option 1 + */ + optarg = nargv[optind++]; + return INORDER; + } + if (!PERMUTE) { + /* + * if no permutation wanted, stop parsing + * at first non-option + */ + return -1; + } + /* do permutation */ + if (nonopt_start == -1) + nonopt_start = optind; + else if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + nonopt_start = optind - + (nonopt_end - nonopt_start); + nonopt_end = -1; + } + optind++; + /* process next argument */ + goto start; + } + if (nonopt_start != -1 && nonopt_end == -1) + nonopt_end = optind; + if (place[1] && *++place == '-') { /* found "--" */ + place++; + return -2; + } + } + if ((optchar = (int)*place++) == (int)':' || + (oli = strchr(options + (IGNORE_FIRST ? 1 : 0), optchar)) == NULL) { + /* option letter unknown or ':' */ + if (!*place) + ++optind; + if (PRINT_ERROR) + warnx(illoptchar, optchar); + optopt = optchar; + return BADCH; + } + if (optchar == 'W' && oli[1] == ';') { /* -W long-option */ + /* XXX: what if no long options provided (called by getopt)? */ + if (*place) + return -2; + + if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return BADARG; + } else /* white space */ + place = nargv[optind]; + /* + * Handle -W arg the same as --arg (which causes getopt to + * stop parsing). + */ + return -2; + } + if (*++oli != ':') { /* doesn't take argument */ + if (!*place) + ++optind; + } else { /* takes (optional) argument */ + optarg = NULL; + if (*place) /* no white space */ + optarg = (char *) place; + /* XXX: disable test for :: if PC? (GNU doesn't) */ + else if (oli[1] != ':') { /* arg not optional */ + if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return BADARG; + } else + optarg = nargv[optind]; + } + place = EMSG; + ++optind; + } + /* dump back option letter */ + return optchar; +} + +#ifdef REPLACE_GETOPT +/* + * getopt -- + * Parse argc/argv argument vector. + * + * [eventually this will replace the real getopt] + */ +int +getopt(int nargc, char * const *nargv, const char *options) +{ + int retval; + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(options != NULL); + + if ((retval = getopt_internal(nargc, nargv, options)) == -2) { + ++optind; + /* + * We found an option (--), so if we skipped non-options, + * we have to permute. + */ + if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, optind, + nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + retval = -1; + } + return retval; +} +#endif + +/* + * getopt_long -- + * Parse argc/argv argument vector. + */ +int +getopt_long(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx) +{ + int retval; + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(options != NULL); + _DIAGASSERT(long_options != NULL); + /* idx may be NULL */ + + if ((retval = getopt_internal(nargc, nargv, options)) == -2) { + char *current_argv, *has_equal; + size_t current_argv_len; + int i, match; + + current_argv = (char *) place; + match = -1; + + optind++; + place = EMSG; + + if (*current_argv == '\0') { /* found "--" */ + /* + * We found an option (--), so if we skipped + * non-options, we have to permute. + */ + if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + return -1; + } + if ((has_equal = strchr(current_argv, '=')) != NULL) { + /* argument found (--option=arg) */ + current_argv_len = has_equal - current_argv; + has_equal++; + } else + current_argv_len = strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + /* find matching long option */ + if (strncmp(current_argv, long_options[i].name, + current_argv_len)) + continue; + + if (strlen(long_options[i].name) == + (unsigned)current_argv_len) { + /* exact match */ + match = i; + break; + } + if (match == -1) /* partial match */ + match = i; + else { + /* ambiguous abbreviation */ + if (PRINT_ERROR) + warnx(ambig, (int)current_argv_len, + current_argv); + optopt = 0; + return BADCH; + } + } + if (match != -1) { /* option found */ + if (long_options[match].has_arg == no_argument + && has_equal) { + if (PRINT_ERROR) + warnx(noarg, (int)current_argv_len, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of + * flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + return BADARG; + } + if (long_options[match].has_arg == required_argument || + long_options[match].has_arg == optional_argument) { + if (has_equal) + optarg = has_equal; + else if (long_options[match].has_arg == + required_argument) { + /* + * optional argument doesn't use + * next nargv + */ + optarg = nargv[optind++]; + } + } + if ((long_options[match].has_arg == required_argument) + && (optarg == NULL)) { + /* + * Missing argument; leading ':' + * indicates no error should be generated + */ + if (PRINT_ERROR) + warnx(recargstring, current_argv); + /* + * XXX: GNU sets optopt to val regardless + * of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + --optind; + return BADARG; + } + } else { /* unknown option */ + if (PRINT_ERROR) + warnx(illoptstring, current_argv); + optopt = 0; + return BADCH; + } + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + retval = 0; + } else + retval = long_options[match].val; + if (idx) + *idx = match; + } + return retval; +} Index: squid/lib/win32lib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/win32lib.c,v retrieving revision 1.1.32.10 retrieving revision 1.1.32.11 diff -u -r1.1.32.10 -r1.1.32.11 --- squid/lib/win32lib.c 20 Oct 2002 09:54:26 -0000 1.1.32.10 +++ squid/lib/win32lib.c 27 Oct 2002 10:42:20 -0000 1.1.32.11 @@ -1,5 +1,5 @@ /* - * $Id: win32lib.c,v 1.1.32.10 2002/10/20 09:54:26 serassio Exp $ + * $Id: win32lib.c,v 1.1.32.11 2002/10/27 10:42:20 serassio Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -50,20 +50,42 @@ #include #include -#define OPTERRCOLON (1) -#define OPTERRNF (2) -#define OPTERRARG (3) - -__declspec(thread) int ws32_result; -__declspec(thread) int _so_err; -__declspec(thread) int _so_err_siz; +THREADLOCAL int ws32_result; +THREADLOCAL int _so_err; +THREADLOCAL int _so_err_siz = sizeof(int); LPCRITICAL_SECTION dbg_mutex = NULL; -char *optarg; -int optreset = 0; -int optind = 1; -int opterr = 1; -int optopt; +/* internal to Microsoft CRTLIB */ +#define FPIPE 0x08 /* file handle refers to a pipe */ +typedef struct { + long osfhnd; /* underlying OS file HANDLE */ + char osfile; /* attributes of file (e.g., open in text mode?) */ + char pipech; /* one char buffer for handles opened on pipes */ +#ifdef _MT + int lockinitflag; + CRITICAL_SECTION lock; +#endif /* _MT */ + } ioinfo; +#define IOINFO_L2E 5 +#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E) +#define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)) ) +#define _osfile(i) ( _pioinfo(i)->osfile ) +#define _osfhnd(i) ( _pioinfo(i)->osfhnd ) + +#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ + +extern _CRTIMP ioinfo * __pioinfo[]; +int __cdecl _free_osfhnd(int); +#define FOPEN 0x01 /* file handle open */ + +#elif defined(__MINGW32__) /* MinGW environment */ + +#define FOPEN 0x01 /* file handle open */ +__MINGW_IMPORT ioinfo * __pioinfo[]; +int _free_osfhnd(int); + +#endif + uid_t geteuid(void) { @@ -219,122 +241,12 @@ else { res = WIN32_ftruncate (fd, length); - close (fd); + _close (fd); } return res; } - -static int -optiserr(int argc, char * const *argv, int oint, const char *optstr, - int optchr, int err) -{ - if(opterr) - { - fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1); - switch(err) - { - case OPTERRCOLON: - fprintf(stderr, ": in flags\n"); - break; - case OPTERRNF: - fprintf(stderr, "option not found %c\n", argv[oint][optchr]); - break; - case OPTERRARG: - fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]); - break; - default: - fprintf(stderr, "unknown\n"); - break; - } - } - optopt = argv[oint][optchr]; - return('?'); -} - - -int -getopt(int argc, char* const *argv, const char *optstr) -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - - char *cp; - - if (optreset) - optreset = optchr = dash = 0; - if (optind >= argc) - return(EOF); - if (!dash && (argv[optind][0] != '-')) - return(EOF); - if (!dash && (argv[optind][0] == '-') && !argv[optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return(EOF); - } - if ((argv[optind][0] == '-') && (argv[optind][1] == '-')) - { - /* -- indicates end of args */ - optind++; - return(EOF); - } - if (!dash) - { - assert((argv[optind][0] == '-') && argv[optind][1]); - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - assert(dash); - if(argv[optind][optchr] == ':') - { - dash = 0; - optind++; - return(optiserr(argc, argv, optind-1, optstr, optchr, OPTERRCOLON)); - } - if(!(cp = strchr(optstr, argv[optind][optchr]))) - { - int errind = optind; - int errchr = optchr; - - if(!argv[optind][optchr+1]) - { - dash = 0; - optind++; - } - else - optchr++; - return(optiserr(argc, argv, errind, optstr, errchr, OPTERRNF)); - } - if(cp[1] == ':') - { - dash = 0; - optind++; - if(optind == argc) - return(optiserr(argc, argv, optind-1, optstr, optchr, OPTERRARG)); - optarg = argv[optind++]; - return(*cp); - } - else - { - if(!argv[optind][optchr+1]) - { - dash = 0; - optind++; - } - else - optchr++; - return(*cp); - } - assert(0); - return(0); -} - static struct _wsaerrtext { int err; const char *errconst; @@ -451,4 +363,123 @@ return xbstrerror_buf; } +int WIN32_Close_FD_Socket(int fd) + +{ + int result = 0; + + if (closesocket(_get_osfhandle(fd)) == SOCKET_ERROR) { + errno = WSAGetLastError(); + result = 1; + } + _free_osfhnd(fd); + _osfile(fd) = 0; + return result; +} + +#if defined(__MINGW32__) /* MinGW environment */ +int _free_osfhnd(int filehandle) +{ + if ( ((unsigned)filehandle < SQUID_MAXFD) && + (_osfile(filehandle) & FOPEN) && + (_osfhnd(filehandle) != (long)INVALID_HANDLE_VALUE) ) + { + switch (filehandle) { + case 0: + SetStdHandle( STD_INPUT_HANDLE, NULL ); + break; + case 1: + SetStdHandle( STD_OUTPUT_HANDLE, NULL ); + break; + case 2: + SetStdHandle( STD_ERROR_HANDLE, NULL ); + break; + } + _osfhnd(filehandle) = (long)INVALID_HANDLE_VALUE; + return(0); + } else { + errno = EBADF; /* bad handle */ + _doserrno = 0L; /* not an OS error */ + return -1; + } +} +#endif + +struct errorentry { + unsigned long WIN32_code; + int POSIX_errno; +}; + +static struct errorentry errortable[] = { + {ERROR_INVALID_FUNCTION, EINVAL}, + {ERROR_FILE_NOT_FOUND, ENOENT}, + {ERROR_PATH_NOT_FOUND, ENOENT}, + {ERROR_TOO_MANY_OPEN_FILES, EMFILE}, + {ERROR_ACCESS_DENIED, EACCES}, + {ERROR_INVALID_HANDLE, EBADF}, + {ERROR_ARENA_TRASHED, ENOMEM}, + {ERROR_NOT_ENOUGH_MEMORY, ENOMEM}, + {ERROR_INVALID_BLOCK, ENOMEM}, + {ERROR_BAD_ENVIRONMENT, E2BIG}, + {ERROR_BAD_FORMAT, ENOEXEC}, + {ERROR_INVALID_ACCESS, EINVAL}, + {ERROR_INVALID_DATA, EINVAL}, + {ERROR_INVALID_DRIVE, ENOENT}, + {ERROR_CURRENT_DIRECTORY, EACCES}, + {ERROR_NOT_SAME_DEVICE, EXDEV}, + {ERROR_NO_MORE_FILES, ENOENT}, + {ERROR_LOCK_VIOLATION, EACCES}, + {ERROR_BAD_NETPATH, ENOENT}, + {ERROR_NETWORK_ACCESS_DENIED, EACCES}, + {ERROR_BAD_NET_NAME, ENOENT}, + {ERROR_FILE_EXISTS, EEXIST}, + {ERROR_CANNOT_MAKE, EACCES}, + {ERROR_FAIL_I24, EACCES}, + {ERROR_INVALID_PARAMETER, EINVAL}, + {ERROR_NO_PROC_SLOTS, EAGAIN}, + {ERROR_DRIVE_LOCKED, EACCES}, + {ERROR_BROKEN_PIPE, EPIPE}, + {ERROR_DISK_FULL, ENOSPC}, + {ERROR_INVALID_TARGET_HANDLE, EBADF}, + {ERROR_INVALID_HANDLE, EINVAL}, + {ERROR_WAIT_NO_CHILDREN, ECHILD}, + {ERROR_CHILD_NOT_COMPLETE, ECHILD}, + {ERROR_DIRECT_ACCESS_HANDLE, EBADF}, + {ERROR_NEGATIVE_SEEK, EINVAL}, + {ERROR_SEEK_ON_DEVICE, EACCES}, + {ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, + {ERROR_NOT_LOCKED, EACCES}, + {ERROR_BAD_PATHNAME, ENOENT}, + {ERROR_MAX_THRDS_REACHED, EAGAIN}, + {ERROR_LOCK_FAILED, EACCES}, + {ERROR_ALREADY_EXISTS, EEXIST}, + {ERROR_FILENAME_EXCED_RANGE, ENOENT}, + {ERROR_NESTING_NOT_ALLOWED, EAGAIN}, + {ERROR_NOT_ENOUGH_QUOTA, ENOMEM} +}; + +#define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG +#define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN + +#define MIN_EACCES_RANGE ERROR_WRITE_PROTECT +#define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED + +void WIN32_maperror(unsigned long WIN32_oserrno) +{ + int i; + + _doserrno = WIN32_oserrno; + for (i = 0; i < (sizeof(errortable)/sizeof(struct errorentry)); ++i) { + if (WIN32_oserrno == errortable[i].WIN32_code) { + errno = errortable[i].POSIX_errno; + return; + } + } + if (WIN32_oserrno >= MIN_EACCES_RANGE && WIN32_oserrno <= MAX_EACCES_RANGE) + errno = EACCES; + else if (WIN32_oserrno >= MIN_EXEC_ERROR && WIN32_oserrno <= MAX_EXEC_ERROR) + errno = ENOEXEC; + else + errno = EINVAL; +} #endif Index: squid/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Makefile.am,v retrieving revision 1.13.2.1.4.6 retrieving revision 1.13.2.1.4.7 diff -u -r1.13.2.1.4.6 -r1.13.2.1.4.7 --- squid/src/Makefile.am 30 Sep 2002 18:59:57 -0000 1.13.2.1.4.6 +++ squid/src/Makefile.am 27 Oct 2002 10:46:14 -0000 1.13.2.1.4.7 @@ -62,9 +62,15 @@ WIN32SOURCE = endif -SUBDIRS = fs repl auth +if ENABLE_MINGW32SPECIFIC +INCLUDES = -I$(top_srcdir)/port/win32/include -I$(srcdir) -I$(top_srcdir)/include +MINGWEXLIB = -lmingwex +else +INCLUDES = -I$(srcdir) -I$(top_srcdir)/include +MINGWEXLIB = +endif -INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include +SUBDIRS = fs repl auth EXTRA_PROGRAMS = \ unlinkd \ @@ -227,7 +233,8 @@ @LIB_MALLOC@ \ @SSLLIB@ \ -lmiscutil \ - @XTRA_LIBS@ + @XTRA_LIBS@ \ + $(MINGWEXLIB) unlinkd_SOURCES = unlinkd_LDADD = unlinkd-daemon.o @@ -286,6 +293,7 @@ DEFAULT_ICON_DIR = $(datadir)/icons DEFAULT_ERROR_DIR = $(datadir)/errors/@ERR_DEFAULT_LANGUAGE@ DEFAULT_MIB_PATH = $(datadir)/mib.txt +DEFAULT_HOSTS = @OPT_DEFAULT_HOSTS@ DEFS = @DEFS@ -DDEFAULT_CONFIG_FILE=\"$(DEFAULT_CONFIG_FILE)\" @@ -335,7 +343,8 @@ s%@DEFAULT_ICON_DIR@%$(DEFAULT_ICON_DIR)%g;\ s%@DEFAULT_MIB_PATH@%$(DEFAULT_MIB_PATH)%g;\ s%@DEFAULT_ERROR_DIR@%$(DEFAULT_ERROR_DIR)%g;\ - s%@DEFAULT_PREFIX@%$(DEFAULT_PREFIX)%g;"\ + s%@DEFAULT_PREFIX@%$(DEFAULT_PREFIX)%g;\ + s%@DEFAULT_HOSTS@%$(DEFAULT_HOSTS)%g;"\ < $(srcdir)/cf.data.pre >$@ store_modules.c: store_modules.sh Makefile Index: squid/src/client.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/client.c,v retrieving revision 1.8.14.7 retrieving revision 1.8.14.8 diff -u -r1.8.14.7 -r1.8.14.8 --- squid/src/client.c 16 Jul 2002 09:21:48 -0000 1.8.14.7 +++ squid/src/client.c 27 Oct 2002 10:46:14 -0000 1.8.14.8 @@ -1,6 +1,6 @@ /* - * $Id: client.c,v 1.8.14.7 2002/07/16 09:21:48 serassio Exp $ + * $Id: client.c,v 1.8.14.8 2002/10/27 10:46:14 serassio Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived @@ -47,8 +47,10 @@ static SIGHDLR catch; static SIGHDLR pipe_handler; static void set_our_signal(void); +#ifndef _SQUID_MSWIN_ static ssize_t myread(int fd, void *buf, size_t len); static ssize_t mywrite(int fd, void *buf, size_t len); +#endif static int put_fd; static char *put_file = NULL; static struct stat sb; Index: squid/src/comm_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_select.c,v retrieving revision 1.8.10.6 retrieving revision 1.8.10.7 diff -u -r1.8.10.6 -r1.8.10.7 --- squid/src/comm_select.c 29 Apr 2002 07:13:31 -0000 1.8.10.6 +++ squid/src/comm_select.c 27 Oct 2002 10:46:14 -0000 1.8.10.7 @@ -1,6 +1,6 @@ /* - * $Id: comm_select.c,v 1.8.10.6 2002/04/29 07:13:31 serassio Exp $ + * $Id: comm_select.c,v 1.8.10.7 2002/10/27 10:46:14 serassio Exp $ * * DEBUG: section 5 Socket Functions * @@ -908,7 +908,6 @@ } } #ifdef _SQUID_MSWIN_ -#if 1 assert(errfds.fd_count <= (unsigned int) Biggest_FD); for (j = 0; j < (int) errfds.fd_count; j++) { for ( fd = Biggest_FD; fd; fd-- ) { @@ -925,7 +924,6 @@ } } } -#endif assert(writefds.fd_count <= (unsigned int) Biggest_FD); for (j = 0; j < (int) writefds.fd_count; j++) { no_bits = 1; Index: squid/src/debug.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/debug.c,v retrieving revision 1.9.10.6 retrieving revision 1.9.10.7 diff -u -r1.9.10.6 -r1.9.10.7 --- squid/src/debug.c 22 Sep 2002 11:38:05 -0000 1.9.10.6 +++ squid/src/debug.c 27 Oct 2002 10:46:14 -0000 1.9.10.7 @@ -1,6 +1,6 @@ /* - * $Id: debug.c,v 1.9.10.6 2002/09/22 11:38:05 serassio Exp $ + * $Id: debug.c,v 1.9.10.7 2002/10/27 10:46:14 serassio Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -68,7 +68,7 @@ #define args2 args1 #define args3 args1 #endif -#if defined (_SQUID_MSWIN_) && !defined(PINGER) +#ifdef _SQUID_MSWIN_ /* Multiple WIN32 threads may call this simultaneously */ if (!dbg_mutex) { HMODULE krnl_lib = GetModuleHandle("Kernel32"); @@ -80,24 +80,18 @@ "InitializeCriticalSectionAndSpinCount"); dbg_mutex = xcalloc(1, sizeof(CRITICAL_SECTION)); - __try { - if (InitializeCriticalSectionAndSpinCount) { - /* let multiprocessor systems EnterCriticalSection() fast */ - if (!InitializeCriticalSectionAndSpinCount(dbg_mutex, 4000)) - RaiseException(STATUS_NO_MEMORY, 0, 0, NULL); + if (InitializeCriticalSectionAndSpinCount) { + /* let multiprocessor systems EnterCriticalSection() fast */ + if (!InitializeCriticalSectionAndSpinCount(dbg_mutex, 4000)) { + if (debug_log) { + fprintf(debug_log, "FATAL: _db_print: can't initialize critical section\n"); + fflush(debug_log); + } + fprintf(stderr, "FATAL: _db_print: can't initialize critical section\n"); + abort(); } else InitializeCriticalSection(dbg_mutex); } - __except(STATUS_NO_MEMORY == - GetExceptionCode()? EXCEPTION_EXECUTE_HANDLER : - EXCEPTION_CONTINUE_SEARCH) { - if (debug_log) { - fprintf(debug_log, "FATAL: _db_print: can't initialize critical section\n"); - fflush(debug_log); - } - fprintf(stderr, "FATAL: _db_print: can't initialize critical section\n"); - abort(); - } } EnterCriticalSection(dbg_mutex); #endif @@ -119,7 +113,7 @@ #if HAVE_SYSLOG _db_print_syslog(format, args3); #endif -#if defined (_SQUID_MSWIN_) && !defined(PINGER) +#ifdef _SQUID_MSWIN_ LeaveCriticalSection(dbg_mutex); #endif va_end(args1); Index: squid/src/dns_internal.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/dns_internal.c,v retrieving revision 1.15.14.4 retrieving revision 1.15.14.5 diff -u -r1.15.14.4 -r1.15.14.5 --- squid/src/dns_internal.c 28 Sep 2002 14:27:50 -0000 1.15.14.4 +++ squid/src/dns_internal.c 27 Oct 2002 10:46:14 -0000 1.15.14.5 @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.c,v 1.15.14.4 2002/09/28 14:27:50 serassio Exp $ + * $Id: dns_internal.c,v 1.15.14.5 2002/10/27 10:46:14 serassio Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -35,6 +35,10 @@ #include "squid.h" +/* MS VisualStudio Projects are monolitich, so we need the followin + #ifndef to exclude the internal DNS code from compile process when + using External DNS process. + */ #ifndef USE_DNSSERVERS #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) #include Index: squid/src/fd.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fd.c,v retrieving revision 1.7.16.6 retrieving revision 1.7.16.7 diff -u -r1.7.16.6 -r1.7.16.7 --- squid/src/fd.c 2 Jun 2002 19:26:57 -0000 1.7.16.6 +++ squid/src/fd.c 27 Oct 2002 10:46:14 -0000 1.7.16.7 @@ -1,6 +1,6 @@ /* - * $Id: fd.c,v 1.7.16.6 2002/06/02 19:26:57 serassio Exp $ + * $Id: fd.c,v 1.7.16.7 2002/10/27 10:46:14 serassio Exp $ * * DEBUG: section 51 Filedescriptor Functions * AUTHOR: Duane Wessels @@ -163,8 +163,7 @@ F->write_method = &file_write_method; break; default: - F->read_method = &default_read_method; - F->write_method = &default_write_method; + fatalf("fd_open(): unknown FD type - FD#: %i, type: %u, desc %s\n", fd, type, desc); } #else F->read_method = &default_read_method; Index: squid/src/globals.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/globals.h,v retrieving revision 1.14.14.4 retrieving revision 1.14.14.5 diff -u -r1.14.14.4 -r1.14.14.5 --- squid/src/globals.h 15 Jul 2002 06:18:08 -0000 1.14.14.4 +++ squid/src/globals.h 27 Oct 2002 10:46:14 -0000 1.14.14.5 @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.14.14.4 2002/07/15 06:18:08 serassio Exp $ + * $Id: globals.h,v 1.14.14.5 2002/10/27 10:46:14 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -160,6 +160,7 @@ extern hash_table *proxy_auth_username_cache; /* NULL */ extern int incoming_sockets_accepted; #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) +extern unsigned int WIN32_Socks_initialized; /* 0 */ extern unsigned int WIN32_OS_version; /* 0 */ extern char *WIN32_OS_string; /* NULL */ extern char *WIN32_Service_name; /* NULL */ Index: squid/src/icmp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icmp.c,v retrieving revision 1.4.74.7 retrieving revision 1.4.74.8 diff -u -r1.4.74.7 -r1.4.74.8 --- squid/src/icmp.c 28 Sep 2002 14:27:51 -0000 1.4.74.7 +++ squid/src/icmp.c 27 Oct 2002 10:46:14 -0000 1.4.74.8 @@ -1,6 +1,6 @@ /* - * $Id: icmp.c,v 1.4.74.7 2002/09/28 14:27:51 serassio Exp $ + * $Id: icmp.c,v 1.4.74.8 2002/10/27 10:46:14 serassio Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels @@ -86,7 +86,7 @@ sizeof(pingerReplyData), 0); if (n < 0) { - debug(50, 1) ("icmpRecv: recv: %s\n", xstrerror()); + debug(37, 1) ("icmpRecv: recv: %s\n", xstrerror()); if (++fail_count == 10 || errno == ECONNREFUSED) icmpClose(); return; @@ -124,7 +124,7 @@ inet_ntoa(pkt->to), (int) pkt->opcode, pkt->psize); x = send(icmp_sock, (char *) pkt, len, 0); if (x < 0) { - debug(50, 1) ("icmpSend: send: %s\n", xstrerror()); + debug(37, 1) ("icmpSend: send: %s\n", xstrerror()); if (errno == ECONNREFUSED || errno == EPIPE) { icmpClose(); return; @@ -208,7 +208,7 @@ int rfd; int wfd; if (strcmp(Config.Program.pinger, "none") == 0) { - debug(29, 1) ("Pinger disabled\n"); + debug(37, 1) ("Pinger disabled\n"); return; } args[0] = "(pinger)"; @@ -230,7 +230,7 @@ fd_note(icmp_sock, "pinger"); commSetSelect(icmp_sock, COMM_SELECT_READ, icmpRecv, NULL, 0); commSetTimeout(icmp_sock, -1, NULL, NULL); - debug(29, 1) ("Pinger socket opened on FD %d\n", icmp_sock); + debug(37, 1) ("Pinger socket opened on FD %d\n", icmp_sock); #endif } @@ -240,7 +240,7 @@ #if USE_ICMP if (icmp_sock < 0) return; - debug(29, 1) ("Closing Pinger socket on FD %d\n", icmp_sock); + debug(37, 1) ("Closing Pinger socket on FD %d\n", icmp_sock); #ifdef _SQUID_MSWIN_ send(icmp_sock, "$shutdown\n", 10, 0); #endif @@ -249,7 +249,7 @@ if (hIpc) { if (WaitForSingleObject(hIpc, 12000) != WAIT_OBJECT_0) { getCurrentTime(); - debug(34, 1) + debug(37, 1) ("icmpClose: WARNING: (pinger,%ld) didn't exit in 12 seconds\n", (long int)pid); } Index: squid/src/ipc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipc.c,v retrieving revision 1.7.10.8 retrieving revision 1.7.10.9 diff -u -r1.7.10.8 -r1.7.10.9 --- squid/src/ipc.c 28 Sep 2002 14:27:51 -0000 1.7.10.8 +++ squid/src/ipc.c 27 Oct 2002 10:46:15 -0000 1.7.10.9 @@ -1,6 +1,6 @@ /* - * $Id: ipc.c,v 1.7.10.8 2002/09/28 14:27:51 serassio Exp $ + * $Id: ipc.c,v 1.7.10.9 2002/10/27 10:46:15 serassio Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -604,7 +604,7 @@ hProcess = pi.hProcess; } else { pid = -1; - _dosmaperr(GetLastError()); + WIN32_maperror(GetLastError()); x = errno; } } Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.28.6.1.4.13 retrieving revision 1.28.6.1.4.14 diff -u -r1.28.6.1.4.13 -r1.28.6.1.4.14 --- squid/src/main.c 20 Oct 2002 09:17:30 -0000 1.28.6.1.4.13 +++ squid/src/main.c 27 Oct 2002 10:46:15 -0000 1.28.6.1.4.14 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.28.6.1.4.13 2002/10/20 09:17:30 serassio Exp $ + * $Id: main.c,v 1.28.6.1.4.14 2002/10/27 10:46:15 serassio Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -572,6 +572,8 @@ debug(1, 1) ("With %d file descriptors available\n", Squid_MaxFD); #ifdef _SQUID_MSWIN_ debug(1, 1) ("With %d CRT stdio descriptors available\n", _getmaxstdio()); + if (WIN32_Socks_initialized) + debug(1, 1)("Windows sockets initialized\n"); #endif if (!configured_once) Index: squid/src/unlinkd.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/unlinkd.c,v retrieving revision 1.6.10.8 retrieving revision 1.6.10.9 diff -u -r1.6.10.8 -r1.6.10.9 --- squid/src/unlinkd.c 21 Jul 2002 08:58:20 -0000 1.6.10.8 +++ squid/src/unlinkd.c 27 Oct 2002 10:46:15 -0000 1.6.10.9 @@ -1,6 +1,6 @@ /* - * $Id: unlinkd.c,v 1.6.10.8 2002/07/21 08:58:20 serassio Exp $ + * $Id: unlinkd.c,v 1.6.10.9 2002/10/27 10:46:15 serassio Exp $ * * DEBUG: section 2 Unlink Daemon * AUTHOR: Duane Wessels @@ -160,7 +160,7 @@ { #ifdef _SQUID_MSWIN_ if (unlinkd_wfd > -1) { - debug(12, 1) ("Closing unlinkd pipe on FD %d\n", unlinkd_wfd); + debug(2, 1) ("Closing unlinkd pipe on FD %d\n", unlinkd_wfd); shutdown(unlinkd_wfd, SD_BOTH); comm_close(unlinkd_wfd); if (unlinkd_wfd != unlinkd_rfd) @@ -168,12 +168,12 @@ unlinkd_wfd = -1; unlinkd_rfd = -1; } else - debug(12, 0) ("unlinkdClose: WARNING: unlinkd_wfd is %d\n", + debug(2, 0) ("unlinkdClose: WARNING: unlinkd_wfd is %d\n", unlinkd_wfd); if (hIpc) { if (WaitForSingleObject(hIpc, 5000) != WAIT_OBJECT_0) { getCurrentTime(); - debug(12, 1) + debug(2, 1) ("unlinkdClose: WARNING: (unlinkd,%ld) didn't exit in 5 seconds\n", pid); } Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.5.14.12 retrieving revision 1.5.14.13 diff -u -r1.5.14.12 -r1.5.14.13 --- squid/src/win32.c 20 Oct 2002 09:54:08 -0000 1.5.14.12 +++ squid/src/win32.c 27 Oct 2002 10:46:15 -0000 1.5.14.13 @@ -127,13 +127,13 @@ NULL, /* class */ REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKeyNext, &result); if (rv != ERROR_SUCCESS) { - debug(1, 1) ("RegCreateKeyEx(%s),%d\n", keys[index], (int) rv); + fprintf(stderr, "RegCreateKeyEx(%s),%d\n", keys[index], (int) rv); retval = -4; } /* Close the old key */ rv = RegCloseKey(hKey); if (rv != ERROR_SUCCESS) { - debug(1, 1) ("RegCloseKey %d\n", (int) rv); + fprintf(stderr, "RegCloseKey %d\n", (int) rv); if (retval == 0) { /* Keep error status from RegCreateKeyEx, if any */ retval = -4; @@ -151,7 +151,7 @@ */ rv = RegCloseKey(hKey); if (rv != ERROR_SUCCESS) { - debug(1, 1) ("RegCloseKey %d\n", (int) rv); + fprintf(stderr, "RegCloseKey %d\n", (int) rv); if (retval == 0) { /* Keep error status from RegCreateKeyEx, if any */ retval = -4; @@ -181,13 +181,13 @@ */ rv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY, 0, KEY_WRITE, &hKey); if (rv == ERROR_FILE_NOT_FOUND) { - debug(1, 1) ("Registry does not contain key %s after creation", + fprintf(stderr, "Registry does not contain key %s after creation\n", REGKEY); return -1; } } if (rv != ERROR_SUCCESS) { - debug(1, 1) ("RegOpenKeyEx HKLM\\%s, %d\n", REGKEY, (int) rv); + fprintf(stderr, "RegOpenKeyEx HKLM\\%s, %d\n", REGKEY, (int) rv); return -4; } /* Now set the value and data */ @@ -198,10 +198,10 @@ (DWORD) value_size); /* for size of "value" */ retval = 0; /* Return value */ if (rv != ERROR_SUCCESS) { - debug(1, 1) ("RegQueryValueEx(key %s),%d\n", key, (int) rv); + fprintf(stderr, "RegQueryValueEx(key %s),%d\n", key, (int) rv); retval = -4; } else { - debug(1, 1) ("Registry stored HKLM\\%s\\%s value %s\n", + fprintf(stderr, "Registry stored HKLM\\%s\\%s value %s\n", REGKEY, key, type == REG_SZ ? value : (unsigned char *) "(not displayable)"); @@ -211,7 +211,7 @@ */ rv = RegCloseKey(hKey); if (rv != ERROR_SUCCESS) { - debug(1, 1) ("RegCloseKey HKLM\\%s, %d\n", REGKEY, (int) rv); + fprintf(stderr, "RegCloseKey HKLM\\%s, %d\n", REGKEY, (int) rv); if (retval == 0) { /* Keep error status from RegQueryValueEx, if any */ retval = -4; @@ -453,15 +453,15 @@ shut_down(SIGTERM); if (!SetServiceStatus(svcHandle, &svcStatus)) { status = GetLastError(); - debug(1, 1) (" SetServiceStatus error %ld\n", status); + debug(1, 1) ("SetServiceStatus error %ld\n", status); } - debug(1, 1) ("Leaving Squid service \n"); + debug(1, 1) ("Leaving Squid service\n"); return; case _WIN_SQUID_SERVICE_CONTROL_INTERROGATE: /* Fall through to send current status. */ if (!SetServiceStatus(svcHandle, &svcStatus)) { status = GetLastError(); - debug(1, 1) (" SetServiceStatus error %ld\n", status); + debug(1, 1) ("SetServiceStatus error %ld\n", status); } break; case _WIN_SQUID_SERVICE_CONTROL_ROTATE: @@ -482,9 +482,9 @@ shut_down(SIGINT); if (!SetServiceStatus(svcHandle, &svcStatus)) { status = GetLastError(); - debug(1, 1) (" SetServiceStatus error %ld\n", status); + debug(1, 1) ("SetServiceStatus error %ld\n", status); } - debug(1, 1) ("Leaving Squid service \n"); + debug(1, 1) ("Leaving Squid service\n"); break; default: debug(1, 1) ("Unrecognized opcode %ld\n", Opcode); @@ -507,11 +507,11 @@ SC_MANAGER_ALL_ACCESS /* access required */ ); if (!schSCManager) - debug(1, 1) ("OpenSCManager failed"); + fprintf(stderr, "OpenSCManager failed\n"); else { schService = OpenService(schSCManager, WIN32_Service_name, SERVICE_ALL_ACCESS); if (schService == NULL) - debug(1, 1) ("OpenService failed"); + fprintf(stderr, "OpenService failed\n"); /* Could not open the service */ else { /* try to stop the service */ @@ -527,7 +527,7 @@ } /* now remove the service */ if (DeleteService(schService) == 0) - fprintf(stderr,"DeleteService failed.\n"); + fprintf(stderr, "DeleteService failed.\n"); else printf("Service %s deleted successfully.\n", WIN32_Service_name); @@ -562,7 +562,7 @@ strcat(REGKEY, WIN32_Service_name); keys[4] = WIN32_Service_name; if ((lenpath = GetModuleFileName(NULL, ServicePath, 512)) == 0) { - debug(1, 1) ("Can't get executable path"); + fprintf(stderr, "Can't get executable path\n"); exit(1); } snprintf(szPath, sizeof(szPath), "%s %s:%s", ServicePath, _WIN_SQUID_SERVICE_OPTION, WIN32_Service_name); @@ -571,7 +571,7 @@ SC_MANAGER_ALL_ACCESS /* access required */ ); if (!schSCManager) { - debug(1, 1) ("OpenSCManager failed"); + fprintf(stderr, "OpenSCManager failed\n"); exit(1); } else { @@ -615,7 +615,7 @@ ("To run, start it from the Services Applet of Control Panel.\n"); printf("Don't forget to edit squid.conf before starting it.\n\n"); } else { - debug(1, 1) ("CreateService failed"); + fprintf(stderr, "CreateService failed\n"); exit(1); } CloseServiceHandle(schSCManager); @@ -637,7 +637,7 @@ SC_MANAGER_ALL_ACCESS /* access required */ ); if (!schSCManager) { - debug(1, 1) ("OpenSCManager failed"); + fprintf(stderr, "OpenSCManager failed\n"); exit(1); } /* The required service object access depends on the control. */ @@ -754,7 +754,7 @@ PROCESS_VM_READ, FALSE, GetCurrentProcessId()); { - /* Microsoft Visual C++ doesn't have getrusage function, */ + /* Microsoft CRT doesn't have getrusage function, */ /* so we get process CPU time information from PSAPI.DLL. */ FILETIME ftCreate, ftExit, ftKernel, ftUser; if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) @@ -813,7 +813,7 @@ WSACleanup(); return (s_iInitCount); } - debug(1,1)("Windows sockets initialised"); + WIN32_Socks_initialized = 1; s_iInitCount++; return (s_iInitCount); } Index: squid/src/auth/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/Makefile.am,v retrieving revision 1.2 retrieving revision 1.2.40.1 diff -u -r1.2 -r1.2.40.1 --- squid/src/auth/Makefile.am 1 Sep 2001 11:46:49 -0000 1.2 +++ squid/src/auth/Makefile.am 27 Oct 2002 10:46:15 -0000 1.2.40.1 @@ -14,5 +14,9 @@ libdigest_a_SOURCES = digest/auth_digest.c digest/auth_digest.h libntlm_a_SOURCES = ntlm/auth_ntlm.c ntlm/auth_ntlm.h -INCLUDES = -I. -I$(top_builddir)/include -I$(top_srcdir)/include \ - -I$(top_srcdir)/src/ +if ENABLE_WIN32SPECIFIC +INCLUDES = -I. -I$(top_srcdir)/port/win32/include -I$(top_srcdir)/include \ + -I$(top_srcdir)/src +else +INCLUDES = -I. -I$(top_srcdir)/include -I$(top_srcdir)/src +endif Index: squid/src/fs/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/Makefile.am,v retrieving revision 1.2.40.2 retrieving revision 1.2.40.3 diff -u -r1.2.40.2 -r1.2.40.3 --- squid/src/fs/Makefile.am 25 May 2002 12:08:36 -0000 1.2.40.2 +++ squid/src/fs/Makefile.am 27 Oct 2002 10:46:15 -0000 1.2.40.3 @@ -25,8 +25,12 @@ EXTRA_DIST = \ coss/coss-notes.txt -INCLUDES = -I. -I$(top_builddir)/include -I$(top_srcdir)/include \ +if ENABLE_WIN32SPECIFIC +INCLUDES = -I. -I$(top_srcdir)/port/win32/include -I$(top_srcdir)/include \ -I$(top_srcdir)/src/ +else +INCLUDES = -I. -I$(top_srcdir)/include -I$(top_srcdir)/src +endif ## targets below to emulate distributed makefiles aufs/all: libaufs.a Index: squid/src/fs/awin32/aiops.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/aiops.c,v retrieving revision 1.1.62.9 retrieving revision 1.1.62.10 diff -u -r1.1.62.9 -r1.1.62.10 --- squid/src/fs/awin32/aiops.c 22 Sep 2002 11:38:06 -0000 1.1.62.9 +++ squid/src/fs/awin32/aiops.c 27 Oct 2002 10:46:15 -0000 1.1.62.10 @@ -1,5 +1,5 @@ /* - * $Id: aiops.c,v 1.1.62.9 2002/09/22 11:38:06 serassio Exp $ + * $Id: aiops.c,v 1.1.62.10 2002/10/27 10:46:15 serassio Exp $ * * DEBUG: section 43 AIOPS * AUTHOR: Stewart Forster @@ -300,6 +300,7 @@ /* Create threads and get them to sit in their wait loop */ squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t)); + assert(NUMTHREADS); for (i = 0; i < NUMTHREADS; i++) { threadp = memPoolAlloc(squidaio_thread_pool); threadp->status = _THREAD_STARTING; @@ -513,46 +514,31 @@ request->resultp->_data = request; /* Play some tricks with the request_queue2 queue */ request->next = NULL; - if (!request_queue2.head) { - /* If queue2 is empty, insert into queue 1 and try to "push" the queue - If the "push" fails, queue it via queue2 */ - if (WaitForSingleObject(request_queue.mutex, 0) == WAIT_OBJECT_0) { - /* Normal path */ - *request_queue.tailp = request; - request_queue.tailp = &request->next; - if (!SetEvent(request_queue.cond)) - fatal("couldn't push queue\n"); - if (!ReleaseMutex(request_queue.mutex)) { - /* unexpected error */ - fatal("couldn't push queue\n"); - } - Sleep(0); - } else { - /* Oops, the request queue is blocked, use request_queue2 */ - *request_queue2.tailp = request; - request_queue2.tailp = &request->next; - } - } else { - /* Secondary path. We have blocked requests to deal with */ - /* add the request to the chain */ - *request_queue2.tailp = request; - if (WaitForSingleObject(request_queue.mutex, 0)==WAIT_OBJECT_0) { - /* Ok, the queue is no longer blocked */ + if (WaitForSingleObject(request_queue.mutex, 0) == WAIT_OBJECT_0) { + if (request_queue2.head) { + /* Grab blocked requests */ *request_queue.tailp = request_queue2.head; - request_queue.tailp = &request->next; - if (!SetEvent(request_queue.cond)) - fatal("couldn't push queue\n"); - if (!ReleaseMutex(request_queue.mutex)) { - /* unexpected error */ - fatal("couldn't push queue\n"); - } - Sleep(0); + request_queue.tailp = request_queue2.tailp; + } + /* Enqueue request */ + *request_queue.tailp = request; + request_queue.tailp = &request->next; + if (!SetEvent(request_queue.cond)) + fatal("couldn't push queue\n"); + if (!ReleaseMutex(request_queue.mutex)) { + /* unexpected error */ + fatal("couldn't push queue\n"); + } + Sleep(0); + if (request_queue2.head) { + /* Clear queue of blocked requests */ request_queue2.head = NULL; request_queue2.tailp = &request_queue2.head; - } else { - /* still blocked, bump the blocked request chain */ - request_queue2.tailp = &request->next; } + } else { + /* Oops, the request queue is blocked, use request_queue2 */ + *request_queue2.tailp = request; + request_queue2.tailp = &request->next; } if (request_queue2.head) { static int filter = 0; @@ -721,7 +707,7 @@ #ifdef _SQUID_MSWIN_ if (!ReadFile((HANDLE)_get_osfhandle(requestp->fd), requestp->tmpbufp, requestp->buflen, (LPDWORD)&requestp->ret, NULL)) { - _dosmaperr(GetLastError()); + WIN32_maperror(GetLastError()); requestp->ret = -1; } #else @@ -760,7 +746,7 @@ #ifdef _SQUID_MSWIN_ if (!WriteFile((HANDLE)_get_osfhandle(requestp->fd), requestp->tmpbufp, requestp->buflen, (LPDWORD)&requestp->ret, NULL)) { - _dosmaperr(GetLastError()); + WIN32_maperror(GetLastError()); requestp->ret = -1; } #else Index: squid/src/fs/awin32/store_dir_aufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/store_dir_aufs.c,v retrieving revision 1.1.62.10 retrieving revision 1.1.62.11 diff -u -r1.1.62.10 -r1.1.62.11 --- squid/src/fs/awin32/store_dir_aufs.c 24 Aug 2002 10:06:52 -0000 1.1.62.10 +++ squid/src/fs/awin32/store_dir_aufs.c 27 Oct 2002 10:46:15 -0000 1.1.62.11 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.c,v 1.1.62.10 2002/08/24 10:06:52 serassio Exp $ + * $Id: store_dir_aufs.c,v 1.1.62.11 2002/10/27 10:46:15 serassio Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -215,7 +215,11 @@ } else { fatalf("Swap directory %s is not a directory.", path); } +#ifdef _SQUID_MSWIN_ + } else if (0 == mkdir(path)) { +#else } else if (0 == mkdir(path, 0755)) { +#endif debug(47, should_exist ? 1 : 3) ("%s created\n", path); created = 1; } else { @@ -1170,7 +1174,11 @@ if (dp == NULL) { if (errno == ENOENT) { debug(36, 0) ("storeDirClean: WARNING: Creating %s\n", p1); +#ifdef _SQUID_MSWIN_ + if (mkdir(p1) == 0) +#else if (mkdir(p1, 0777) == 0) +#endif return 0; } debug(50, 0) ("storeDirClean: %s: %s\n", p1, xstrerror()); Index: squid/src/fs/ufs/store_dir_ufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/store_dir_ufs.c,v retrieving revision 1.21.6.1.4.11 retrieving revision 1.21.6.1.4.12 diff -u -r1.21.6.1.4.11 -r1.21.6.1.4.12 --- squid/src/fs/ufs/store_dir_ufs.c 22 Sep 2002 11:38:06 -0000 1.21.6.1.4.11 +++ squid/src/fs/ufs/store_dir_ufs.c 27 Oct 2002 10:46:16 -0000 1.21.6.1.4.12 @@ -214,7 +214,11 @@ } else { fatalf("Swap directory %s is not a directory.", path); } +#ifdef _SQUID_MSWIN_ + } else if (0 == mkdir(path)) { +#else } else if (0 == mkdir(path, 0755)) { +#endif debug(47, should_exist ? 1 : 3) ("%s created\n", path); created = 1; } else { @@ -1168,7 +1172,11 @@ if (dp == NULL) { if (errno == ENOENT) { debug(36, 0) ("storeDirClean: WARNING: Creating %s\n", p1); +#ifdef _SQUID_MSWIN_ + if (mkdir(p1) == 0) +#else if (mkdir(p1, 0777) == 0) +#endif return 0; } debug(50, 0) ("storeDirClean: %s: %s\n", p1, xstrerror());