From: wessels <> Date: Thu, 4 Jan 2001 10:42:34 +0000 (+0000) Subject: Robert Collins' Cygwin file mode support and ufs writecleanswap bugfix. X-Git-Tag: SQUID_3_0_PRE1~1705 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c4aefe96cc57b10f60bbbb7d3f8ca660c4eb1ff6;p=thirdparty%2Fsquid.git Robert Collins' Cygwin file mode support and ufs writecleanswap bugfix. Without it users on cygwin with text mode mounts will die badly, and all cygwin users will not ever see a (CLEAN) status on their cache_dir's. Why I was getting clean status when I first looked into this may be due to some of the 'emulation' work done on cygwin to make UN*X assumptions (ie unlinking open files) work somewhat. --- diff --git a/src/acl.cc b/src/acl.cc index 1acbfa2848..cc7083e8cf 100644 --- a/src/acl.cc +++ b/src/acl.cc @@ -1,6 +1,6 @@ /* - * $Id: acl.cc,v 1.228 2001/01/02 00:09:55 wessels Exp $ + * $Id: acl.cc,v 1.229 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -120,6 +120,9 @@ strtokFile(void) debug(28, 0) ("strtokFile: %s not found\n", fn); return (NULL); } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(aclFile), O_TEXT); +#endif aclFromFile = 1; } else { return t; diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 151790cbb8..b898d1c3ba 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.362 2001/01/02 01:41:30 wessels Exp $ + * $Id: cache_cf.cc,v 1.363 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -218,6 +218,9 @@ parseConfigFile(const char *file_name) if ((fp = fopen(file_name, "r")) == NULL) fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror()); +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_TEXT); +#endif cfg_filename = file_name; if ((token = strrchr(cfg_filename, '/'))) cfg_filename = token + 1; diff --git a/src/cache_diff.cc b/src/cache_diff.cc index 9379a62d47..b447511e26 100644 --- a/src/cache_diff.cc +++ b/src/cache_diff.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_diff.cc,v 1.13 2000/10/31 23:48:13 wessels Exp $ + * $Id: cache_diff.cc,v 1.14 2001/01/04 03:42:34 wessels Exp $ * * AUTHOR: Alex Rousskov * @@ -137,6 +137,9 @@ cacheIndexAddLog(CacheIndex * idx, const char *fname) fprintf(stderr, "cannot open %s: %s\n", fname, strerror(errno)); return 0; } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(file), O_BINARY); +#endif scanned_count = cacheIndexScan(idx, fname, file); fclose(file); diff --git a/src/cf_gen.cc b/src/cf_gen.cc index 1e6441fe81..6353701ad7 100644 --- a/src/cf_gen.cc +++ b/src/cf_gen.cc @@ -1,6 +1,6 @@ /* - * $Id: cf_gen.cc,v 1.37 2000/11/25 16:02:14 adrian Exp $ + * $Id: cf_gen.cc,v 1.38 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: none Generate squid.conf and cf_parser.c * AUTHOR: Max Okumoto @@ -66,6 +66,12 @@ #if HAVE_ASSERT_H #include #endif +#if defined(_SQUID_CYGWIN_) +#include +#endif +#if HAVE_FCNTL_H +#include +#endif #include "util.h" @@ -145,6 +151,9 @@ main(int argc, char *argv[]) perror(input_filename); exit(1); } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_TEXT); +#endif state = sSTART; while (feof(fp) == 0 && state != sEXIT) { char buff[MAX_LINE]; @@ -318,6 +327,9 @@ main(int argc, char *argv[]) perror(output_filename); exit(1); } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_TEXT); +#endif fprintf(fp, "/*\n" " * Generated automatically from %s by %s\n" @@ -340,6 +352,9 @@ main(int argc, char *argv[]) perror(conf_filename); exit(1); } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_TEXT); +#endif gen_conf(entries, fp); fclose(fp); diff --git a/src/client.cc b/src/client.cc index 7077fc9e62..4c5bedef39 100644 --- a/src/client.cc +++ b/src/client.cc @@ -1,6 +1,6 @@ /* - * $Id: client.cc,v 1.89 2000/08/15 02:37:14 wessels Exp $ + * $Id: client.cc,v 1.90 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived @@ -203,6 +203,9 @@ main(int argc, char *argv[]) xstrerror()); exit(-1); } +#if defined(_SQUID_CYGWIN_) + setmode(put_fd, O_BINARY); +#endif fstat(put_fd, &sb); } snprintf(msg, BUFSIZ, "%s %s HTTP/1.0\r\n", method, url); diff --git a/src/debug.cc b/src/debug.cc index 18269c0034..3267b988c2 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -1,6 +1,6 @@ /* - * $Id: debug.cc,v 1.78 2000/03/06 16:23:30 wessels Exp $ + * $Id: debug.cc,v 1.79 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -157,6 +157,9 @@ debugOpenLog(const char *logfile) fflush(stderr); debug_log = stderr; } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(debug_log), O_TEXT); +#endif } void diff --git a/src/defines.h b/src/defines.h index 09ea28b2c2..f4ba216783 100644 --- a/src/defines.h +++ b/src/defines.h @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.83 2000/10/17 08:06:03 adrian Exp $ + * $Id: defines.h,v 1.84 2001/01/04 03:42:34 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -281,3 +281,10 @@ #ifndef _PATH_DEVNULL #define _PATH_DEVNULL "/dev/null" #endif + +#ifndef O_TEXT +#define O_TEXT 0 +#endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 1496bdb099..bf8b0d6e9e 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.cc,v 1.34 2000/11/03 17:03:54 wessels Exp $ + * $Id: dns_internal.cc,v 1.35 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -148,6 +148,9 @@ idnsParseResolvConf(void) debug(78, 1) ("%s: %s\n", _PATH_RESOLV_CONF, xstrerror()); return; } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_TEXT); +#endif while (fgets(buf, 512, fp)) { t = strtok(buf, w_space); if (NULL == t) diff --git a/src/errorpage.cc b/src/errorpage.cc index 763ef0c92a..ffd3e4be46 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.158 2000/12/08 23:58:08 wessels Exp $ + * $Id: errorpage.cc,v 1.159 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -171,7 +171,7 @@ errorTryLoadText(const char *page_name, const char *dir) char *text; snprintf(path, sizeof(path), "%s/%s", dir, page_name); - fd = file_open(path, O_RDONLY); + fd = file_open(path, O_RDONLY | O_TEXT); if (fd < 0 || fstat(fd, &sb) < 0) { debug(4, 0) ("errorTryLoadText: '%s': %s\n", path, xstrerror()); if (fd >= 0) diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 04b2ecf62e..0db450a9f7 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.21 2001/01/02 01:41:35 wessels Exp $ + * $Id: store_dir_ufs.cc,v 1.22 2001/01/04 03:42:38 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -322,7 +322,7 @@ storeUfsDirOpenSwapLog(SwapDir * sd) char *path; int fd; path = storeUfsDirSwapLogFile(sd, NULL); - fd = file_open(path, O_WRONLY | O_CREAT); + fd = file_open(path, O_WRONLY | O_CREAT | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", path, xstrerror()); fatal("storeUfsDirOpenSwapLog: Failed to open swap log."); @@ -756,7 +756,7 @@ storeUfsDirGetNextFile(RebuildState * rb, int *sfileno, int *size) snprintf(rb->fullfilename, SQUID_MAXPATHLEN, "%s/%s", rb->fullpath, rb->entry->d_name); debug(20, 3) ("storeUfsDirGetNextFile: Opening %s\n", rb->fullfilename); - fd = file_open(rb->fullfilename, O_RDONLY); + fd = file_open(rb->fullfilename, O_RDONLY | O_BINARY); if (fd < 0) debug(50, 1) ("storeUfsDirGetNextFile: %s: %s\n", rb->fullfilename, xstrerror()); else @@ -862,7 +862,7 @@ storeUfsDirCloseTmpSwapLog(SwapDir * sd) char *new_path = xstrdup(storeUfsDirSwapLogFile(sd, ".new")); int fd; file_close(ufsinfo->swaplog_fd); -#ifdef _SQUID_OS2_ +#if defined (_SQUID_OS2_) || defined (_SQUID_CYGWIN_) if (unlink(swaplog_path) < 0) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeUfsDirCloseTmpSwapLog: unlink failed"); @@ -871,7 +871,7 @@ storeUfsDirCloseTmpSwapLog(SwapDir * sd) if (xrename(new_path, swaplog_path) < 0) { fatal("storeUfsDirCloseTmpSwapLog: rename failed"); } - fd = file_open(swaplog_path, O_WRONLY | O_CREAT); + fd = file_open(swaplog_path, O_WRONLY | O_CREAT | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeUfsDirCloseTmpSwapLog: Failed to open swap log."); @@ -905,7 +905,7 @@ storeUfsDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag) if (ufsinfo->swaplog_fd >= 0) file_close(ufsinfo->swaplog_fd); /* open a write-only FD for the new log */ - fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC); + fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", new_path, xstrerror()); fatal("storeDirOpenTmpSwapLog: Failed to open swap log."); @@ -917,6 +917,9 @@ storeUfsDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag) debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_BINARY); +#endif memset(&clean_sb, '\0', sizeof(struct stat)); if (stat(clean_path, &clean_sb) < 0) *clean_flag = 0; @@ -955,7 +958,7 @@ storeUfsDirWriteCleanStart(SwapDir * sd) sd->log.clean.write = NULL; sd->log.clean.state = NULL; state->new = xstrdup(storeUfsDirSwapLogFile(sd, ".clean")); - state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); + state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (state->fd < 0) { xfree(state->new); xfree(state); @@ -966,7 +969,9 @@ storeUfsDirWriteCleanStart(SwapDir * sd) state->outbuf = xcalloc(CLEAN_BUF_SZ, 1); state->outbuf_offset = 0; state->walker = sd->repl->WalkInit(sd->repl); +#if !(defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_)) unlink(state->new); +#endif unlink(state->cln); debug(20, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n", state->new, state->fd); @@ -1034,6 +1039,7 @@ storeUfsDirWriteCleanEntry(SwapDir * sd, const StoreEntry * e) static void storeUfsDirWriteCleanDone(SwapDir * sd) { + int fd; struct _clean_state *state = sd->log.clean.state; if (NULL == state) return; @@ -1055,24 +1061,26 @@ storeUfsDirWriteCleanDone(SwapDir * sd) * so we have to close before renaming. */ storeUfsDirCloseSwapLog(sd); + /* save the fd value for a later test */ + fd = state->fd; /* rename */ if (state->fd >= 0) { -#ifdef _SQUID_OS2_ +#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) file_close(state->fd); state->fd = -1; - if (unlink(cur) < 0) + if (unlink(state->cur) < 0) debug(50, 0) ("storeDirWriteCleanLogs: unlinkd failed: %s, %s\n", - xstrerror(), cur); + xstrerror(), state->cur); #endif xrename(state->new, state->cur); } /* touch a timestamp file if we're not still validating */ if (store_dirs_rebuilding) (void) 0; - else if (state->fd < 0) + else if (fd < 0) (void) 0; else - file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC)); + file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)); /* close */ safe_free(state->cur); safe_free(state->new); diff --git a/src/fs/ufs/store_io_ufs.cc b/src/fs/ufs/store_io_ufs.cc index 6364396da5..fed25de8ee 100644 --- a/src/fs/ufs/store_io_ufs.cc +++ b/src/fs/ufs/store_io_ufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_io_ufs.cc,v 1.3 2000/06/26 20:17:13 adrian Exp $ + * $Id: store_io_ufs.cc,v 1.4 2001/01/04 03:42:38 wessels Exp $ * * DEBUG: section 79 Storage Manager UFS Interface * AUTHOR: Duane Wessels @@ -54,7 +54,7 @@ storeUfsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, struct stat sb; int fd; debug(79, 3) ("storeUfsOpen: fileno %08X\n", f); - fd = file_open(path, O_RDONLY); + fd = file_open(path, O_RDONLY | O_BINARY); if (fd < 0) { debug(79, 3) ("storeUfsOpen: got failure (%d)\n", errno); return NULL; @@ -88,7 +88,7 @@ storeUfsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * ca { storeIOState *sio; int fd; - int mode = (O_WRONLY | O_CREAT | O_TRUNC); + int mode = (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); char *path; ufsinfo_t *ufsinfo = (ufsinfo_t *) SD->fsdata; sfileno filn; diff --git a/src/logfile.cc b/src/logfile.cc index 707771d131..85edf7231f 100644 --- a/src/logfile.cc +++ b/src/logfile.cc @@ -1,5 +1,5 @@ /* - * $Id: logfile.cc,v 1.6 2000/10/10 18:15:30 wessels Exp $ + * $Id: logfile.cc,v 1.7 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 50 Log file handling * AUTHOR: Duane Wessels @@ -41,7 +41,7 @@ logfileOpen(const char *path, size_t bufsz, int fatal_flag) { int fd; Logfile *lf; - fd = file_open(path, O_WRONLY | O_CREAT); + fd = file_open(path, O_WRONLY | O_CREAT | O_TEXT); if (DISK_ERROR == fd) { if (ENOENT == errno && fatal_flag) { fatalf("Cannot open '%s' because\n" @@ -108,7 +108,7 @@ logfileRotate(Logfile * lf) xrename(lf->path, to); } /* Reopen the log. It may have been renamed "manually" */ - lf->fd = file_open(lf->path, O_WRONLY | O_CREAT); + lf->fd = file_open(lf->path, O_WRONLY | O_CREAT | O_TEXT); if (DISK_ERROR == lf->fd && lf->flags.fatal) { debug(50, 1) ("logfileRotate: %s: %s\n", lf->path, xstrerror()); fatalf("Cannot open %s: %s", lf->path, xstrerror()); diff --git a/src/main.cc b/src/main.cc index ccf195b660..8ff720c773 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.326 2001/01/01 16:24:39 hno Exp $ + * $Id: main.cc,v 1.327 2001/01/04 03:42:34 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -845,7 +845,7 @@ watch_child(char *argv[]) syslog(LOG_ALERT, "setsid failed: %s", xstrerror()); closelog(); #ifdef TIOCNOTTY - if ((i = open("/dev/tty", O_RDWR)) >= 0) { + if ((i = open("/dev/tty", O_RDWR | O_TEXT)) >= 0) { ioctl(i, TIOCNOTTY, NULL); close(i); } @@ -858,7 +858,7 @@ watch_child(char *argv[]) * 1.1.3. execvp had a bit overflow error in a loop.. */ /* Connect stdio to /dev/null in daemon mode */ - nullfd = open("/dev/null", O_RDWR); + nullfd = open("/dev/null", O_RDWR | O_TEXT); dup2(nullfd, 0); if (opt_debug_stderr < 0) { dup2(nullfd, 1); diff --git a/src/mime.cc b/src/mime.cc index 2a6840c4b4..c50387569b 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -1,6 +1,6 @@ /* - * $Id: mime.cc,v 1.97 2001/01/01 16:24:39 hno Exp $ + * $Id: mime.cc,v 1.98 2001/01/04 03:42:35 wessels Exp $ * * DEBUG: section 25 MIME Parsing * AUTHOR: Harvest Derived @@ -297,6 +297,9 @@ mimeInit(char *filename) debug(50, 1) ("mimeInit: %s: %s\n", filename, xstrerror()); return; } +#if defined (_SQUID_CYGWIN_) + setmode(fileno(fp), O_TEXT); +#endif mimeFreeMemory(); while (fgets(buf, BUFSIZ, fp)) { if ((t = strchr(buf, '#'))) @@ -406,7 +409,7 @@ mimeLoadIconFile(const char *icon) if (storeGetPublic(url, METHOD_GET)) return; snprintf(path, MAXPATHLEN, "%s/%s", Config.icons.directory, icon); - fd = file_open(path, O_RDONLY); + fd = file_open(path, O_RDONLY | O_BINARY); if (fd < 0) { debug(25, 0) ("mimeLoadIconFile: %s: %s\n", path, xstrerror()); return; diff --git a/src/net_db.cc b/src/net_db.cc index c65d80b792..13d5929ee5 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -1,6 +1,6 @@ /* - * $Id: net_db.cc,v 1.153 2000/11/13 23:30:26 wessels Exp $ + * $Id: net_db.cc,v 1.154 2001/01/04 03:42:35 wessels Exp $ * * DEBUG: section 38 Network Measurement Database * AUTHOR: Duane Wessels @@ -435,7 +435,7 @@ netdbReloadState(void) * Solaris bugs, its a bad idea. fopen can fail if more than * 256 FDs are open. */ - fd = file_open(path, O_RDONLY); + fd = file_open(path, O_RDONLY | O_TEXT); if (fd < 0) return; if (fstat(fd, &sb) < 0) diff --git a/src/send-announce.cc b/src/send-announce.cc index 1317386681..e67ef7f04a 100644 --- a/src/send-announce.cc +++ b/src/send-announce.cc @@ -1,6 +1,6 @@ /* - * $Id: send-announce.cc,v 1.58 2000/03/06 16:23:34 wessels Exp $ + * $Id: send-announce.cc,v 1.59 2001/01/04 03:42:35 wessels Exp $ * * DEBUG: section 27 Cache Announcer * AUTHOR: Duane Wessels @@ -88,7 +88,7 @@ send_announce(const ipcache_addrs * ia, void *junk) strcat(sndbuf, tbuf); l = strlen(sndbuf); if ((file = Config.Announce.file) != NULL) { - fd = file_open(file, O_RDONLY); + fd = file_open(file, O_RDONLY | O_TEXT); if (fd > -1 && (n = read(fd, sndbuf + l, BUFSIZ - l - 1)) > 0) { fd_bytes(fd, n, FD_READ); l += n; diff --git a/src/squid.h b/src/squid.h index 46b75dabb9..761500e31e 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.203 2000/08/07 23:01:18 wessels Exp $ + * $Id: squid.h,v 1.204 2001/01/04 03:42:35 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -191,6 +191,9 @@ #if HAVE_LIMITS_H #include #endif +#if defined(_SQUID_CYGWIN_) +#include +#endif #if HAVE_DIRENT_H #include diff --git a/src/tools.cc b/src/tools.cc index e232ac3063..f08689b333 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.201 2000/12/31 23:53:08 wessels Exp $ + * $Id: tools.cc,v 1.202 2001/01/04 03:42:35 wessels Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -578,7 +578,7 @@ writePidFile(void) return; enter_suid(); old_umask = umask(022); - fd = file_open(f, O_WRONLY | O_CREAT | O_TRUNC); + fd = file_open(f, O_WRONLY | O_CREAT | O_TRUNC | O_TEXT); umask(old_umask); leave_suid(); if (fd < 0) { @@ -955,6 +955,9 @@ parseEtcHosts(void) Config.etcHostsPath, xstrerror()); return; } +#if defined(_SQUID_CYGWIN_) + setmode(fileno(fp), O_TEXT); +#endif while (fgets(buf, 1024, fp)) { /* for each line */ wordlist *hosts = NULL; if (buf[0] == '#') /* MS-windows likes to add comments */