--------------------- PatchSet 3737 Date: 2002/03/16 10:31:31 Author: serassio Branch: nt-2_5 Tag: (none) Log: Imported Windows patches fron NT-2_3 and Cygwin-svc (second round) Members: src/client.c:1.8->1.8.14.1 src/debug.c:1.9->1.9.10.1 src/mime.c:1.11->1.11.14.1 src/win32.c:1.5.14.1->1.5.14.2 src/fs/aufs/store_dir_aufs.c:1.23.6.1->1.23.6.1.4.1 src/fs/ufs/store_dir_ufs.c:1.21.6.1.4.1->1.21.6.1.4.2 Index: squid/src/client.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/client.c,v retrieving revision 1.8 retrieving revision 1.8.14.1 diff -u -r1.8 -r1.8.14.1 --- squid/src/client.c 18 Oct 2001 20:52:11 -0000 1.8 +++ squid/src/client.c 16 Mar 2002 10:31:31 -0000 1.8.14.1 @@ -1,6 +1,6 @@ /* - * $Id: client.c,v 1.8 2001/10/18 20:52:11 squidadm Exp $ + * $Id: client.c,v 1.8.14.1 2002/03/16 10:31:31 serassio Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived @@ -200,7 +200,7 @@ xstrerror()); exit(-1); } -#if defined(_SQUID_CYGWIN_) +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) setmode(put_fd, O_BINARY); #endif fstat(put_fd, &sb); Index: squid/src/debug.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/debug.c,v retrieving revision 1.9 retrieving revision 1.9.10.1 diff -u -r1.9 -r1.9.10.1 --- squid/src/debug.c 18 Dec 2001 13:38:47 -0000 1.9 +++ squid/src/debug.c 16 Mar 2002 10:31:31 -0000 1.9.10.1 @@ -1,6 +1,6 @@ /* - * $Id: debug.c,v 1.9 2001/12/18 13:38:47 squidadm Exp $ + * $Id: debug.c,v 1.9.10.1 2002/03/16 10:31:31 serassio Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -67,7 +67,7 @@ /* give a chance to context-based debugging to print current context */ if (!Ctx_Lock) ctx_print(); -#if STDC_HEADERS +#if STDC_HEADERS va_start(args1, format); va_start(args2, format); va_start(args3, format); @@ -177,7 +177,7 @@ fflush(stderr); debug_log = stderr; } -#if defined(_SQUID_CYGWIN_) +#if defined(_SQUID_CYGWIN_)||defined(_SQUID_MSWIN_) setmode(fileno(debug_log), O_TEXT); #endif } @@ -237,6 +237,14 @@ snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, i); rename(from, to); } +/* + * You can't rename open files on Microsoft "operating systems" + * so we close before renaming. + */ +#ifdef _SQUID_MSWIN_ + if (debug_log != stderr) + fclose(debug_log); +#endif /* Rotate the current log to .0 */ if (Config.Log.rotateNumber > 0) { snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, 0); Index: squid/src/mime.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/mime.c,v retrieving revision 1.11 retrieving revision 1.11.14.1 diff -u -r1.11 -r1.11.14.1 --- squid/src/mime.c 13 Nov 2001 22:19:33 -0000 1.11 +++ squid/src/mime.c 16 Mar 2002 10:31:31 -0000 1.11.14.1 @@ -1,6 +1,6 @@ /* - * $Id: mime.c,v 1.11 2001/11/13 22:19:33 squidadm Exp $ + * $Id: mime.c,v 1.11.14.1 2002/03/16 10:31:31 serassio Exp $ * * DEBUG: section 25 MIME Parsing * AUTHOR: Harvest Derived @@ -297,7 +297,7 @@ debug(50, 1) ("mimeInit: %s: %s\n", filename, xstrerror()); return; } -#if defined (_SQUID_CYGWIN_) +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) setmode(fileno(fp), O_TEXT); #endif mimeFreeMemory(); Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.5.14.1 retrieving revision 1.5.14.2 diff -u -r1.5.14.1 -r1.5.14.2 --- squid/src/win32.c 14 Mar 2002 20:23:46 -0000 1.5.14.1 +++ squid/src/win32.c 16 Mar 2002 10:31:31 -0000 1.5.14.2 @@ -30,12 +30,12 @@ /* This code compiles only CygWin & Windows NT Port */ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) #include -#ifdef _SQUID_MSWIN_ -#if HAVE_WIN32_PSAPI -#include -#endif -#include -#endif +#ifdef _SQUID_MSWIN_ +#if HAVE_WIN32_PSAPI +#include +#endif +#include +#endif static unsigned int GetOSVersion(); void WIN32_svcstatusupdate(DWORD); @@ -709,54 +709,54 @@ #if defined(_SQUID_MSWIN_) static int s_iInitCount = 0; -int WIN32_getrusage(int who, struct rusage *usage) -{ -#if HAVE_WIN32_PSAPI - if ((WIN32_OS_version == _WIN_OS_WINNT) || (WIN32_OS_version == _WIN_OS_WIN2K) - || (WIN32_OS_version == _WIN_OS_WINXP)) - { - /* On Windows NT/2000 call PSAPI.DLL for process Memory */ - /* informations -- Guido Serassio */ - HANDLE hProcess; - PROCESS_MEMORY_COUNTERS pmc; - hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | - PROCESS_VM_READ, - FALSE, GetCurrentProcessId()); - { - /* Microsoft Visual C++ 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)) - { - LONGLONG tUser64 = (*(LONGLONG *)&ftUser / 10); - LONGLONG tKernel64 = (*(LONGLONG *)&ftKernel / 10); - usage->ru_utime.tv_sec =(long)(tUser64 / 1000000); - usage->ru_stime.tv_sec =(long)(tKernel64 / 1000000); - usage->ru_utime.tv_usec =(long)(tUser64 % 1000000); - usage->ru_stime.tv_usec =(long)(tKernel64 % 1000000); - } - else - { - CloseHandle( hProcess ); - return -1; - } - } - if (GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc))) - { - usage->ru_maxrss=(DWORD)(pmc.WorkingSetSize /1024); - usage->ru_majflt=pmc.PageFaultCount; - } - else - { - CloseHandle( hProcess ); - return -1; - } - CloseHandle( hProcess ); - } -#endif - return 0; -} - +int WIN32_getrusage(int who, struct rusage *usage) +{ +#if HAVE_WIN32_PSAPI + if ((WIN32_OS_version == _WIN_OS_WINNT) || (WIN32_OS_version == _WIN_OS_WIN2K) + || (WIN32_OS_version == _WIN_OS_WINXP)) + { + /* On Windows NT/2000 call PSAPI.DLL for process Memory */ + /* informations -- Guido Serassio */ + HANDLE hProcess; + PROCESS_MEMORY_COUNTERS pmc; + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | + PROCESS_VM_READ, + FALSE, GetCurrentProcessId()); + { + /* Microsoft Visual C++ 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)) + { + LONGLONG tUser64 = (*(LONGLONG *)&ftUser / 10); + LONGLONG tKernel64 = (*(LONGLONG *)&ftKernel / 10); + usage->ru_utime.tv_sec =(long)(tUser64 / 1000000); + usage->ru_stime.tv_sec =(long)(tKernel64 / 1000000); + usage->ru_utime.tv_usec =(long)(tUser64 % 1000000); + usage->ru_stime.tv_usec =(long)(tKernel64 % 1000000); + } + else + { + CloseHandle( hProcess ); + return -1; + } + } + if (GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc))) + { + usage->ru_maxrss=(DWORD)(pmc.WorkingSetSize /1024); + usage->ru_majflt=pmc.PageFaultCount; + } + else + { + CloseHandle( hProcess ); + return -1; + } + CloseHandle( hProcess ); + } +#endif + return 0; +} + static int Win32SockInit(void) { int iVersionRequested; Index: squid/src/fs/aufs/store_dir_aufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/aufs/store_dir_aufs.c,v retrieving revision 1.23.6.1 retrieving revision 1.23.6.1.4.1 diff -u -r1.23.6.1 -r1.23.6.1.4.1 --- squid/src/fs/aufs/store_dir_aufs.c 20 Feb 2002 02:49:04 -0000 1.23.6.1 +++ squid/src/fs/aufs/store_dir_aufs.c 16 Mar 2002 10:31:32 -0000 1.23.6.1.4.1 @@ -862,7 +862,7 @@ char *new_path = xstrdup(storeAufsDirSwapLogFile(sd, ".new")); int fd; file_close(aioinfo->swaplog_fd); -#if defined (_SQUID_OS2_) || defined (_SQUID_CYGWIN_) +#if defined (_SQUID_OS2_) || defined (_SQUID_CYGWIN_) || defined (_SQUID_MSWIN_) if (unlink(swaplog_path) < 0) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeAufsDirCloseTmpSwapLog: unlink failed"); @@ -917,7 +917,7 @@ debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); } -#if defined(_SQUID_CYGWIN_) +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) setmode(fileno(fp), O_BINARY); #endif memset(&clean_sb, '\0', sizeof(struct stat)); @@ -1062,7 +1062,7 @@ fd = state->fd; /* rename */ if (state->fd >= 0) { -#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) +#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) || defined(_SQUID_MSWIN_) file_close(state->fd); state->fd = -1; if (unlink(state->cur) < 0) 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.1 retrieving revision 1.21.6.1.4.2 diff -u -r1.21.6.1.4.1 -r1.21.6.1.4.2 --- squid/src/fs/ufs/store_dir_ufs.c 14 Mar 2002 20:23:47 -0000 1.21.6.1.4.1 +++ squid/src/fs/ufs/store_dir_ufs.c 16 Mar 2002 10:31:33 -0000 1.21.6.1.4.2 @@ -416,12 +416,12 @@ rb->sd->path, rb->counts.scancount); debug(20, 9) ("file_in: fd=%d %08X\n", fd, filn); statCounter.syscalls.disk.reads++; -#ifdef _SQUID_MSWIN_ - if (fread(hdr_buf, 1, SM_PAGE_SIZE, fd_table[fd].fbuf) == 0 - && ferror(fd_table[fd].fbuf)) { -#else - if (read(fd, hdr_buf, SM_PAGE_SIZE) < 0) { -#endif +#ifdef _SQUID_MSWIN_ + if (fread(hdr_buf, 1, SM_PAGE_SIZE, fd_table[fd].fbuf) == 0 + && ferror(fd_table[fd].fbuf)) { +#else + if (read(fd, hdr_buf, SM_PAGE_SIZE) < 0) { +#endif debug(20, 1) ("storeUfsDirRebuildFromDirectory: read(FD %d): %s\n", fd, xstrerror()); file_close(fd); @@ -1024,11 +1024,11 @@ state->outbuf_offset += ss; /* buffered write */ if (state->outbuf_offset + ss > CLEAN_BUF_SZ) { -#ifdef _SQUID_MSWIN_ - if (fwrite(state->outbuf, 1, state->outbuf_offset, fd_table[state->fd].fbuf) < state->outbuf_offset) { -#else +#ifdef _SQUID_MSWIN_ + if (fwrite(state->outbuf, 1, state->outbuf_offset, fd_table[state->fd].fbuf) < state->outbuf_offset) { +#else if (write(state->fd, state->outbuf, state->outbuf_offset) < 0) { -#endif +#endif debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", state->new, xstrerror()); debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile not replaced.\n"); @@ -1046,9 +1046,9 @@ static void storeUfsDirWriteCleanDone(SwapDir * sd) { -#ifdef _SQUID_MSWIN_ - FILE *fbuf; -#endif +#ifdef _SQUID_MSWIN_ + FILE *fbuf; +#endif int fd; struct _clean_state *state = sd->log.clean.state; if (NULL == state) @@ -1056,13 +1056,13 @@ if (state->fd < 0) return; state->walker->Done(state->walker); -#ifdef _SQUID_MSWIN_ - fbuf=fd_table[state->fd].fbuf; - fwrite(state->outbuf, 1, state->outbuf_offset, fbuf); - if (ferror(fbuf) || feof(fbuf)){ -#else +#ifdef _SQUID_MSWIN_ + fbuf=fd_table[state->fd].fbuf; + fwrite(state->outbuf, 1, state->outbuf_offset, fbuf); + if (ferror(fbuf) || feof(fbuf)){ +#else if (write(state->fd, state->outbuf, state->outbuf_offset) < 0) { -#endif +#endif debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", state->new, xstrerror()); debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile " @@ -1591,7 +1591,7 @@ static int storeUfsCleanupDoubleCheck(SwapDir * sd, StoreEntry * e) { -#ifndef _SQUID_MSWIN_ +#ifndef _SQUID_MSWIN_ struct stat sb; if (stat(storeUfsDirFullPath(sd, e->swap_filen, NULL), &sb) < 0) { debug(20, 0) ("storeUfsCleanupDoubleCheck: MISSING SWAP FILE\n"); @@ -1611,7 +1611,7 @@ storeEntryDump(e, 0); return -1; } -#endif +#endif return 0; }