From: Michael Meffie Date: Wed, 11 Oct 2017 02:57:01 +0000 (-0400) Subject: fsprobe: add fsprobe_Wait function X-Git-Tag: openafs-devel-1_9_0~424 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=794748af87134d0b89fbca3be6e0480a96a0655c;hp=2c1a7e47336c8f8d14dd6c65d53925a9e0e87c66 fsprobe: add fsprobe_Wait function Move the lwp code to wait in the fsprobe applications down to the fsprobe library. This is a non-functional change in anticipation of converting the fsprobe library and programs to pthreads. Change-Id: I2972b13e2e3eeb691c64c91b0640bbc97e7d0b21 Reviewed-on: https://gerrit.openafs.org/12747 Reviewed-by: Michael Meffie Reviewed-by: Benjamin Kaduk Tested-by: BuildBot --- diff --git a/src/WINNT/client_creds/ipaddrchg.c b/src/WINNT/client_creds/ipaddrchg.c index 5bfb3c1..f2aec04 100644 --- a/src/WINNT/client_creds/ipaddrchg.c +++ b/src/WINNT/client_creds/ipaddrchg.c @@ -146,13 +146,7 @@ pingFS(void *ping_params, struct sockaddr_in *addrp, char *namep) return 0; } - for (;;) - { - tv.tv_sec = pp->host.wait; - tv.tv_usec = 0; - if (IOMGR_Select(0, 0, 0, 0, &tv)) - break; - } + fsprobe_Wait(0); probeComplete(); return(0); } diff --git a/src/fsprobe/fsprobe.c b/src/fsprobe/fsprobe.c index 03657eb..8ddb320 100644 --- a/src/fsprobe/fsprobe.c +++ b/src/fsprobe/fsprobe.c @@ -831,3 +831,44 @@ fsprobe_ForceProbeNow(void) return (0); } /*fsprobe_ForceProbeNow */ + +/*------------------------------------------------------------------------ + * [exported] fsprobe_Wait + * + * Description: + * Wait for the collection to complete. + * + * Arguments: + * int sleep_secs : time to wait in seconds. 0 means sleep forever. + * + * Returns: + * 0 on success, + * Error value otherwise. + * + * Environment: + * The module must have been initialized. + * + * Side Effects: + * As advertised. + *------------------------------------------------------------------------*/ +int +fsprobe_Wait(int sleep_secs) +{ + int code; + struct timeval tv; + + if (sleep_secs == 0) { + while (1) { + tv.tv_sec = 30; + tv.tv_usec = 0; + code = IOMGR_Select(0, 0, 0, 0, &tv); + if (code != 0) + break; + } + } else { + tv.tv_sec = sleep_secs; + tv.tv_usec = 0; + code = IOMGR_Select(0, 0, 0, 0, &tv); + } + return code; +} diff --git a/src/fsprobe/fsprobe.h b/src/fsprobe/fsprobe.h index 94083bf..c3588d1 100644 --- a/src/fsprobe/fsprobe.h +++ b/src/fsprobe/fsprobe.h @@ -152,4 +152,6 @@ extern int fsprobe_Cleanup(int); * with the fsprobe connection array. */ +extern int fsprobe_Wait(int); + #endif /* __fsprobe_h */ diff --git a/src/fsprobe/fsprobe_test.c b/src/fsprobe/fsprobe_test.c index 941c8c7..7d78b6a 100644 --- a/src/fsprobe/fsprobe_test.c +++ b/src/fsprobe/fsprobe_test.c @@ -148,7 +148,6 @@ main(int argc, char **argv) afs_int32 code; /*Return code */ struct sockaddr_in FSSktArray[3]; /*socket array */ struct hostent *he; /*Host entry */ - struct timeval tv; /*Time structure */ int sleep_secs; /*Number of seconds to sleep */ printf("\n\nTest of the fsprobe facility.\n\n"); @@ -211,20 +210,7 @@ main(int argc, char **argv) ("Fsprobe service started, main thread sleeping for %d seconds...\n", sleep_secs); - /* - * Let's just fall asleep for a while, then we'll clean up. - */ - tv.tv_sec = sleep_secs; - tv.tv_usec = 0; - code = IOMGR_Select(0, /*Num fds */ - 0, /*Descriptors ready for reading */ - 0, /*Descriptors ready for writing */ - 0, /*Descriptors with exceptional conditions */ - &tv); /*Timeout structure */ - if (code) { - fprintf(stderr, "[%s] IOMGR_Select() returned non-zero value: %d\n", - rn, code); - } + fsprobe_Wait(sleep_secs); /* * We're all done. Clean up, put the last nail in Rx, then diff --git a/src/scout/scout.c b/src/scout/scout.c index 9396c50..4a38b47 100644 --- a/src/scout/scout.c +++ b/src/scout/scout.c @@ -1635,7 +1635,6 @@ execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg) struct mini_line *curr_line; /*Ptr to current line */ int i; /*Generic loop variable */ int mini_line_bytes; /*Num bytes in mini_lines */ - struct timeval tv; /*Time structure */ int linenum; /*Current mini-line number */ #if 0 PROCESS pid; /*Main LWP process ID */ @@ -1966,18 +1965,7 @@ execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg) scout_CleanExit(code); } - /* - * We fall into a loop, sleeping forever. - */ - while (1) { - tv.tv_sec = 60 * 60; /*Sleep for an hour at a time */ - tv.tv_usec = 0; - select(0, /*Num fds */ - 0, /*Descriptors ready for reading */ - 0, /*Descriptors ready for writing */ - 0, /*Descriptors with exceptional conditions */ - &tv); /*Timeout structure */ - } /*Sleep forever */ + fsprobe_Wait(0); /* sleep forever */ #if 0 /* @@ -1988,6 +1976,7 @@ execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg) return (0); #endif /* 0 */ + return 0; } /*execute_scout */ /*------------------------------------------------------------------------