From: Amos Jeffries Date: Thu, 19 Aug 2010 03:14:16 +0000 (-0600) Subject: revert unwanted changes slipped into rev10756. X-Git-Tag: take1~365 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c060699c240d3619640c333ef1e760a72d780030;p=thirdparty%2Fsquid.git revert unwanted changes slipped into rev10756. --- diff --git a/configure.in b/configure.in index d05efe5f1b..591c7f7a73 100644 --- a/configure.in +++ b/configure.in @@ -2125,7 +2125,6 @@ AC_CHECK_HEADERS( \ regex.h \ sched.h \ security/pam_appl.h \ - siginfo.h \ signal.h \ sstream \ stdarg.h \ @@ -2146,7 +2145,7 @@ AC_CHECK_HEADERS( \ sys/md5.h \ sys/msg.h \ sys/resource.h \ - sys/select.h \ + sys/select.h\ sys/socket.h \ sys/stat.h \ sys/statvfs.h \ @@ -2918,7 +2917,6 @@ AC_REPLACE_FUNCS(\ initgroups \ getaddrinfo \ getnameinfo \ - psignal \ strerror \ strsep \ strtoll \ @@ -3240,7 +3238,6 @@ AC_CONFIG_FILES([\ helpers/url_rewrite/Makefile \ helpers/url_rewrite/fake/Makefile \ tools/Makefile - tools/purge/Makefile ]) AC_CONFIG_SUBDIRS(lib/libTrie) diff --git a/lib/Makefile.am b/lib/Makefile.am index a1fcf15c37..f474316568 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -46,7 +46,6 @@ EXTRA_libmiscutil_a_SOURCES = \ md5.c \ Profiler.c \ win32lib.c - libmiscutil_a_SOURCES = \ MemPool.cc \ MemPoolChunked.cc \ diff --git a/tools/Makefile.am b/tools/Makefile.am index 8d0d182347..5efe2628e1 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -11,7 +11,7 @@ AUTOMAKE_OPTIONS = subdir-objects ## we need our local files too (but avoid -I. at all costs) INCLUDES += -I$(srcdir) -SUBDIRS = purge +SUBDIRS = EXTRA_DIST = man_MANS = DISTCLEANFILES = diff --git a/tools/purge/Makefile b/tools/purge/Makefile new file mode 100644 index 0000000000..a9cbf8ef18 --- /dev/null +++ b/tools/purge/Makefile @@ -0,0 +1,181 @@ +# +# 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 ) diff --git a/tools/purge/convert.cc b/tools/purge/convert.cc index 64238121ce..189d896b91 100644 --- a/tools/purge/convert.cc +++ b/tools/purge/convert.cc @@ -57,6 +57,9 @@ #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 @@ -104,7 +107,7 @@ my_sock_fd2a( int fd, SockAddress buffer, bool peer ) // 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 ) diff --git a/tools/purge/copyout.cc b/tools/purge/copyout.cc index 53419c80fc..525094e746 100644 --- a/tools/purge/copyout.cc +++ b/tools/purge/copyout.cc @@ -42,23 +42,25 @@ #pragma implementation #endif -#include "config.h" -#include "copyout.hh" - -//#include -//#include +#include +#include #include #include #include #include #include #include -#include +#include #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. diff --git a/tools/purge/hexd.c b/tools/purge/hexd.c new file mode 100644 index 0000000000..af7f8ef666 --- /dev/null +++ b/tools/purge/hexd.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +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); +} + + diff --git a/tools/purge/hexd.cc b/tools/purge/hexd.cc deleted file mode 100644 index 1756067d1a..0000000000 --- a/tools/purge/hexd.cc +++ /dev/null @@ -1,93 +0,0 @@ -#include "config.h" - -#include -#include -#include -#include -#include -#include - -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(); -} diff --git a/tools/purge/purge.cc b/tools/purge/purge.cc index 0ba6fcdd9e..4031e933c4 100644 --- a/tools/purge/purge.cc +++ b/tools/purge/purge.cc @@ -95,19 +95,22 @@ // #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 +#include #include #include #include -//#include +#include #include -//#include +#include #include #include #include @@ -117,9 +120,9 @@ #include #include -#if HAVE_SIGINFO_H +#if defined(HAS_PSIGNAL) && !defined(LINUX) && !defined(FREEBSD) #include -#endif +#endif // HAS_PSIGNAL #include #include // TCP_NODELAY @@ -154,7 +157,8 @@ static bool verbose = false; 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$"; // ---------------------------------------------------------------------- @@ -169,7 +173,7 @@ struct REList { }; 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) ); @@ -631,13 +635,13 @@ parseCommandline( int argc, char* argv[], REList*& head, 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; @@ -842,7 +846,7 @@ main( int argc, char* argv[] ) { // 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 ); @@ -903,7 +907,7 @@ main( int argc, char* argv[] ) ::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 ) { @@ -929,7 +933,7 @@ main( int argc, char* argv[] ) // 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 ); diff --git a/tools/purge/signal.cc b/tools/purge/signal.cc index 5eb91e3df1..3f302d2657 100644 --- a/tools/purge/signal.cc +++ b/tools/purge/signal.cc @@ -49,17 +49,40 @@ #pragma implementation #endif -#include "config.h" -#include "signal.hh" - -//#include +#include #include #include #include #include #include #include -//#include +#include + +#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 ) @@ -115,10 +138,10 @@ sigChild( int signo ) 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)" : "", @@ -127,7 +150,7 @@ sigChild( int signo ) #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) ); diff --git a/tools/purge/signal.hh b/tools/purge/signal.hh index 73d1cdfadf..b923b740ce 100644 --- a/tools/purge/signal.hh +++ b/tools/purge/signal.hh @@ -47,16 +47,9 @@ // Initial revision // // - #ifndef _SIGNAL_HH #define _SIGNAL_HH -#include "config.h" - -#if HAVE_SIGNAL_H -#include -#endif - #if defined(__GNUC__) || defined(__GNUG__) #pragma interface #else @@ -84,6 +77,14 @@ extern "C" { 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 diff --git a/tools/purge/socket.cc b/tools/purge/socket.cc index 129e6d1c2d..033ffe7adb 100644 --- a/tools/purge/socket.cc +++ b/tools/purge/socket.cc @@ -60,6 +60,9 @@ #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 @@ -92,7 +95,7 @@ getSocketNoDelay( int sockfd ) // -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" ); diff --git a/tools/purge/squid-tlv.cc b/tools/purge/squid-tlv.cc index 29a53d1168..55fca05434 100644 --- a/tools/purge/squid-tlv.cc +++ b/tools/purge/squid-tlv.cc @@ -39,10 +39,12 @@ #pragma implementation #endif -#include "config.h" -//#include +#include #include "squid-tlv.hh" +static const char* RCS_ID = + "$Id$"; + SquidTLV::SquidTLV( SquidMetaType _type, size_t _size, void* _data ) :next(0),size(_size) {