]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
DW:
authorwessels <>
Wed, 11 Oct 2000 00:15:30 +0000 (00:15 +0000)
committerwessels <>
Wed, 11 Oct 2000 00:15:30 +0000 (00:15 +0000)
 - My change to eliminate stdio from net_db.c sucked.  It leaked memory,
   and it had awkward buffer offset junk.  Its probably better to
   use the logfile.c code, which unfortunately requires a change
   to logfileOpen().  Previously the logfile code exited with
   a fatal message if there was an error opening or writing the
   file.  For netdb we don't care that much, so I added a "fatal"
   flag to logfileOpen().

src/access_log.cc
src/logfile.cc
src/net_db.cc
src/protos.h
src/referer.cc
src/store_log.cc
src/structs.h
src/useragent.cc

index 69809a3597eacf66311976115216da3f6a2fe1be..bc995936c8b5e8ed25bf8c7291b9b5918f5c86db 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: access_log.cc,v 1.58 2000/06/06 19:34:31 hno Exp $
+ * $Id: access_log.cc,v 1.59 2000/10/10 18:15:30 wessels Exp $
  *
  * DEBUG: section 46    Access Log
  * AUTHOR: Duane Wessels
@@ -329,7 +329,7 @@ void
 accessLogInit(void)
 {
     assert(sizeof(log_tags) == (LOG_TYPE_MAX + 1) * sizeof(char *));
-    logfile = logfileOpen(Config.Log.access, MAX_URL << 1);
+    logfile = logfileOpen(Config.Log.access, MAX_URL << 1, 1);
     LogfileStatus = LOG_ENABLE;
 #if HEADERS_LOG
     headerslog = logfileOpen("/usr/local/squid/logs/headers.log", 512);
index 04d8a6b93603037196396decfd11c1ba3fbbb1d0..707771d1315db9f59e762dd98deb5c09d191ad8a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: logfile.cc,v 1.5 2000/07/12 16:15:15 wessels Exp $
+ * $Id: logfile.cc,v 1.6 2000/10/10 18:15:30 wessels Exp $
  *
  * DEBUG: section 50    Log file handling
  * AUTHOR: Duane Wessels
 static void logfileWriteWrapper(Logfile * lf, const void *buf, size_t len);
 
 Logfile *
-logfileOpen(const char *path, size_t bufsz)
+logfileOpen(const char *path, size_t bufsz, int fatal_flag)
 {
     int fd;
     Logfile *lf;
     fd = file_open(path, O_WRONLY | O_CREAT);
     if (DISK_ERROR == fd) {
-       if (ENOENT == errno) {
+       if (ENOENT == errno && fatal_flag) {
            fatalf("Cannot open '%s' because\n"
                "\tthe parent directory does not exist.\n"
                "\tPlease create the directory.\n", path);
-       } else if (EACCES == errno) {
+       } else if (EACCES == errno && fatal_flag) {
            fatalf("Cannot open '%s' for writing.\n"
                "\tThe parent directory must be writeable by the\n"
                "\tuser '%s', which is the cache_effective_user\n"
@@ -59,6 +59,8 @@ logfileOpen(const char *path, size_t bufsz)
     }
     lf = xcalloc(1, sizeof(*lf));
     lf->fd = fd;
+    if (fatal_flag)
+       lf->flags.fatal = 1;
     xstrncpy(lf->path, path, MAXPATHLEN);
     if (bufsz > 0) {
        lf->buf = xmalloc(bufsz);
@@ -107,7 +109,7 @@ logfileRotate(Logfile * lf)
     }
     /* Reopen the log.  It may have been renamed "manually" */
     lf->fd = file_open(lf->path, O_WRONLY | O_CREAT);
-    if (DISK_ERROR == lf->fd) {
+    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());
     }
@@ -179,5 +181,7 @@ logfileWriteWrapper(Logfile * lf, const void *buf, size_t len)
     fd_bytes(lf->fd, s, FD_WRITE);
     if (s == len)
        return;
+    if (!lf->flags.fatal)
+       return;
     fatalf("logfileWrite: %s: %s\n", lf->path, xstrerror());
 }
index 2516688ec448f161c6dca09c4bc529bbf5209e75..9cd8ad9bfe2b2d74e2e07e6899a052d73627ab5b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: net_db.cc,v 1.148 2000/10/06 05:42:46 wessels Exp $
+ * $Id: net_db.cc,v 1.149 2000/10/10 18:15:30 wessels Exp $
  *
  * DEBUG: section 38    Network Measurement Database
  * AUTHOR: Duane Wessels
@@ -368,34 +368,27 @@ static void
 netdbSaveState(void *foo)
 {
     LOCAL_ARRAY(char, path, SQUID_MAXPATHLEN);
-    int fd;
+    Logfile *lf;
     netdbEntry *n;
     net_db_name *x;
     struct timeval start = current_time;
     int count = 0;
-    size_t wl = 4096;
-    char *wbuf = xmalloc(wl);
-    off_t wo = 0;
     snprintf(path, SQUID_MAXPATHLEN, "%s/netdb_state", storeSwapDir(0));
     /*
      * This was nicer when we were using stdio, but thanks to
      * Solaris bugs, its a bad idea.  fopen can fail if more than
      * 256 FDs are open.
      */
-    fd = file_open(path, O_WRONLY | O_CREAT | O_TRUNC);
-    if (fd < 0) {
+    lf = logfileOpen(path, 4096, 0);
+    if (NULL == lf) {
        debug(50, 1) ("netdbSaveState: %s: %s\n", path, xstrerror());
        return;
     }
     hash_first(addr_table);
     while ((n = (netdbEntry *) hash_next(addr_table))) {
-#define RBUF_SZ 4096
-       char rbuf[RBUF_SZ];
-       off_t ro;
        if (n->pings_recv == 0)
            continue;
-       ro = 0;
-       ro += snprintf(rbuf, RBUF_SZ, "%s %d %d %10.5f %10.5f %d %d",
+       logfilePrintf(lf, "%s %d %d %10.5f %10.5f %d %d",
            n->network,
            n->pings_sent,
            n->pings_recv,
@@ -404,24 +397,12 @@ netdbSaveState(void *foo)
            (int) n->next_ping_time,
            (int) n->last_use_time);
        for (x = n->hosts; x; x = x->next)
-           ro += snprintf(rbuf + ro, RBUF_SZ - ro, " %s", x->name);
-       ro += snprintf(rbuf + ro, RBUF_SZ - ro, "\n");
-       assert(ro <= RBUF_SZ);
-       while (ro + wo > wl) {
-           char *t;
-           t = wbuf;
-           wl <<= 1;
-           wbuf = xmalloc(wl);
-           xmemcpy(wbuf, t, wo);
-           xfree(t);
-       }
-       xmemcpy(wbuf + wo, rbuf, ro);
-       wo += ro;
+           logfilePrintf(lf, " %s", x->name);
+       logfilePrintf(lf, "\n");
        count++;
 #undef RBUF_SZ
     }
-    write(fd, wbuf, wo);
-    file_close(fd);
+    logfileClose(lf);
     getCurrentTime();
     debug(38, 1) ("NETDB state saved; %d entries, %d msec\n",
        count, tvSubMsec(start, current_time));
index df3449075724a9dbe492d2280671c16946fba8b6..2e172ac4f57fe5928becc1384eddffba7ec99e18 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.381 2000/10/10 02:10:42 wessels Exp $
+ * $Id: protos.h,v 1.382 2000/10/10 18:15:30 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -1179,7 +1179,7 @@ extern void *leakFreeFL(void *, const char *, int);
 #endif
 
 /* logfile.c */
-extern Logfile *logfileOpen(const char *path, size_t bufsz);
+extern Logfile *logfileOpen(const char *path, size_t bufsz, int);
 extern void logfileClose(Logfile * lf);
 extern void logfileRotate(Logfile * lf);
 extern void logfileWrite(Logfile * lf, void *buf, size_t len);
index d401b61e8a249e9439722a86febedd5861896a36..96b0a9daac6c273c04babd28c68e6d353eb04cb6 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: referer.cc,v 1.1 2000/07/13 06:13:43 wessels Exp $
+ * $Id: referer.cc,v 1.2 2000/10/10 18:15:30 wessels Exp $
  *
  * DEBUG: section 40    User-Agent and Referer logging
  * AUTHOR: Joe Ramey <ramey@csc.ti.com> (useragent)
@@ -49,7 +49,7 @@ refererOpenLog(void)
        debug(40, 1) ("Referer logging is disabled.\n");
        return;
     }
-    logfileOpen(Config.Log.referer, 0);
+    logfileOpen(Config.Log.referer, 0, 1);
 #endif
 }
 
index e29e46f9f517fed53991708d8cd8dbc70e348907..da476217c1900ccefcee525c41253d0851e1fc14 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_log.cc,v 1.18 2000/07/21 06:06:22 wessels Exp $
+ * $Id: store_log.cc,v 1.19 2000/10/10 18:15:30 wessels Exp $
  *
  * DEBUG: section 20    Storage Manager Logging Functions
  * AUTHOR: Duane Wessels
@@ -119,5 +119,5 @@ storeLogOpen(void)
        debug(20, 1) ("Store logging disabled\n");
        return;
     }
-    storelog = logfileOpen(Config.Log.store, 0);
+    storelog = logfileOpen(Config.Log.store, 0, 1);
 }
index 01aa4612d0e72597eebed7d188d6f180d6e2c3b8..7f792b49738d7a842d640fd7c0287ab6169359ba 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.354 2000/10/04 15:32:14 wessels Exp $
+ * $Id: structs.h,v 1.355 2000/10/10 18:15:30 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -1889,4 +1889,7 @@ struct _Logfile {
     char *buf;
     size_t bufsz;
     off_t offset;
+    struct {
+       unsigned int fatal:1;
+    } flags;
 };
index 3f978dd6902988b2a7d92e3a62e38ec757399e81..956b1ec1c02223ade5c566ea01f8264a4242b1fc 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: useragent.cc,v 1.21 2000/06/21 20:34:37 hno Exp $
+ * $Id: useragent.cc,v 1.22 2000/10/10 18:15:30 wessels Exp $
  *
  * DEBUG: section 40    User-Agent logging
  * AUTHOR: Joe Ramey <ramey@csc.ti.com>
@@ -48,7 +48,7 @@ useragentOpenLog(void)
        debug(40, 1) ("User-Agent logging is disabled.\n");
        return;
     }
-    logfileOpen(Config.Log.useragent, 0);
+    logfileOpen(Config.Log.useragent, 0, 1);
 #endif
 }