From: Michael Meffie Date: Mon, 13 Jan 2014 20:28:17 +0000 (-0500) Subject: xstat: use ephemeral ports for xstat_fs_test and scout X-Git-Tag: openafs-stable-1_8_0pre1~841 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=cda5e665ebee3da5615dba71b7a11ffff1229c6d xstat: use ephemeral ports for xstat_fs_test and scout Instead of trying to bind to port 7101, and then retrying if the port is in already in use, let the os find an available port for scout and xstat_fs_test. This fixes a bug where scout and xstat_fs_test do not call rx_Finalize() before retrying rx_Init() with a different port number, causing the program to crash later when more than one copy of xstat_fs_test and/or scout are running at the same time. Change-Id: I64e4916b03b1cae20ef36bb1ae293885962677e7 Reviewed-on: http://gerrit.openafs.org/10707 Tested-by: BuildBot Reviewed-by: Marc Dionne Reviewed-by: Derrick Brashear --- diff --git a/src/fsprobe/fsprobe.c b/src/fsprobe/fsprobe.c index 6f8cdbf..1ca1b5a 100644 --- a/src/fsprobe/fsprobe.c +++ b/src/fsprobe/fsprobe.c @@ -49,14 +49,6 @@ static PROCESS probeLWP_ID; /*Probe LWP process ID */ static int fsprobe_statsBytes; /*Num bytes in stats block */ static int fsprobe_probeOKBytes; /*Num bytes in probeOK block */ -/* - * We have to pass a port to Rx to start up our callback listener - * service, but 7001 is already taken up by the Cache Manager. So, - * we make up our own. - */ -#define FSPROBE_CBPORT 7101 - - /*------------------------------------------------------------------------ * [private] fsprobe_CleanupInit * @@ -489,7 +481,6 @@ fsprobe_Init(int a_numServers, struct sockaddr_in *a_socketArray, struct fsprobe_ConnectionInfo *curr_conn; /*Ptr to current conn */ char *hostNameFound; /*Ptr to returned host name */ int conn_err; /*Connection error? */ - int PortToUse; /*Callback port to use */ /* * If we've already been called, snicker at the bozo, gently @@ -594,24 +585,13 @@ fsprobe_Init(int a_numServers, struct sockaddr_in *a_socketArray, */ if (fsprobe_debug) fprintf(stderr, "[%s] Initializing Rx\n", rn); - PortToUse = FSPROBE_CBPORT; - do { - code = rx_Init(htons(PortToUse)); - if (code) { - if (code == RX_ADDRINUSE) { - if (fsprobe_debug) - fprintf(stderr, - "[%s] Callback port %d in use, advancing\n", rn, - PortToUse); - PortToUse++; - } else { - fprintf(stderr, "[%s] Fatal error in rx_Init()\n", rn); - return (-1); - } - } - } while (code); + code = rx_Init(0); + if (code) { + fprintf(stderr, "[%s] Fatal error in rx_Init()\n", rn); + return (-1); + } if (fsprobe_debug) - fprintf(stderr, "[%s] Rx initialized on port %d\n", rn, PortToUse); + fprintf(stderr, "[%s] Rx initialized.\n", rn); /* * Create a null Rx server security object, to be used by the diff --git a/src/xstat/xstat_fs.c b/src/xstat/xstat_fs.c index e35469e..f588d0f 100644 --- a/src/xstat/xstat_fs.c +++ b/src/xstat/xstat_fs.c @@ -51,13 +51,6 @@ static PROCESS probeLWP_ID; /*Probe LWP process ID */ static int xstat_fs_numCollections; /*Number of desired collections */ static afs_int32 *xstat_fs_collIDP; /*Ptr to collection IDs desired */ -/* - * We have to pass a port to Rx to start up our callback listener - * service, but 7001 is already taken up by the Cache Manager. So, - * we make up our own. - */ -#define XSTAT_FS_CBPORT 7101 - /*------------------------------------------------------------------------ * [private] xstat_fs_CleanupInit @@ -419,7 +412,6 @@ xstat_fs_Init(int a_numServers, struct sockaddr_in *a_socketArray, struct xstat_fs_ConnectionInfo *curr_conn; /*Ptr to current conn */ char *hostNameFound; /*Ptr to returned host name */ int conn_err; /*Connection error? */ - int PortToUse; /*Callback port to use */ int collIDBytes; /*Num bytes in coll ID array */ char hoststr[16]; @@ -514,25 +506,13 @@ xstat_fs_Init(int a_numServers, struct sockaddr_in *a_socketArray, */ if (xstat_fs_debug) printf("[%s] Initializing Rx\n", rn); - PortToUse = XSTAT_FS_CBPORT; - - do { - code = rx_Init(htons(PortToUse)); - if (code) { - if (code == RX_ADDRINUSE) { - if (xstat_fs_debug) - fprintf(stderr, - "[%s] Callback port %d in use, advancing\n", rn, - PortToUse); - PortToUse++; - } else { - fprintf(stderr, "[%s] Fatal error in rx_Init()\n", rn); - return (-1); - } - } - } while (code); + code = rx_Init(0); + if (code) { + fprintf(stderr, "[%s] Fatal error in rx_Init()\n", rn); + return (-1); + } if (xstat_fs_debug) - printf("[%s] Rx initialized on port %d\n", rn, PortToUse); + printf("[%s] Rx initialized\n", rn); /* * Create a null Rx server security object, to be used by the