From: Florian Krohm Date: Mon, 29 Dec 2014 22:07:35 +0000 (+0000) Subject: Add a command line option to allow the user to provide an upper bound X-Git-Tag: svn/VALGRIND_3_11_0~748 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d509d8aff0e3e3ccb2c557d10c555c5ccb9770be;p=thirdparty%2Fvalgrind.git Add a command line option to allow the user to provide an upper bound for the number of connected processes. This is still lame but better than asking her to recompile. Part of fixing BZ #337869. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14838 --- diff --git a/auxprogs/valgrind-listener.c b/auxprogs/valgrind-listener.c index 15b23abd94..8da7a288b4 100644 --- a/auxprogs/valgrind-listener.c +++ b/auxprogs/valgrind-listener.c @@ -57,9 +57,13 @@ /*---------------------------------------------------------------*/ -/* The maximum allowable number concurrent connections. */ -#define M_CONNECTIONS 50 +/* The default allowable number of concurrent connections. */ +#define M_CONNECTIONS_DEFAULT 50 +/* The maximum allowable number of concurrent connections. */ +#define M_CONNECTIONS_MAX 5000 +/* The maximum allowable number of concurrent connections. */ +unsigned M_CONNECTIONS = 0; /*---------------------------------------------------------------*/ @@ -98,8 +102,8 @@ static void my_assert_fail ( const char* expr, const char* file, int line, const /* holds the fds for connections; zero if slot not in use. */ int conn_count = 0; -int conn_fd[M_CONNECTIONS]; -struct pollfd conn_pollfd[M_CONNECTIONS]; +int *conn_fd; +struct pollfd *conn_pollfd; static void set_nonblocking ( int sd ) @@ -167,8 +171,8 @@ static void snooze ( void ) } -/* returns 0 if invalid, else port # */ -static int atoi_portno ( const char* str ) +/* returns 0 if negative, or > BOUND or invalid characters were found */ +static int atoi_with_bound ( const char* str, int bound ) { int n = 0; while (1) { @@ -178,9 +182,17 @@ static int atoi_portno ( const char* str ) return 0; n = 10*n + (int)(*str - '0'); str++; - if (n >= 65536) + if (n >= bound) return 0; } + return n; +} + +/* returns 0 if invalid, else port # */ +static int atoi_portno ( const char* str ) +{ + int n = atoi_with_bound(str, 65536); + if (n < 1024) return 0; return n; @@ -193,18 +205,22 @@ static void usage ( void ) "\n" "usage is:\n" "\n" - " valgrind-listener [--exit-at-zero|-e] [port-number]\n" + " valgrind-listener [--exit-at-zero|-e] [--max-connect=INT] [port-number]\n" "\n" " where --exit-at-zero or -e causes the listener to exit\n" " when the number of connections falls back to zero\n" " (the default is to keep listening forever)\n" "\n" + " --max-connect=INT can be used to increase the maximum\n" + " number of connected processes (default = %d).\n" + " INT must be positive and less than %d.\n" + "\n" " port-number is the default port on which to listen for\n" " connections. It must be between 1024 and 65535.\n" " Current default is %d.\n" "\n" , - VG_CLO_DEFAULT_LOGPORT + M_CONNECTIONS_DEFAULT, M_CONNECTIONS_MAX, VG_CLO_DEFAULT_LOGPORT ); exit(1); } @@ -247,6 +263,11 @@ int main (int argc, char** argv) || 0==strcmp(argv[i], "-e")) { exit_when_zero = 1; } + else if (0 == strncmp(argv[i], "--max-connect=", 14)) { + M_CONNECTIONS = atoi_with_bound(strchr(argv[i], '=') + 1, 5000); + if (M_CONNECTIONS <= 0 || M_CONNECTIONS > M_CONNECTIONS_MAX) + usage(); + } else if (atoi_portno(argv[i]) > 0) { port = atoi_portno(argv[i]); @@ -255,6 +276,16 @@ int main (int argc, char** argv) usage(); } + if (M_CONNECTIONS == 0) // nothing specified on command line + M_CONNECTIONS = M_CONNECTIONS_DEFAULT; + + conn_fd = malloc(M_CONNECTIONS * sizeof conn_fd[0]); + conn_pollfd = malloc(M_CONNECTIONS * sizeof conn_pollfd[0]); + if (conn_fd == NULL || conn_pollfd == NULL) { + fprintf(stderr, "Memory allocation failed; cannot continue.\n"); + exit(1); + } + banner("started"); signal(SIGINT, sigint_handler); @@ -326,9 +357,11 @@ int main (int argc, char** argv) break; if (i >= M_CONNECTIONS) { - fprintf(stderr, "Too many concurrent connections. " - "Increase M_CONNECTIONS and recompile.\n"); - panic("main -- too many concurrent connections"); + fprintf(stderr, "\n\nMore than %d concurrent connections.\n" + "Restart the listener giving --max-connect=INT on the\n" + "commandline to increase the limit.\n\n", + M_CONNECTIONS); + exit(1); } conn_fd[i] = new_sd; diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml index f11e9b166b..3ea5635e6c 100644 --- a/docs/xml/manual-core.xml +++ b/docs/xml/manual-core.xml @@ -236,7 +236,7 @@ re-run, passing the option to Valgrind. A second of each line of output it prints the current number of active connections in round brackets. - valgrind-listener accepts two + valgrind-listener accepts three command-line options: @@ -248,6 +248,16 @@ re-run, passing the option to Valgrind. A second send it Control-C. + + + + By default, the listener can connect to up to 50 processes. + Occasionally, that number is too small. Use this option to + provide a different limit. E.g. + --max-connext=100. + + +