crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

commit a597c987229349b08dad454f0bb599362e2602f7
parent 15a3b46e31c79be85ec1992e77c028558b2a3a94
Author: finwo <finwo@pm.me>
Date:   Sat,  3 Jan 2026 19:35:54 +0100

2.14

Diffstat:
MChangeLog | 5+++++
MMakefile | 2+-
Mxr/config/config | 8++++++--
Mxr/config/config1.cc | 1+
Mxr/config/parsecmdline.cc | 6+++++-
Mxr/etc/usage.txt | 6++++--
Mxr/sys/fdwrite.cc | 14++++++++++++++
Mxr/sys/str2parts.cc | 8--------
8 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +2.14 [KK 2008-09-30] +- Removed spurious debug message. +- Fixed usage info for buffer size flag (should be -B). +- Implemented flag -l (--log-traffic). + 2.13 [KK 2008-09-17] - Porting issues resolved for older MacOSX (10.3, 10.4) - Bugfix in XML emitting of web interface. Most browsers didn't even notice.. diff --git a/Makefile b/Makefile @@ -1,7 +1,7 @@ # Top-level Makefile for XR # ------------------------- -VER = 2.13 +VER = 2.14 BINDIR = /usr/sbin TAR = /tmp/crossroads-$(VER).tar.gz AUTHOR = Karel Kubat <karel@kubat.nl> diff --git a/xr/config/config b/xr/config/config @@ -1,5 +1,5 @@ -#ifndef _CMDLINE_ -#define _CMDLINE_ +#ifndef _CONFIG_ +#define _CONFIG_ #include "sys/sys" #include "backenddef/backenddef" @@ -71,6 +71,9 @@ public: void addserverheader (string const &s); void removeserverheader (unsigned i); void changeserverheader (unsigned i, string const &s); + + string dumpdir() const { return (dump_dir); } + void dumpdir (string s) { dump_dir = s; } unsigned nallow() const { return (allowlist.size()); } unsigned ndeny() const { return (denylist.size()); } @@ -130,6 +133,7 @@ private: static bool use_webinterface; static string webinterface_ip; static int webinterface_port; + static string dump_dir; }; extern Config config; diff --git a/xr/config/config1.cc b/xr/config/config1.cc @@ -28,6 +28,7 @@ int Config::ipstore_timeout; bool Config::use_webinterface = false; string Config::webinterface_ip; int Config::webinterface_port; +string Config::dump_dir; Config::Config () { } diff --git a/xr/config/parsecmdline.cc b/xr/config/parsecmdline.cc @@ -16,7 +16,7 @@ void Config::parsecmdline (int ac, char **av) { throw static_cast<Error>("Bad command line '") + cmdline + "'\n" + USAGE; -# define OPTSTRING "?a:A:B:b:c:Dd:fhH:m:M:nPp:Ss:t:T:vVW:w:xX" +# define OPTSTRING "?a:A:B:b:c:Dd:fhH:l:m:M:nPp:Ss:t:T:vVW:w:xX" # ifdef HAVE_GETOPT_LONG static struct option longopts[] = { { "allow-from", required_argument, 0, 'a' }, @@ -30,6 +30,7 @@ void Config::parsecmdline (int ac, char **av) { { "foreground", no_argument, 0, 'f' }, { "help", no_argument, 0, 'h' }, { "add-server-header", required_argument, 0, 'H' }, + { "log-traffic", required_argument, 0, 'l' }, { "max-connections", required_argument, 0, 'm' }, { "host-match", required_argument, 0, 'M' }, { "tryout", no_argument, 0, 'n' }, @@ -97,6 +98,9 @@ void Config::parsecmdline (int ac, char **av) { case 'H': addserverheader (optarg); break; + case 'l': + dumpdir (optarg); + break; case 'M': current_hostmatch = optarg; break; diff --git a/xr/etc/usage.txt b/xr/etc/usage.txt @@ -13,7 +13,7 @@ may not exist on your platform): At least one -b... must be given. Specifier MAX is optional: when given, defines the maximum connections for the back end. WEIGHT is optional: when given, specifies the weight (bigger means better server, default 1). - -b SIZE, --buffer-size SIZE + -B SIZE, --buffer-size SIZE Sets the network buffer size, default is 2048 (in bytes) -C, --close-sockets-fast Sockets are closed faster to avoid TIME_WAIT states. @@ -46,12 +46,14 @@ may not exist on your platform): "unavailable", <b0-connections> is the nr. of connections. The program must reply with a back end number (0..max) on stdout. -f, --foreground - Suppresses forking/threading, useful for debugging. Also suppresses + Suppresses forking/threading, only for debugging. Also suppresses wakeup (-w) and checkup (-c) threads. -h, -?, --help This text. -H HDR, --add-server-header HDR Inserts HDR into back end bound HTTP messages. + -l DIR, --log-traffic DIR + Log passing traffic with dumps in DIR. Only for debugging, very slow! -m MAX, --max-connections MAX Sets the maximum number of connections to the balancer. Default is 0, no maximum. diff --git a/xr/sys/fdwrite.cc b/xr/sys/fdwrite.cc @@ -9,6 +9,20 @@ void fdwrite (int fd, int timeout, char const *buf, unsigned buflen) { debugmsg (o.str()); } + // Log to dump directory if requested + if (config.dumpdir().length()) { + ostringstream of; + of << config.dumpdir() << "/" << pthread_self() << "." << fd; + FILE *f; + if ( (!(f = fopen (of.str().c_str(), "a"))) && + (!(f = fopen (of.str().c_str(), "w"))) ) + throw static_cast<Error>("Cannot write traffic log ") + + of.str() + ": " + strerror(errno); + fwrite (buf, 1, buflen, f); + fclose (f); + } + + // Send to the socket unsigned totwritten = 0; while (totwritten < buflen) { // Wait for the socket to become writeable. diff --git a/xr/sys/str2parts.cc b/xr/sys/str2parts.cc @@ -14,13 +14,5 @@ vector<string> str2parts (string const &s, char sep) { if (str.length() > 0) parts.push_back (str); - if (config.debug()) { - ostringstream o; - o << "String '" << s << "' split by '" << sep << "': "; - for (unsigned i = 0; i < parts.size(); i++) - o << " '" << parts[i] << "'"; - debugmsg (o.str() + "\n"); - } - return (parts); }