-/* $Id: cache_cf.cc,v 1.6 1996/03/27 18:15:40 wessels Exp $ */
+/* $Id: cache_cf.cc,v 1.7 1996/03/27 18:50:20 wessels Exp $ */
#include "squid.h"
} Accel;
char *appendDomain;
char *debugOptions;
+ char *pidFilename;
} Config;
#define DefaultMemMaxSize (16 << 20) /* 16 MB */
#define DefaultEffectiveGroup (char *)NULL /* default NONE */
#define DefaultAppendDomain (char *)NULL /* default NONE */
-#define DefaultDebugOptions "ALL,1"
+#define DefaultDebugOptions "ALL,1" /* All sections at level 1 */
#define DefaultAccelHost (char *)NULL /* default NONE */
#define DefaultAccelPrefix (char *)NULL /* default NONE */
#define DefaultAccelPort 0 /* default off */
#define DefaultNeighborTimeout 2 /* 2 seconds */
#define DefaultStallDelay 3 /* 3 seconds */
#define DefaultSingleParentBypass 0 /* default off */
+#define DefaultPidFilename (char *)NULL /* default NONE */
+
+extern char *config_file;
stoplist *http_stoplist = NULL;
stoplist *gopher_stoplist = NULL;
static void configSetFactoryDefaults();
static void configDoConfigure();
-extern int getMaxFD();
-extern void fatal _PARAMS((char *));
-extern void neighbors_cf_add _PARAMS((char *, char *, int, int, int));
-extern int neighbors_cf_domain _PARAMS((char *, char *));
-
void self_destruct(in_string)
char *in_string;
{
Config.debugOptions = xstrdup(token);
}
+static void parsePidFilenameLine(line_in)
+ char *line_in;
+{
+ char *token;
+ token = strtok(NULL, w_space);
+ safe_free(Config.pidFilename);
+ if (token == (char *) NULL)
+ self_destruct(line_in);
+ Config.pidFilename = xstrdup(token);
+}
+
int parseConfigFile(file_name)
char *file_name;
{
else if (!strcmp(token, "debug_options"))
parseDebugOptionsLine(line_in);
+ else if (!strcmp(token, "pid_filename"))
+ parsePidFilenameLine(line_in);
+
/* If unknown, treat as a comment line */
else {
/* EMPTY */ ;
{
return Config.Http.maxObjSize;
}
-
int getHttpTTL()
{
return Config.Http.defaultTtl;
}
-
int getGopherMax()
{
return Config.Gopher.maxObjSize;
}
-
int getGopherTTL()
{
return Config.Gopher.defaultTtl;
}
-
int getWAISMax()
{
return Config.Wais.maxObjSize;
{
return Config.Wais.relayPort;
}
-
int getFtpMax()
{
return Config.Ftp.maxObjSize;
}
-
int getFtpTTL()
{
return Config.Ftp.defaultTtl;
}
-
int getNegativeTTL()
{
return Config.negativeTtl;
}
-
int getCacheMemMax()
{
return Config.Mem.maxSize;
}
-
int getCacheMemHighWaterMark()
{
return Config.Mem.highWatherMark;
}
-
int getCacheMemLowWaterMark()
{
return Config.Mem.lowWaterMark;
}
-
double getCacheHotVmFactor()
{
return Config.hotVmFactor;
}
-
int getCacheSwapHighWaterMark()
{
return Config.Swap.highWatherMark;
}
-
int getCacheSwapLowWaterMark()
{
return Config.Swap.lowWaterMark;
}
-
int getCacheSwapMax()
{
return Config.Swap.maxSize;
}
-
int setCacheSwapMax(size)
int size;
{
Config.Swap.maxSize = size;
return Config.Swap.maxSize;
}
-
int getReadTimeout()
{
return Config.readTimeout;
}
-
int getClientLifetime()
{
return Config.lifetimeDefault;
}
-
int getConnectTimeout()
{
return Config.connectTimeout;
}
-
int getCleanRate()
{
return Config.cleanRate;
}
-
int getSourcePing()
{
return Config.sourcePing;
}
-
int getDnsChildren()
{
return Config.dnsChildren;
}
-
int getQuickAbort()
{
return Config.quickAbort;
}
-
char *getAccelPrefix()
{
return Config.Accel.prefix;
{
return Config.effectiveGroup;
}
+char *getPidFilename()
+{
+ return Config.pidFilename;
+}
+
int setAsciiPortNum(p)
int p;
{
Config.Accel.prefix = safe_xstrdup(DefaultAccelPrefix);
Config.Accel.port = DefaultAccelPort;
Config.Accel.withProxy = DefaultAccelWithProxy;
-
+ Config.pidFilename = safe_xstrdup(DefaultPidFilename);
}
static void configDoConfigure()
-/* $Id: debug.cc,v 1.6 1996/03/27 18:16:28 wessels Exp $ */
+/* $Id: debug.cc,v 1.7 1996/03/27 18:50:22 wessels Exp $ */
#include "squid.h"
int _db_line = 0;
int syslog_enable = 0;
-int stderr_enable = 0;
FILE *debug_log = NULL;
static char *debug_log_file = NULL;
static time_t last_cached_curtime = 0;
syslog(LOG_ERR, tmpbuf);
}
#endif /* HAVE_SYSLOG */
+
/* write to log file */
vfprintf(debug_log, f, args);
if (unbuffered_logs)
fflush(debug_log);
- /* if requested, dump it to stderr also */
- if (stderr_enable) {
- vfprintf(stderr, f, args);
- fflush(stderr);
- }
va_end(args);
}
debugLevels[i] = l;
}
-void _db_init(prefix, logfile)
- char *prefix;
+static void debugOpenLog(logfile)
+ char *logfile;
+{
+ if (logfile == NULL) {
+ debug_log = stderr;
+ return;
+ }
+ if (debug_log_file)
+ free(debug_log_file);
+ debug_log_file = xstrdup(logfile); /* keep a static copy */
+ debug_log = fopen(logfile, "a+");
+ if (!debug_log) {
+ fprintf(stderr, "WARNING: Cannot write log file: %s\n", logfile);
+ perror(logfile);
+ fprintf(stderr, " messages will be sent to 'stderr'.\n");
+ fflush(stderr);
+ debug_log = stderr;
+ }
+}
+
+void _db_init(logfile)
char *logfile;
{
int i;
}
xfree(p);
}
- /* open error logging file */
- if (logfile != NULL) {
- if (debug_log_file)
- free(debug_log_file);
- debug_log_file = strdup(logfile); /* keep a static copy */
- debug_log = fopen(logfile, "a+");
- if (!debug_log) {
- fprintf(stderr, "WARNING: Cannot write log file: %s\n", logfile);
- perror(logfile);
- fprintf(stderr, " messages will be sent to 'stderr'.\n");
- fflush(stderr);
- debug_log = stderr;
- /* avoid reduntancy */
- stderr_enable = 0;
- }
- } else {
- fprintf(stderr, "WARNING: No log file specified?\n");
- fprintf(stderr, " messages will be sent to 'stderr'.\n");
- fflush(stderr);
- debug_log = stderr;
- stderr_enable = 0;
- }
+
+ debugOpenLog(logfile);
#if HAVE_SYSLOG
if (syslog_enable)
}
-/* gack! would be nice to use _db_init() instead */
void _db_rotate_log()
{
int i;
}
/* Close and reopen the log. It may have been renamed "manually"
* before HUP'ing us. */
- fclose(debug_log);
- debug_log = fopen(debug_log_file, "a+");
- if (debug_log == NULL) {
- fprintf(stderr, "WARNING: Cannot write log file: %s\n",
- debug_log_file);
- perror(debug_log_file);
- fprintf(stderr, " messages will be sent to 'stderr'.\n");
- fflush(stderr);
- debug_log = stderr;
- /* avoid redundancy */
- stderr_enable = 0;
+ if (debug_log != stderr) {
+ fclose(debug_log);
+ debugOpenLog(debug_log_file);
}
}
-/* $Id: main.cc,v 1.10 1996/03/27 18:15:49 wessels Exp $ */
+/* $Id: main.cc,v 1.11 1996/03/27 18:50:23 wessels Exp $ */
#include "squid.h"
static int binaryPortNumOverride = 0;
static int udpPortNumOverride = 0;
+
+static void usage()
+{
+ fprintf(stderr, "\
+Usage: cached [-Rsehvz] [-f config-file] [-[apu] port]\n\
+ -h Print help message.\n\
+ -s Enable logging to syslog.\n\
+ -v Print version.\n\
+ -z Zap disk storage -- deletes all objects in disk cache.\n\
+ -C Do not catch fatal signals.\n\
+ -D Disable initial DNS tests.\n\
+ -R Do not set REUSEADDR on port.\n\
+ -f file Use given config-file instead of\n\
+ $HARVEST_HOME/lib/cached.conf.\n\
+ -a port Specify ASCII port number (default: %d).\n\
+ -u port Specify UDP port number (default: %d).\n",
+ CACHE_HTTP_PORT, CACHE_ICP_PORT);
+ exit(1);
+}
+
int main(argc, argv)
int argc;
char **argv;
int n; /* # of GC'd objects */
time_t last_maintain = 0;
-#ifdef WRITE_PID_FILE
- FILE *pid_fp = NULL;
- static char pidfn[MAXPATHLEN];
-#endif
-
cached_starttime = cached_curtime = time((time_t *) NULL);
failure_notify = fatal_dump;
/*init comm module */
comm_init();
-#ifdef DAEMON
- if (daemonize()) {
- fprintf(stderr, "Error: couldn't create daemon process\n");
- exit(0);
- }
- /* signal( SIGHUP, restart ); *//* restart if/when proc dies */
-#endif /* DAEMON */
-
/* we have to init fdstat here. */
fdstat_init(PREOPEN_FD);
fdstat_open(0, LOG);
}
/* enable syslog by default */
- syslog_enable = 1;
- /* disable stderr debug printout by default */
- stderr_enable = 0;
+ syslog_enable = 0;
/* preinit for debug module */
debug_log = stderr;
hash_init(0);
- while ((c = getopt(argc, argv, "vCDRVseif:a:p:u:d:m:zh?")) != -1)
+ while ((c = getopt(argc, argv, "vCDRVsif:a:p:u:m:zh?")) != -1)
switch (c) {
case 'v':
printf("Harvest Cache: Version %s\n", SQUID_VERSION);
case 's':
syslog_enable = 0;
break;
- case 'e':
- stderr_enable = 1;
break;
case 'R':
do_reuse = 0;
case '?':
case 'h':
default:
- printf("\
-Usage: cached [-Rsehvz] [-f config-file] [-[apu] port]\n\
- -e Print messages to stderr.\n\
- -h Print help message.\n\
- -s Disable syslog output.\n\
- -v Print version.\n\
- -z Zap disk storage -- deletes all objects in disk cache.\n\
- -C Do not catch fatal signals.\n\
- -D Disable initial DNS tests.\n\
- -R Do not set REUSEADDR on port.\n\
- -f file Use given config-file instead of\n\
- $HARVEST_HOME/lib/cached.conf.\n\
- -a port Specify ASCII port number (default: %d).\n\
- -u port Specify UDP port number (default: %d).\n",
- CACHE_HTTP_PORT, CACHE_ICP_PORT);
-
- exit(1);
+ usage();
break;
}
if (udpPortNumOverride > 0)
setUdpPortNum(udpPortNumOverride);
- _db_init("cached", getCacheLogFile());
+ _db_init(getCacheLogFile());
fdstat_open(fileno(debug_log), LOG);
fd_note(fileno(debug_log), getCacheLogFile());
stat_init(&CacheInfo, getAccessLogFile());
storeInit();
stmemInit();
-
-#ifdef WRITE_PID_FILE
- /* Try to write the pid to cached.pid in the same directory as
- * cached.conf */
- memset(pidfn, '\0', MAXPATHLEN);
- strcpy(pidfn, config_file);
- if ((s = strrchr(pidfn, '/')) != NULL)
- strcpy(s, "/cached.pid");
- else
- strcpy(pidfn, "/usr/local/harvest/lib/cached.pid");
- pid_fp = fopen(pidfn, "w");
- if (pid_fp != NULL) {
- fprintf(pid_fp, "%d\n", (int) getpid());
- fclose(pid_fp);
- }
-#endif
+ writePidFile();
/* after this point we want to see the mallinfo() output */
do_mallinfo = 1;
-/* $Id: tools.cc,v 1.10 1996/03/27 18:15:55 wessels Exp $ */
+/* $Id: tools.cc,v 1.11 1996/03/27 18:50:24 wessels Exp $ */
#include "squid.h"
}
setuid(pwd->pw_uid);
}
+
+void writePidFile()
+{
+ FILE *pid_fp = NULL;
+ char *f = NULL;
+
+ if ((f = getPidFilename()) == NULL)
+ return;
+ if ((pid_fp = fopen(f, "w")) == NULL) {
+ debug(0,0,"WARNING: Could not write pid file\n");
+ debug(0,0," %s: %s\n", f, xstrerror());
+ return;
+ }
+ fprintf(pid_fp, "%d\n", (int) getpid());
+ fclose(pid_fp);
+}