|
From: <sv...@va...> - 2014-12-29 22:07:54
|
Author: florian
Date: Mon Dec 29 22:07:35 2014
New Revision: 14838
Log:
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.
Modified:
trunk/auxprogs/valgrind-listener.c
trunk/docs/xml/manual-core.xml
Modified: trunk/auxprogs/valgrind-listener.c
==============================================================================
--- trunk/auxprogs/valgrind-listener.c (original)
+++ trunk/auxprogs/valgrind-listener.c Mon Dec 29 22:07:35 2014
@@ -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 @@
/* 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 @@
}
-/* 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 @@
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 @@
"\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 @@
|| 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 @@
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 @@
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;
Modified: trunk/docs/xml/manual-core.xml
==============================================================================
--- trunk/docs/xml/manual-core.xml (original)
+++ trunk/docs/xml/manual-core.xml Mon Dec 29 22:07:35 2014
@@ -236,7 +236,7 @@
of each line of output it prints the current number of active
connections in round brackets.</para>
- <para><computeroutput>valgrind-listener</computeroutput> accepts two
+ <para><computeroutput>valgrind-listener</computeroutput> accepts three
command-line options:</para>
<!-- start of xi:include in the manpage -->
<variablelist id="listener.opts.list">
@@ -249,6 +249,16 @@
</listitem>
</varlistentry>
<varlistentry>
+ <term><option>--max-connext=INTEGER</option></term>
+ <listitem>
+ <para>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.
+ <computeroutput>--max-connext=100</computeroutput>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>portnumber</option></term>
<listitem>
<para>Changes the port it listens on from the default (1500).
|