From: Michael Meffie Date: Thu, 4 Nov 2010 13:26:25 +0000 (-0400) Subject: avoid private stdio fields in waitkey X-Git-Tag: openafs-devel-1_7_1~1295 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=aac929badb5e40a59ae77ae69fc43df8f6f376fc avoid private stdio fields in waitkey Use the stdio_ext functions provided by solaris and glibc instead of directly accessing private stdio FILE structure members. This is needed for 64-bit solaris builds and is more portable in general since the FILE structure is meant to be opaque. Remove the duplicated code in the pthreaded butc package. Change-Id: Idbefa88e2563bb117322e818b1300b324fc3626d Reviewed-on: http://gerrit.openafs.org/3257 Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/acinclude.m4 b/acinclude.m4 index cc97b6a..af50792 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1215,7 +1215,7 @@ AC_CHECK_HEADERS(windows.h direct.h sys/ipc.h sys/resource.h sys/un.h) AC_CHECK_HEADERS(security/pam_modules.h ucontext.h regex.h sys/statvfs.h sys/statfs.h sys/bitypes.h) AC_CHECK_HEADERS(sys/socket.h sys/ioctl.h errno.h time.h syslog.h) AC_CHECK_HEADERS(linux/errqueue.h,,,[#include ]) -AC_CHECK_HEADERS(et/com_err.h) +AC_CHECK_HEADERS(et/com_err.h stdio_ext.h) AC_CHECK_TYPES([fsblkcnt_t],,,[ #include diff --git a/src/butc/butc_internal.h b/src/butc/butc_internal.h index a0f6243..e51aadb 100644 --- a/src/butc/butc_internal.h +++ b/src/butc/butc_internal.h @@ -38,8 +38,6 @@ extern int FindVolTrailer(char *, afs_int32, afs_int32 *, struct volumeHeader *); extern int FindVolTrailer2(char *, afs_int32, afs_int32 *, char *, afs_int32, afs_int32 *, struct volumeHeader *); -extern int GetResponseKey(int, char *); - /* recoverDb.c */ extern afs_int32 Ask(char *); diff --git a/src/butc/dump.c b/src/butc/dump.c index 94bc76a..229d312 100644 --- a/src/butc/dump.c +++ b/src/butc/dump.c @@ -1422,11 +1422,7 @@ retryPrompt(char *volumeName, afs_int32 volumeId, afs_uint32 taskId) start = time(0); while (1) { -#ifdef AFS_PTHREAD_ENV - code = GetResponseKey(5, &ch); /* ch stores key pressed */ -#else code = LWP_GetResponseKey(5, &ch); /* ch stores key pressed */ -#endif if (code == 1) break; /* input is available */ diff --git a/src/butc/lwps.c b/src/butc/lwps.c index 79690fb..525aa3d 100644 --- a/src/butc/lwps.c +++ b/src/butc/lwps.c @@ -324,122 +324,6 @@ LeaveDeviceQueue(struct deviceSyncNode *devLatch) #define BELLTIME 60 /* 60 seconds before a bell rings */ #define BELLCHAR 7 /* ascii for bell */ - -#ifdef AFS_PTHREAD_ENV -#ifdef AFS_NT40_ENV -/* WaitForKeystroke : Wait until a key has been struck or time (secconds) - * runs out and return to caller. The NT version of this function will return - * immediately after a key has been pressed (doesn't wait for cr). - * Input: - * seconds: wait for seconds before returning. If seconds < 0, - * wait infinitely. - * Return Value: - * 1: Keyboard input available - * 0: seconds elapsed. Timeout. - * - * STOLEN FROM LWP_WaitForKeystroke() - */ -int -WaitForKeystroke(int seconds) -{ - time_t startTime, nowTime; - double timeleft = 1; - struct timeval twait; - - time(&startTime); - twait.tv_sec = 0; - twait.tv_usec = 250; - if (seconds >= 0) - timeleft = seconds; - - do { - /* check if we have a keystroke */ - if (_kbhit()) - return 1; - if (timeleft == 0) - break; - - /* sleep for LWP_KEYSTROKE_DELAY ms and let other - * process run some*/ - select(0, 0, 0, 0, &twait); - - if (seconds > 0) { /* we only worry about elapsed time if - * not looping forever (seconds < 0) */ - time(&nowTime); - timeleft = seconds - difftime(nowTime, startTime); - } - } while (timeleft > 0); - return 0; -} -#else /* AFS_NT40)ENV */ -extern int WaitForKeystroke(int); -/* - * STOLEN FROM LWP_WaitForKeystroke() - */ -int -WaitForKeystroke(int seconds) -{ - fd_set rdfds; - int code; - struct timeval twait; - struct timeval *tp = NULL; - -#ifdef AFS_LINUX20_ENV - if (stdin->_IO_read_ptr < stdin->_IO_read_end) - return 1; -#else - if (stdin->_cnt > 0) - return 1; -#endif - FD_ZERO(&rdfds); - FD_SET(fileno(stdin), &rdfds); - - if (seconds >= 0) { - twait.tv_sec = seconds; - twait.tv_usec = 0; - tp = &twait; - } - code = select(1 + fileno(stdin), &rdfds, NULL, NULL, tp); - return (code == 1) ? 1 : 0; -} -#endif - -/* GetResponseKey() - Waits for a specified period of time and - * returns a char when one has been typed by the user. - * Input: - * seconds - how long to wait for a key press. - * *key - char entered by user - * Return Values: - * 0 - Time ran out before the user typed a key. - * 1 - Valid char is being returned. - * - * STOLEN FROM LWP_GetResponseKey(); - */ -int -GetResponseKey(int seconds, char *key) -{ - int rc; - - if (key == NULL) - return 0; /* need space to store char */ - fflush(stdin); /* flush all existing data and start anew */ - - rc = WaitForKeystroke(seconds); - if (rc == 0) { /* time ran out */ - *key = 0; - return rc; - } - - /* now read the char. */ -#ifdef AFS_NT40_ENV - *key = getche(); /* get char and echo it to screen */ -#else - *key = getchar(); -#endif - return rc; -} -#endif /* AFS_PTHREAD_ENV */ - /* * FFlushInput * flush all input @@ -454,12 +338,7 @@ FFlushInput(void) fflush(stdin); while (1) { -#ifdef AFS_PTHREAD_ENV - w = WaitForKeystroke(0); -#else w = LWP_WaitForKeystroke(0); -#endif /* AFS_PTHREAD_ENV */ - if (w) { #ifdef AFS_NT40_ENV getche(); @@ -807,11 +686,7 @@ PromptForTape(int flag, char *name, afs_uint32 dbDumpId, afs_uint32 taskId, putchar(BELLCHAR); fflush(stdout); } -#ifdef AFS_PTHREAD_ENV - wcode = GetResponseKey(5, &inchr); /* inchr stores key read */ -#else wcode = LWP_GetResponseKey(5, &inchr); /* inchr stores key read */ -#endif if (wcode == 1) { /* keyboard input is available */ if ((inchr == 'a') || (inchr == 'A')) { diff --git a/src/lwp/lwp.h b/src/lwp/lwp.h index 81050b0..c54e77c 100644 --- a/src/lwp/lwp.h +++ b/src/lwp/lwp.h @@ -358,9 +358,6 @@ extern int IOMGR_Initialize(void); extern void IOMGR_FreeFDSet(fd_set * fds); extern int IOMGR_SoftSig(void *(*aproc) (void *), void *arock); -extern int LWP_WaitForKeystroke(int seconds); /* -1 => forever */ -extern int LWP_GetResponseKey(int seconds, char *key); -extern int LWP_GetLine(char *linebuf, int len); #ifdef AFS_NT40_ENV /* lwp.c */ extern int LWP_InitializeProcessSupport(int priority, PROCESS * pid); @@ -402,7 +399,11 @@ extern void returnto(struct lwp_context *savearea); /* max time we spend on a select in a Win95 DOS box */ #define IOMGR_WIN95WAITTIME 5000 /* microseconds */ -#endif -#endif /* __LWP_INCLUDE_ */ +#endif /* !AFS_PTHREAD_ENV */ + +extern int LWP_WaitForKeystroke(int seconds); /* -1 => forever */ +extern int LWP_GetResponseKey(int seconds, char *key); +extern int LWP_GetLine(char *linebuf, int len); #endif /* !KERNEL && !_KMEMUSER */ +#endif /* __LWP_INCLUDE_ */ diff --git a/src/lwp/test/Makefile.in b/src/lwp/test/Makefile.in index e492fcb..8112f27 100644 --- a/src/lwp/test/Makefile.in +++ b/src/lwp/test/Makefile.in @@ -39,7 +39,7 @@ selserver: selserver.o selsubs.o ${LIBS} selsubs.o: selsubs.c seltest.h test_key: test_key.o - $(AFS_LDRULE) test_key.o ../liblwp.a $(DESTDIR)/lib/afs/util.a + $(AFS_LDRULE) test_key.o ${LIBS} ${TOP_LIBDIR}/util.a clean: - -$(RM) -f *.o *.a test testlwp selclient selserver core + -$(RM) -f *.o *.a test test_key selclient selserver core diff --git a/src/lwp/test/NTMakefile b/src/lwp/test/NTMakefile index e211b02..08486e5 100644 --- a/src/lwp/test/NTMakefile +++ b/src/lwp/test/NTMakefile @@ -10,7 +10,7 @@ RELDIR=lwp\test !INCLUDE ..\..\config\NTMakefile.version LIBS = $(DESTDIR)\lib\afslwp.lib \ - $(DESTDIR)lib\afs\afsutil.lib + $(DESTDIR)\lib\afs\afsutil.lib # build testkey.exe diff --git a/src/lwp/waitkey.c b/src/lwp/waitkey.c index 98e93bc..330725f 100644 --- a/src/lwp/waitkey.c +++ b/src/lwp/waitkey.c @@ -24,6 +24,9 @@ #include +#ifdef HAVE_STDIO_EXT_H +#include +#endif #include #ifdef AFS_NT40_ENV #include @@ -75,7 +78,11 @@ LWP_WaitForKeystroke(int seconds) /* sleep for LWP_KEYSTROKE_DELAY ms and let other * process run some*/ +#ifdef AFS_PTHREAD_ENV + select(0, 0, 0, 0, &twait); +#else IOMGR_Select(0, 0, 0, 0, &twait); +#endif if (seconds > 0) { /* we only worry about elapsed time if * not looping forever (seconds < 0) */ @@ -158,12 +165,13 @@ LWP_WaitForKeystroke(int seconds) struct timeval twait; struct timeval *tp = NULL; -#ifdef AFS_LINUX20_ENV +#if defined(HAVE_STDIO_EXT_H) + if (__fbufsize(stdin) > 0) + return 1; +#elif defined(AFS_LINUX20_ENV) if (stdin->_IO_read_ptr < stdin->_IO_read_end) return 1; -#else -#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) -#if defined(AFS_DFBSD_ENV) +#elif (defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)) && defined(AFS_DFBSD_ENV) struct appx_sbuf { unsigned char *_base; int _size; @@ -176,15 +184,13 @@ LWP_WaitForKeystroke(int seconds) struct APPX_FILE *appx_stdin = (struct APPX_FILE *) stdin; if (appx_stdin->_bf._size > 0) return 1; -#else +#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) if (stdin->_bf._size > 0) return 1; -#endif #else if (stdin->_cnt > 0) return 1; #endif -#endif FD_ZERO(&rdfds); FD_SET(fileno(stdin), &rdfds); @@ -195,7 +201,11 @@ LWP_WaitForKeystroke(int seconds) tp = &twait; } +#ifdef AFS_PTHREAD_ENV + code = select(1 + fileno(stdin), &rdfds, NULL, NULL, tp); +#else code = IOMGR_Select(1 + fileno(stdin), &rdfds, NULL, NULL, tp); +#endif return (code == 1) ? 1 : 0; } diff --git a/src/tbutc/Makefile.in b/src/tbutc/Makefile.in index 010d328..49c6329 100644 --- a/src/tbutc/Makefile.in +++ b/src/tbutc/Makefile.in @@ -32,7 +32,7 @@ BUCOORDOBJS=ubik_db_if.o ../bucoord/volstub.o ../bucoord/dlq.o \ VOLSEROBJS=vsprocs.o vsutils.o lockprocs.o VOLSERLIBS=${TOP_LIBDIR}/libvosadmin.a ${TOP_LIBDIR}/libafsadminutil.a -LWPOBJS =lock.o +LWPOBJS =lock.o waitkey.o BUTCOBJS =dbentries.o tcprocs.o lwps.o tcmain.o list.o recoverDb.o \ tcudbprocs.o dump.o tcstatus.o butc_xbsa.o afsxbsa.o \ @@ -129,6 +129,9 @@ lockprocs.o: ${VOLSER}/lockprocs.c lock.o: ${LWP}/lock.c $(AFS_CCRULE) ${LWP}/lock.c +waitkey.o: ${LWP}/waitkey.c + $(AFS_CCRULE) ${LWP}/waitkey.c + file_tm.o: ${BUTM}/file_tm.c ${BUTMINCLS} $(AFS_CCRULE) ${BUTM}/file_tm.c diff --git a/src/tbutc/NTMakefile b/src/tbutc/NTMakefile index 83802e1..320186f 100644 --- a/src/tbutc/NTMakefile +++ b/src/tbutc/NTMakefile @@ -37,7 +37,7 @@ BUCOORDOBJS = $(OUT)\ubik_db_if.obj \ $(OUT)\$(BUCOORD)\status.obj \ $(OUT)\$(BUCOORD)\bucoord_errs.obj -LWPOBJS = $(OUT)\lock.obj +LWPOBJS = $(OUT)\lock.obj $(OUT)\waitkey.obj BUTMOBJS = $(OUT)\file_tm.obj \ $(OUT)\AFS_component_version_number.obj @@ -143,6 +143,9 @@ $(OUT)\ubik_db_if.obj: $(BUCOORD)/ubik_db_if.c $(OUT)\lock.obj: $(LWP)/lock.c $(C2OBJ) $** +$(OUT)\waitkey.obj: $(LWP)/waitkey.c + $(C2OBJ) $** + #----------------------------------------------- BUTC $(OUT)\file_tm.obj: $(BUTM)/file_tm.c