From 627dc517250de390316c2b8523318be755bd898c Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Mon, 13 Jan 2014 15:28:17 -0500 Subject: [PATCH] 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. Reviewed-on: http://gerrit.openafs.org/10707 Tested-by: BuildBot Reviewed-by: Marc Dionne Reviewed-by: Derrick Brashear (cherry picked from commit cda5e665ebee3da5615dba71b7a11ffff1229c6d) Change-Id: I00c2d9e7d48e80dc1bc062a85788ad2de65709c7 Reviewed-on: http://gerrit.openafs.org/11155 Tested-by: BuildBot Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Perry Ruiter Reviewed-by: Stephan Wiesand --- src/fsprobe/fsprobe.c | 32 ++++++-------------------------- src/xstat/xstat_fs.c | 32 ++++++-------------------------- 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/src/fsprobe/fsprobe.c b/src/fsprobe/fsprobe.c index 1eda563ef..f5008ac5b 100644 --- a/src/fsprobe/fsprobe.c +++ b/src/fsprobe/fsprobe.c @@ -51,14 +51,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 * @@ -491,7 +483,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 @@ -596,24 +587,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 f79f4876a..f970d5e67 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 -- 2.39.5