commit 3770625993b114caaeb7a03c22326f42d55eb532
parent 74ff0e3e4cc89d484a9c98aeda1b2e2380e64091
Author: finwo <finwo@pm.me>
Date: Sat, 3 Jan 2026 19:12:56 +0100
1.16
Diffstat:
18 files changed, 102 insertions(+), 91 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,6 +1,11 @@
ChangeLog for Crossroads
------------------------------------------------------------------------------
+1.16 [KK 2006-11-01] New development version. Usage text updated to
+ point to http://crossroads.e-tunity.com. Flag -s
+ implemented. Small bugfix in 'restart' action.
+ [KK 2006-11-28] Promoted to next stable version.
+
1.15 [KK 2006-10-23] Speedup in the handling of chunked HTTP message
transfer. Furthermore, chunked messages are treated as
single-shot actions (see RFC2616, liberally explained by yours
diff --git a/doc/crossroads.html b/doc/crossroads.html
@@ -1,12 +1,12 @@
<a name="defs.yo"></a><html><head>
-<title>Crossroads 1.15</title>
+<title>Crossroads 1.16</title>
<link rel="stylesheet" type="text/css" href="http://www.e-tunity.com/css/yodl.css">
<link rel="stylesheet" type="text/css" href="http://www.e-tunity.com/css/yodl.css">
<link rev="made" href="mailto:info@e-tunity.com">
</head>
<body>
<hr>
-<h1>Crossroads 1.15</h1>
+<h1>Crossroads 1.16</h1>
<h2>Karel Kubat</h2>
<h2>e-tunity</h2><h2>2005, 2006, ff.</h2>
diff --git a/doc/crossroads.man b/doc/crossroads.man
@@ -1,6 +1,6 @@
-.TH "Crossroads 1\&.15" "2005, 2006, ff\&."
+.TH "Crossroads 1\&.16" "2005, 2006, ff\&."
.PP
-.SH "Crossroads 1\&.15"
+.SH "Crossroads 1\&.16"
.SH "Karel Kubat"
.SH "e-tunity"
.SH "2005, 2006, ff\&."
diff --git a/doc/crossroads.pdf b/doc/crossroads.pdf
Binary files differ.
diff --git a/etc/Makefile.def b/etc/Makefile.def
@@ -3,7 +3,7 @@
# Versioning. This defines the overall version ID and must match the topmost
# entry in the ChangeLog.
-VER = 1.15
+VER = 1.16
# Default config
DEFAULT_CONF = /etc/crossroads.conf
diff --git a/src/configtest.c b/src/configtest.c
@@ -1,6 +1,7 @@
#include "crossroads.h"
-void configtest (int ac, char **av) {
+int configtest (int ac, char **av) {
/* If we got this far, after reading the config: */
printf ("Configuration '%s' OK.\n", config_file);
+ return (1);
}
diff --git a/src/createcommandlinespace.c b/src/createcommandlinespace.c
@@ -0,0 +1,32 @@
+#include "crossroads.h"
+
+void create_commandline_space () {
+ char **argv;
+ int i;
+
+ /* Here's a dirty hack for Linux systems. We're going to get
+ * daemonized (unless -f was given) and we'll want to change the
+ * program name as it appears in the ps list.
+ * So we re-exec ourselves with a dummy -i flag that creates
+ * space on the commanedline.
+ */
+# if SET_PROC_TITLE_BY_ARGV == 1
+ if (! iflag_present) {
+ argv = xmalloc ( (org_argc + 2) * sizeof(char*));
+
+ argv[0] = org_argv[0];
+ argv[1] = "-ixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+ argv[org_argc + 1] = 0;
+
+ for (i = 1; i < org_argc; i++)
+ argv[i + 1] = org_argv[i];
+ argv[org_argc + 1] = 0;
+
+ execv (argv[0], argv);
+ execvp (argv[0], argv);
+ error ("Failed to re-exec program: %s",
+ strerror(errno));
+ }
+# endif
+}
diff --git a/src/crossroads.h b/src/crossroads.h
@@ -240,6 +240,7 @@ EXTERN int relevant_sigs[]; /* relevant signals */
EXTERN int semid; /* semaphore ID */
EXTERN Service *service; /* service descriptions */
EXTERN Servicereport *servicereport; /* reporter in shared mem */
+EXTERN int sloppyportbind; /* -s flag present */
EXTERN unsigned char *srbuf; /* server socket input buffer */
EXTERN unsigned srbufpos, srbufmax; /* .. position & bytes */
EXTERN char *state_to_string_map[]; /* backend states as strings */
@@ -255,7 +256,8 @@ extern int backend_available (void);
extern int backend_connect (void);
extern void choose_backend (void);
extern void copysockets (int clientsock, int serversock);
-extern void configtest (int ac, char **av);
+extern int configtest (int ac, char **av);
+extern void create_commandline_space (void);
extern void decr_client_count (void);
extern void dealloc_reporter (Service *s);
extern void error (char const *fmt, ...);
@@ -306,22 +308,22 @@ extern unsigned char *net_bufread (int sock, unsigned maxbytes,
unsigned *nreadp, int is_client);
extern int net_write (int sock, unsigned char const *buf, unsigned len,
int is_client);
-extern void restart (int ac, char **av);
+extern int restart (int ac, char **av);
extern void runservice (void);
-extern void sample_conf (int ac, char **av);
-extern void serve (int ac, char **av);
+extern int sample_conf (int ac, char **av);
+extern int serve (int ac, char **av);
extern void set_program_title (char const *fmt, ...);
-extern void show_services (int ac, char **av);
-extern void show_status (int ac, char **av);
+extern int show_services (int ac, char **av);
+extern int show_status (int ac, char **av);
extern char *stage_to_string (Programstage stage);
extern char *state_to_string (Backendavail avail);
extern Backendavail string_to_state (char const *str);
-extern void stop_daemon (int ac, char **av);
+extern int stop_daemon (int ac, char **av);
extern char *str_printf (char const *fmt, ...);
extern char *str_vprintf (char const *fmt, va_list args);
extern void sysrun (char const *cmd);
extern void tcpserve (int sock);
-extern void tell_service (int ac, char **av);
+extern int tell_service (int ac, char **av);
extern void thruputlog (unsigned char const *buf, int len, CopyDirection dir);
extern void trafficlog (unsigned char const *buf, int len, CopyDirection dir);
extern void unlock_reporter (void);
diff --git a/src/main.c b/src/main.c
@@ -28,7 +28,7 @@ typedef struct {
char *arg; /* cmdline argument */
int narg; /* required remaining args */
int needconf; /* configuration file required? */
- void (*handler)(int ac, char **av); /* action handler */
+ int (*handler)(int ac, char **av); /* action handler */
} Handler;
int main (int argc, char **argv) {
@@ -51,7 +51,7 @@ int main (int argc, char **argv) {
/* Parse options. */
config_file = DEFAULT_CONF;
- while ( (opt = getopt (argc, argv, "?c:fhvi:Val:")) > 0 )
+ while ( (opt = getopt (argc, argv, "?c:fhvi:Val:s")) > 0 )
switch (opt) {
case 'a':
log_activity++;
@@ -95,6 +95,9 @@ int main (int argc, char **argv) {
usage();
}
break;
+ case 's':
+ sloppyportbind++;
+ break;
case 'V':
puts (VER);
exit (0);
@@ -124,7 +127,8 @@ int main (int argc, char **argv) {
yyparse();
fclose (yyin);
}
- handler[i].handler (argc - optind, argv + optind + 1);
+ if (!handler[i].handler (argc - optind, argv + optind + 1))
+ error ("'%s' failed", argv[optind]);
return (0);
}
}
diff --git a/src/restart.c b/src/restart.c
@@ -1,36 +1,17 @@
#include "crossroads.h"
-void restart (int ac, char **av) {
- char *cmd = 0;
- int i, ret;
-
+int restart (int ac, char **av) {
+
+ create_commandline_space();
+
/* First run the 'stop' action. */
- for (i = 0; i < org_argc - 1; i++) {
- cmd = xstrcat (cmd, org_argv[i]);
- cmd = xstrcat (cmd, " ");
- }
- cmd = xstrcat (cmd, "stop");
+ if (!stop_daemon (ac, av))
+ error ("Daemon stop failed, restart failure");
- msg ("Restart: stopping using '%s'", cmd);
- if ( (ret = system (cmd)) )
- warning ("Failed to stop services (cmd: %s).\n"
- "Attempting to start services, "
- "but Crossroads may be unstable!\n",
- cmd);
+ /* Now run 'start' */
+ if (!serve (ac, av))
+ error ("Daemon start failed, restart failure");
- /* Now run the 'start' action */
- org_argv[org_argc - 1] = "start";
- free (cmd);
- cmd = 0;
- for (i = 0; i < org_argc; i++) {
- cmd = xstrcat (cmd, org_argv[i]);
- if (i < org_argc - 1)
- cmd = xstrcat (cmd, " ");
- }
- msg ("Restart: starting using '%s'", cmd);
-
- // execvp (org_argv[0], org_argv);
- if ( (ret = system (cmd)) )
- error ("Failed to start services (cmd: %s).\n"
- "Crossroads is not running, fix by hand!");
+ /* All ok.. */
+ return (1);
}
diff --git a/src/runservice.c b/src/runservice.c
@@ -59,6 +59,10 @@ void runservice () {
/* Create the socket, bind to port. */
if ( (listen_sock = make_socket (activeservice->port,
activeservice->bind)) < 0 ) {
+ if (!sloppyportbind)
+ error ("Service %s: failed to listen to port %d: %s",
+ activeservice->name, activeservice->port,
+ strerror(errno));
warning ("Service %s: "
"listening socket creation failed.. will retry",
activeservice->name);
diff --git a/src/sampleconf.c b/src/sampleconf.c
@@ -1,7 +1,7 @@
#include "crossroads.h"
#include "sampleconf.h"
-void sample_conf (int ac, char **av) {
+int sample_conf (int ac, char **av) {
printf ("%s\n", SAMPLECONF);
- exit (0);
+ return (1);
}
diff --git a/src/serve.c b/src/serve.c
@@ -1,40 +1,16 @@
#include "crossroads.h"
-void serve (int ac, char **av) {
+int serve (int ac, char **av) {
int i;
msg ("Starting services");
- /* Here's a dirty hack for Linux systems. We're going to get
- * daemonized (unless -f was given) and we'll want to change the
- * program name as it appears in the ps list.
- * So we re-exec ourselves with a dummy -i flag that creates
- * space on the commanedline.
- */
-# if SET_PROC_TITLE_BY_ARGV == 1
- if (! iflag_present) {
- char **argv = xmalloc ( (org_argc + 2) * sizeof(char*));
- int i;
-
- argv[0] = org_argv[0];
- argv[1] = "-ixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
- argv[org_argc + 1] = 0;
-
- for (i = 1; i < org_argc; i++)
- argv[i + 1] = org_argv[i];
- argv[org_argc + 1] = 0;
-
- execv (argv[0], argv);
- execvp (argv[0], argv);
- error ("Failed to re-exec program: %s",
- strerror(errno));
- }
-# endif
+ create_commandline_space();
for (i = 0; i < nservice; i++) {
/* Start the service. */
activeservice = service + i;
runservice ();
}
+ return (1);
}
diff --git a/src/showservices.c b/src/showservices.c
@@ -1,6 +1,6 @@
#include "crossroads.h"
-void show_services (int ac, char **av) {
+int show_services (int ac, char **av) {
int i, j;
for (i = 0; i < nservice; i++) {
@@ -12,6 +12,5 @@ void show_services (int ac, char **av) {
service[i].backend[j].server,
service[i].backend[j].port);
}
-
- exit (nservice == 0);
+ return (1);
}
diff --git a/src/showstatus.c b/src/showstatus.c
@@ -42,7 +42,7 @@ static char *bytestr (unsigned long long nbytes) {
return (buf);
}
-void show_status (int ac, char **av) {
+int show_status (int ac, char **av) {
int i, j;
for (i = 0; i < nservice; i++) {
@@ -80,4 +80,6 @@ void show_status (int ac, char **av) {
error ("Failure releasing reporter memory: %s",
strerror(errno));
}
+
+ return (1);
}
diff --git a/src/stopdaemon.c b/src/stopdaemon.c
@@ -1,7 +1,7 @@
#include "crossroads.h"
-void stop_daemon (int ac, char **av) {
- int i, ret = 0;
+int stop_daemon (int ac, char **av) {
+ int i, result = 0;
for (i = 0; i < nservice; i++) {
alloc_reporter (service + i, 0);
@@ -10,19 +10,21 @@ void stop_daemon (int ac, char **av) {
if (kill (servicereport->pid, SIGINT)) {
warning ("Failed to stop service %s (%s)",
service[i].name, strerror(errno));
- ret++;
- }
- if (servicereport->rev_pid && kill (servicereport->rev_pid, SIGINT)) {
+ result++;
+ } else if (servicereport->rev_pid &&
+ kill (servicereport->rev_pid, SIGINT)) {
warning ("Failed to stop wakeup handler of service %s (%s)",
service[i].name, strerror(errno));
- ret++;
+ result++;
}
/* Note: We run the deallocator of shmem here anyeay, though the
- * signalled listener does it too.. just to make sure..
+ * signalled listener does it too.. just to make sure.. We do this
+ * only if above kills have succeeded.
*/
- dealloc_reporter (service + i);
+ if (!result)
+ dealloc_reporter (service + i);
}
- exit (ret);
+ return (1);
}
diff --git a/src/tellservice.c b/src/tellservice.c
@@ -1,6 +1,6 @@
#include "crossroads.h"
-void tell_service (int ac, char **av) {
+int tell_service (int ac, char **av) {
Service *target_service = 0;
int target_backend = -1, i;
Backendavail avail;
@@ -31,5 +31,6 @@ void tell_service (int ac, char **av) {
servicereport->backendstate[target_backend].avail = avail;
msg ("Marked backend %s of service %s as %s.",
av[1], av[0], av[2]);
+ return (1);
}
diff --git a/src/usage.txt b/src/usage.txt
@@ -1,7 +1,7 @@
This is Crossroads %s, a load balancer and fail-over utility for TCP.
Copyright (c) Karel Kubat / e-tunity 2005/2006 ff. All rights reserved.
For information, contact <info@e-tunity.com> or see <http://www.e-tunity.com>.
-For distributions and updates, visit <http://public.e-tunity.com>.
+For distributions and updates, visit <http://crossroads.e-tunity.com>.
Usage:
** Controlling the daemon: **
@@ -25,6 +25,8 @@ Supported flags:
-l FAC: Specifies the openlog(3) facility to use when
logging. Default is LOG_DAEMON. Allowed values are 0..7
for LOG_LOCAL0 to LOG_LOCAL7.
+ -s: Sloppy binding to the listen port of each service (if the port
+ is busy, Crossroads will wait for it to become free).
-v: Enables verbosity upon startup. Other verbosity (services
and back ends) is controlled in the configuration.
-V: Shows the version ID and stops.