/*
- * $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
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);
/*
- * $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"
}
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);
}
/* 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());
}
fd_bytes(lf->fd, s, FD_WRITE);
if (s == len)
return;
+ if (!lf->flags.fatal)
+ return;
fatalf("logfileWrite: %s: %s\n", lf->path, xstrerror());
}
/*
- * $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
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,
(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));
/*
- * $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/
#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);
/*
- * $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)
debug(40, 1) ("Referer logging is disabled.\n");
return;
}
- logfileOpen(Config.Log.referer, 0);
+ logfileOpen(Config.Log.referer, 0, 1);
#endif
}
/*
- * $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
debug(20, 1) ("Store logging disabled\n");
return;
}
- storelog = logfileOpen(Config.Log.store, 0);
+ storelog = logfileOpen(Config.Log.store, 0, 1);
}
/*
- * $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/
char *buf;
size_t bufsz;
off_t offset;
+ struct {
+ unsigned int fatal:1;
+ } flags;
};
/*
- * $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>
debug(40, 1) ("User-Agent logging is disabled.\n");
return;
}
- logfileOpen(Config.Log.useragent, 0);
+ logfileOpen(Config.Log.useragent, 0, 1);
#endif
}