regex.h \
sched.h \
security/pam_appl.h \
- siginfo.h \
signal.h \
sstream \
stdarg.h \
sys/md5.h \
sys/msg.h \
sys/resource.h \
- sys/select.h \
+ sys/select.h\
sys/socket.h \
sys/stat.h \
sys/statvfs.h \
initgroups \
getaddrinfo \
getnameinfo \
- psignal \
strerror \
strsep \
strtoll \
helpers/url_rewrite/Makefile \
helpers/url_rewrite/fake/Makefile \
tools/Makefile
- tools/purge/Makefile
])
AC_CONFIG_SUBDIRS(lib/libTrie)
md5.c \
Profiler.c \
win32lib.c
-
libmiscutil_a_SOURCES = \
MemPool.cc \
MemPoolChunked.cc \
## we need our local files too (but avoid -I. at all costs)
INCLUDES += -I$(srcdir)
-SUBDIRS = purge
+SUBDIRS =
EXTRA_DIST =
man_MANS =
DISTCLEANFILES =
--- /dev/null
+#
+# Makefile
+#
+# The Makefile is divided into three sections, the "generic section", the
+# "host section" and the "rules section". The generics section defines
+# defaults which you should not change. Changes should solely be made to
+# the rules section.
+#
+# You will need to select several parameters befitting your compiler/system:
+#
+# -DHAS_BOOL - set, if your C++ compiler knows about the 'bool' type.
+# -DHAS_PSIGNAL - set, if your libc supports psignal(int,const char*).
+# -fno-exceptions - may not be recognized by all variants of g++
+# -ffor-scope - the new ANSI C++ scoping of for() variables is used...
+#
+# === [1] ==================================================== generics section
+#
+CXX = g++ -ffor-scope -DHAS_BOOL -DHAS_PSIGNAL
+CC = gcc
+LD = $(CC) # yes, I do mean gcc and not g++
+CXXFLAGS = # -pg -g # -fprofile-arcs -ftest-coverage
+SYSTEM = $(shell uname -s | tr '[a-z]' '[A-Z]' | tr -d '_ -/')
+CPU = $(shell uname -p)
+VERSION = $(shell uname -r)
+HOST = $(shell uname -n)
+MAJOR = $(firstword $(subst ., ,$(VERSION)))
+MINOR = $(strip $(word 2,$(subst ., ,$(VERSION))))
+LOADLIBES =
+SOCKLEN = int # default except for glibc2?
+
+# optimization levels - Do *not* use levels above -O1 with g++,
+# if -fprofile-arcs or -ftest-coverage is selected! Set to different
+# values in the host specific section below.
+#
+# - OPT_NORM for normal level optimization, O2 is a good choice.
+#
+OPT_NORM = -O2
+
+# electric fence library, for test purposes only (helps w/ memory leaks)
+# (developers only)
+EFENCE = -L/usr/local/lib -lefence
+
+#
+# === [2] ======================================================= hosts section
+#
+
+ifeq (SUNOS,${SYSTEM})
+ifeq (5,${MAJOR})
+# use these for the SUN CC compiler (for STL, see below or above)
+# You must define this for Solaris 2.x: CXXFLAGS = -DSOLARIS
+CC = cc
+#CXX = CC -DHAS_BOOL -DHAS_PSIGNAL -DHAS_MUTABLE
+#CXXFLAGS = -DSOLARIS '-library=%none,Cstd,Crun'
+#CXXFLAGS += -dalign -ftrap=%none -fsimple -xlibmil
+#OPT_NORM = -xtarget=ultra2 -xO4
+#EXTRALIB += -lnsl -lsocket
+#LD = CC
+#
+## g++ settings for Solaris on Ultra Sparcs (comment out all of above):
+CXXFLAGS += -DSOLARIS # -ggdb
+OPT_NORM = -O2 # -mcpu=supersparc
+LD = $(CC)
+##
+#EXTRALIB += -lnsl -lsocket -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
+else
+# old SunOS 4.1.x, not supported!
+CXXFLAGS += -DSUN
+endif
+endif
+
+ifeq (IRIX64,${SYSTEM})
+# The regular 64bit Irix stuff is just too slow, use n32!
+SYSTEM := IRIX
+endif
+
+ifeq (FREEBSD,${SYSTEM})
+SOCKLEN = socklen_t
+endif
+
+ifeq (IRIX,${SYSTEM})
+CXX = CC -n32 -mips3 -r4000 -DEFAULT:abi=n32:isa=mips3:proc=r4k
+CXX += -LANG:ansi-for-init-scope=on -LANG:bool=on
+CXX += -LANG:exceptions=off -LANG:explicit=off -LANG:wchar_t=off
+CXX += -LANG:mutable=on -LANG:namespaces=on -LANG:std
+CC = cc -n32 -mips3 -r4000
+CXXFLAGS = -woff 1174 -LANG:exceptions=off -DHAS_BOOL -DHAS_PSIGNAL
+LD = $(CXX)
+OPT_NORM = -O3 -IPA -LNO:opt=1
+# for g++
+#CXXFLAGS += -mips3 -mcpu=r4000
+endif
+
+ifeq (AIX,${SYSTEM})
+ifeq (,${MINOR})
+MINOR := ${MAJOR}
+MAJOR = 4
+endif
+CXX = xlC -UHAS_BOOL -UHAS_PSIGNAL
+CC = xlc
+CXXFLAGS = -qtune=pwr # -qdbxextra -g
+#CXX = g++ -ffor-scope -DHAS_BOOL -UHAS_PSIGNAL
+SOCKLEN = size_t
+LD = $(CXX)
+endif
+
+ifeq (LINUX,${SYSTEM})
+# determine highest version of all installed libc's.
+LIBCVER = $(shell /bin/ls /lib/libc.so.? | \
+ awk -F'.' '{ if (m<$$3) m=$$3;} END { print m} ')
+ifeq (6,${LIBCVER})
+SOCKLEN = socklen_t
+endif
+CXXFLAGS += -DHAS_PSIGNAL -DLIBCVERSION=$(LIBCVER) -pipe # -Wall -pedantic
+OPT_NORM = -O2
+# if your g++ balks (e.g. SuSE still uses 2.7.2.3)
+#CXXFLAGS += -DHAS_PSIGNAL -DLIBCVERSION=$(LIBCVER) -m486
+LD = $(CC)
+EXTRALIB = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
+endif
+
+#
+# === [3] ======================================================= rules section
+# There is no need to change things below this line.
+CXXFLAGS += -D${SYSTEM} -DMAJOR=${MAJOR} -DMINOR=${MINOR} -DSOCKLEN=${SOCKLEN}
+CFLAGS = $(CXXFLAGS)
+LDFLAGS += $(OPT_NORM)
+
+%.o:%.cc
+ $(CXX) $(CXXFLAGS) $(OPT_NORM) -c $< -o $@
+
+OBJS = convert.o socket.o signal.o squid-tlv.o copyout.o conffile.o
+SRCS = $(OBJS:.o=.cc)
+HDRS = $(OBJS:.o=.hh)
+FILES = $(SRCS) $(HDRS) Makefile purge.cc hexd.c
+DIST = $(addprefix purge/,$(FILES) README)
+
+all: purge
+
+purge: $(OBJS) purge.o
+ $(LD) $(OPT_NORM) $(LDFLAGS) $^ -o $@ $(LOADLIBES) $(EXTRALIB)
+hexd: hexd.o
+ $(CC) $(OPT_NORM) $(LDFLAGS) $^ -o $@ $(LOADLIBES)
+#
+# object file rules, generated with "g++ -MM -E *.cc"
+#
+purge.o: purge.cc $(HDRS)
+ $(CXX) $(CXXFLAGS) $(OPT_NORM) -c $< -o $@
+convert.o: convert.cc convert.hh
+conffile.o: conffile.cc conffile.hh
+signal.o: signal.cc signal.hh
+socket.o: socket.cc socket.hh convert.hh
+squid-tlv.o: squid-tlv.cc squid-tlv.hh
+copyout.o: copyout.cc copyout.hh
+hexd.o: hexd.c
+
+clean:
+ $(RM) *.o
+ if [ "${SYSTEM}" = "IRIX" ]; then rm -rf ii_files; fi
+ if [ "${SYSTEM}" = "SUNOS" ]; then rm -rf Templates.DB; fi
+ if [ "${SYSTEM}" = "SUNOS" ]; then rm -rf SunWS_cache; fi
+
+distclean: clean
+ $(RM) purge hexd
+
+realclean: distclean
+clobber: distclean
+
+co-all: $(FILES)
+ echo all checked out
+co-all-lock:
+ co -l $(FILES)
+ci-all:
+ for i in $(FILES); do \
+ test -w $$i && ci $$i; \
+ rm -f $$i; \
+ done
+
+dist: distclean co-all
+ ( cd .. ; gtar cvzf purge-`date +"%Y%m%d"`-src.tar.gz $(DIST) )
+tar: distclean ci-all
+ ( cd .. ; gtar cvzf purge-`date +"%Y%m%d"`-all.tar.gz purge )
#define SA struct sockaddr
#endif
+static const char* RCS_ID =
+ "$Id$";
+
const char*
my_inet_ntoa( const struct in_addr& a, HostAddress output )
// purpose: thread-safely convert IPv4 address -> ASCII representation
// Refer to errno in case of error (usually unconnected fd...)
{
struct sockaddr_in socket;
- socklen_t len = sizeof(socket);
+ SOCKLEN len = sizeof(socket);
if ( (peer ? getpeername( fd, (SA*) &socket, &len ) :
getsockname( fd, (SA*) &socket, &len )) == -1 )
#pragma implementation
#endif
-#include "config.h"
-#include "copyout.hh"
-
-//#include <assert.h>
-//#include <sys/types.h>
+#include <assert.h>
+#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
-#include <sys/mman.h>
+#include <sys/mman.h>
#ifndef MAP_FILE
#define MAP_FILE 0
#endif // MAP_FILE
+#include "copyout.hh"
+
+static const char* RCS_ID =
+ "$Id$";
+
int
assert_copydir( const char* copydir )
// purpose: check, if copydir is a directory and that we can write into it.
--- /dev/null
+#include <ctype.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+unsigned char
+xlate( unsigned char ch )
+{
+ return (isprint(ch & 0x7f) ? ch : '.');
+}
+
+typedef struct {
+ int fd, rsize, cursor;
+ size_t bufsize;
+ unsigned char* buffer;
+} InputByByte;
+
+int
+in_open( InputByByte* this, const char* fn, size_t size )
+{
+ if ( (this->fd = open( fn, O_RDONLY )) == -1 ) return -1;
+ if ( (this->buffer=(unsigned char*) malloc(size)) == 0 ) {
+ close(this->fd);
+ return -1;
+ }
+ this->bufsize = size;
+ this->rsize = this->cursor = 0;
+ return 0;
+}
+
+int
+in_get( InputByByte* this )
+/*
+ * purpose: read next character
+ * returns: 0..255 as valid character, -1 for error, -2 for EOF
+ */
+{
+ if ( this->cursor >= this->rsize ) {
+ do {
+ this->rsize = read( this->fd, this->buffer, this->bufsize );
+ } while ( this->rsize == -1 && errno == EINTR );
+ if ( this->rsize > 0 ) this->cursor = 0;
+ else return ((-2) - this->rsize);
+ }
+
+ return this->buffer[this->cursor++];
+}
+
+int
+in_close( InputByByte* this )
+{
+ free((void*) this->buffer);
+ return close(this->fd);
+}
+
+int
+main( int argc, char* argv[] )
+{
+ int ch, i;
+ unsigned line = 0;
+ InputByByte in;
+ char b2[20];
+
+ if ( argc != 2 ) {
+ fprintf( stderr, "Usage: %s filename\n", argv[0] );
+ return 1;
+ }
+
+ if ( in_open(&in,argv[1],32768) == -1 ) {
+ perror( "open" );
+ return 1;
+ }
+
+ for ( ch = in_get(&in); ch >= 0; ) {
+ printf( "%08X: ", line );
+ memset( b2, 0, sizeof(b2) );
+ for ( i=0; i < 16 && ch >= 0; i++ ) {
+ printf( "%02X%c", ch, ((i==7) ? '-' : ' ' ) );
+ b2[i] = xlate(ch);
+ ch = in_get(&in);
+ }
+ line += i;
+ for ( ; i<16; i++ ) fputs(" ",stdout);
+ printf( " %s\n", b2 );
+ }
+
+ return in_close(&in);
+}
+
+
+++ /dev/null
-#include "config.h"
-
-#include <stdio.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-class InputByByte
-{
-public:
- int open(const char* fn, const size_t size);
- int get();
- int close();
-
-private:
- int fd, rsize, cursor;
- size_t bufsize;
- unsigned char* buffer;
-};
-
-int
-InputByByte::open(const char* fn, const size_t size )
-{
- if ( (fd = open( fn, O_RDONLY )) == -1 ) return -1;
- if ( (buffer=(unsigned char*) malloc(size)) == 0 ) {
- ::close(fd);
- return -1;
- }
- bufsize = size;
- rsize = cursor = 0;
- return 0;
-}
-
-int
-InputByByte::get()
-/*
- * purpose: read next character
- * returns: 0..255 as valid character, -1 for error, -2 for EOF
- */
-{
- if ( cursor >= rsize ) {
- do {
- rsize = read(fd, buffer, bufsize );
- } while ( rsize == -1 && errno == EINTR );
- if ( rsize > 0 ) cursor = 0;
- else return ((-2) - rsize);
- }
-
- return buffer[cursor++];
-}
-
-int
-InputByByte::close()
-{
- free((void*) buffer);
- return close(fd);
-}
-
-int
-main( int argc, char* argv[] )
-{
- int ch, i;
- unsigned line = 0;
- InputByByte in;
- char b2[20];
-
- if ( argc != 2 ) {
- fprintf( stderr, "Usage: %s filename\n", argv[0] );
- return 1;
- }
-
- if ( in.open(argv[1],32768) == -1 ) {
- perror( "open" );
- return 1;
- }
-
- for ( ch = in.get(); ch >= 0; ) {
- printf( "%08X: ", line );
- memset( b2, 0, sizeof(b2) );
- for ( i=0; i < 16 && ch >= 0; i++ ) {
- printf( "%02X%c", ch, ((i==7) ? '-' : ' ' ) );
- b2[i] = (isprint(ch & 0x7f) ? ch : '.');
- ch = in.get();
- }
- line += i;
- for ( ; i<16; i++ ) fputs(" ",stdout);
- printf( " %s\n", b2 );
- }
-
- return in.close();
-}
//
#if defined(__GNUC__) || defined(__GNUG__)
#pragma implementation
+#else
+#ifndef HAS_BOOL
+#define HAS_BOOL
+typedef int bool;
+#define false 0
+#define true 1
+#endif
#endif
-#include "config.h"
-// for xstrdup
-#include "util.h"
-
-//#include <assert.h>
+#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <dirent.h>
-//#include <ctype.h>
+#include <ctype.h>
#include <string.h>
-//#include <sys/types.h>
+#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
-#if HAVE_SIGINFO_H
+#if defined(HAS_PSIGNAL) && !defined(LINUX) && !defined(FREEBSD)
#include <siginfo.h>
-#endif
+#endif // HAS_PSIGNAL
#include <netinet/in.h>
#include <netinet/tcp.h> // TCP_NODELAY
static bool envelope = false;
static bool no_fork = false;
static const char* programname = 0;
-static const char* RCS_ID = "$Id$";
+static const char* RCS_ID =
+ "$Id$";
// ----------------------------------------------------------------------
};
REList::REList( const char* what, bool doCase )
- :next(0),data(xstrdup(what))
+ :next(0),data(strdup(what))
{
int result = regcomp( &rexp, what,
REG_EXTENDED | REG_NOSUB | (doCase ? 0 : REG_ICASE) );
case 'C':
if ( optarg && *optarg ) {
if ( copydir ) free( (void*) copydir );
- assert( (copydir = xstrdup(optarg)) );
+ assert( (copydir = strdup(optarg)) );
}
break;
case 'c':
if ( optarg && *optarg ) {
if ( *conffile ) free((void*) conffile );
- assert( (conffile = xstrdup(optarg)) );
+ assert( (conffile = strdup(optarg)) );
}
break;
{
// setup variables
REList* list = 0;
- char* conffile = xstrdup( DEFAULT_SQUID_CONF );
+ char* conffile = strdup( DEFAULT_SQUID_CONF );
serverPort = htons(DEFAULTPORT);
if ( convertHostname(DEFAULTHOST,serverHost) == -1 ) {
fprintf( stderr, "unable to resolve host %s!\n", DEFAULTHOST );
::iamalive = false;
}
- for ( size_t i=0; i < cdv.size(); ++i ) {
+ for ( int i=0; i < cdv.size(); ++i ) {
if ( getpid() == getpgrp() ) {
// only parent == group leader may fork off new processes
if ( (child[i]=fork()) < 0 ) {
// collect the garbase
pid_t temp;
int status;
- for ( size_t i=0; i < cdv.size(); ++i ) {
+ for ( int i=0; i < cdv.size(); ++i ) {
while ( (temp=waitpid( (pid_t)-1, &status, 0 )) == -1 )
if ( errno == EINTR ) continue;
if ( ::debug ) printf( "collected child %d\n", (int) temp );
#pragma implementation
#endif
-#include "config.h"
-#include "signal.hh"
-
-//#include <sys/types.h>
+#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
-//#include <signal.h>
+#include <signal.h>
+
+#include "signal.hh"
+
+static const char* RCS_ID =
+ "$Id$";
+
+#ifndef HAS_PSIGNAL
+#ifdef AIX
+extern const char* const sys_siglist[];
+#define _sys_nsig 64
+#define _sys_siglist sys_siglist
+#endif // AIX
+
+void
+psignal( int sig, const char* msg )
+// purpose: print message, colon, space, signal name and LF.
+// paramtr: sig (IN): signal number
+// msg (IN): message to prepend
+{
+ if ( msg && *msg ) fprintf( stderr, "%s: ", msg );
+ if ( sig > 0 && sig < _sys_nsig )
+ fprintf( stderr, "%s\n", _sys_siglist[sig] );
+ else
+ fputs( "(unknown)\n", stderr );
+}
+#endif // !HAS_PSIGNAL
SigFunc*
Signal( int signo, SigFunc* newhandler, bool doInterrupt )
int saveerr = errno;
while ( (pid = waitpid( -1, &status, WNOHANG )) > 0 ) {
if ( WIFEXITED(status) ) {
- snprintf( line, 128, "child (pid=%ld) reaped, status %d\n%c",
+ sprintf( line, "child (pid=%ld) reaped, status %d\n%c",
(long) pid, WEXITSTATUS(status), 0 );
} else if ( WIFSIGNALED(status) ) {
- snprintf( line, 128, "child (pid=%ld) died on signal %d%s\n%c",
+ sprintf( line, "child (pid=%ld) died on signal %d%s\n%c",
(long) pid, WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? " (core generated)" : "",
#endif
0 );
} else {
- snprintf( line, 128, "detected dead child (pid=%ld), status %d\n%c",
+ sprintf( line, "detected dead child (pid=%ld), status %d\n%c",
(long) pid, status, 0 );
}
write( STDERR_FILENO, line, strlen(line) );
// Initial revision
//
//
-
#ifndef _SIGNAL_HH
#define _SIGNAL_HH
-#include "config.h"
-
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-
#if defined(__GNUC__) || defined(__GNUG__)
#pragma interface
#else
typedef SIGRETTYPE SigFunc( SIGPARAM );
}
+#ifndef HAS_PSIGNAL
+void
+psignal( int sig, const char* msg );
+ // purpose: print message, colon, space, signal name and LF.
+ // paramtr: sig (IN): signal number
+ // msg (IN): message to prepend
+#endif // ! HAS_PSIGNAL
+
SigFunc*
Signal( int signo, SigFunc* newhandler, bool doInterrupt );
// purpose: install reliable signals
#include "convert.hh"
+static const char* RCS_ID =
+ "$Id$";
+
int
setSocketBuffers( int sockfd, int size )
// purpose: set socket buffers for both directions to the specified size
// -1, if an error occurred (e.g. datagram socket)
{
int delay = 0;
- socklen_t len = sizeof(delay);
+ SOCKLEN len = sizeof(delay);
if ( getsockopt( sockfd, IPPROTO_TCP, TCP_NODELAY,
(char*) &delay, &len ) == -1 ) {
perror( "# getsockopt( TCP_NODELAY ) failed" );
#pragma implementation
#endif
-#include "config.h"
-//#include <assert.h>
+#include <assert.h>
#include "squid-tlv.hh"
+static const char* RCS_ID =
+ "$Id$";
+
SquidTLV::SquidTLV( SquidMetaType _type, size_t _size, void* _data )
:next(0),size(_size)
{