From 62dba066e1bd0ba1d1bb7e9b4b275e40cd7b2c45 Mon Sep 17 00:00:00 2001 From: Bryan Stansell Date: Tue, 13 Oct 2020 14:54:29 -0700 Subject: [PATCH] wrap usleep()/nanosleep() with Sleep() based on configure findings --- configure.ac | 2 +- conserver/consent.c | 7 ++----- conserver/cutil.c | 11 +++++++++++ conserver/cutil.h | 1 + conserver/group.c | 13 +++++-------- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 757133a..ee2bc8a 100644 --- a/configure.ac +++ b/configure.ac @@ -850,7 +850,7 @@ AC_CHECK_HEADERS(pty.h libutil.h util.h) AC_CHECK_LIB(util, openpty) AC_CHECK_FUNCS(openpty) -AC_CHECK_FUNCS(getopt strerror getrlimit getsid setsid getuserattr setgroups tcgetpgrp tcsetpgrp tcgetattr tcsetattr tcsendbreak setpgrp getutent setttyent getspnam setlinebuf setvbuf ptsname grantpt unlockpt sigaction setsockopt getdtablesize putenv memset memcpy memcmp memmove sysconf getlogin inet_aton setproctitle gettimeofday strlcpy closefrom) +AC_CHECK_FUNCS(getopt strerror getrlimit getsid setsid getuserattr setgroups tcgetpgrp tcsetpgrp tcgetattr tcsetattr tcsendbreak setpgrp getutent setttyent getspnam setlinebuf setvbuf ptsname grantpt unlockpt sigaction setsockopt getdtablesize putenv memset memcpy memcmp memmove sysconf getlogin inet_aton setproctitle gettimeofday strlcpy closefrom nanosleep) AC_CHECK_FUNC(strcasecmp, [AC_DEFINE(HAVE_STRCASECMP, 1, [Define if strcasecmp is available])], [AC_CHECK_FUNC(stricmp, diff --git a/conserver/consent.c b/conserver/consent.c index faf118b..c9e0134 100644 --- a/conserver/consent.c +++ b/conserver/consent.c @@ -820,8 +820,7 @@ ConsInit(CONSENT *pCE) */ if (pCE->fup) { ConsDown(pCE, FLAGFALSE, FLAGTRUE); - struct timespec t = {0, 250 * 1000 * 1000}; - nanosleep(&t, NULL); /* pause 0.25 sec to let things settle a bit */ + Sleep(250000); } pCE->autoReUp = 0; @@ -886,9 +885,7 @@ ConsInit(CONSENT *pCE) #if HAVE_SETSOCKOPT int one = 1; #endif - struct timespec t = {0, 100 * 1000 * 1000}; - - nanosleep(&t, NULL); /* Not all terminal servers can keep up */ + Sleep(100000); /* Not all terminal servers can keep up */ #if USE_IPV6 # if HAVE_MEMSET diff --git a/conserver/cutil.c b/conserver/cutil.c index d0075f9..c7f198a 100644 --- a/conserver/cutil.c +++ b/conserver/cutil.c @@ -3091,3 +3091,14 @@ StrCpy(char *dst, const char *src, unsigned int size) strcpy(dst, src); #endif } + +void +Sleep(useconds_t usec) +{ +#ifdef HAVE_NANOSLEEP + struct timespec ts = {0, usec * 1000}; + nanosleep(&ts, NULL); +#else + usleep(usec); +#endif +} diff --git a/conserver/cutil.h b/conserver/cutil.h index db4df7f..6b74a16 100644 --- a/conserver/cutil.h +++ b/conserver/cutil.h @@ -215,6 +215,7 @@ extern void ProcessSubst(SUBST *, char **, char **, char *, char *); extern char *MyVersion(void); extern unsigned int AtoU(char *); extern void StrCpy(char *, const char *, unsigned int); +extern void Sleep(useconds_t); #if HAVE_OPENSSL extern SSL *FileGetSSL(CONSFILE *); extern void FileSetSSL(CONSFILE *, SSL *); diff --git a/conserver/group.c b/conserver/group.c index c663188..9b70f9d 100644 --- a/conserver/group.c +++ b/conserver/group.c @@ -4211,12 +4211,10 @@ FlushConsole(CONSENT *pCEServing) } */ CONDDEBUG((1, - "Kiddie(): heavy IAC - doing usleep() for [%s] (break #%c - delay %dms)", + "Kiddie(): heavy IAC - doing Sleep() for [%s] (break #%c - delay %dms)", pCEServing->server, next, delay)); - if (delay != 0) { - struct timespec d = {0, delay * 1000 * 1000}; - nanosleep(&d, NULL); - } + if (delay != 0) + Sleep(delay * 1000); } else if (next == BREAK) { CONDDEBUG((1, "Kiddie(): heavy IAC - sending break for [%s]", @@ -4248,7 +4246,7 @@ FlushConsole(CONSENT *pCEServing) } /* we do this 'cause we just potentially paused for * a half-second doing a break...or even the - * intentional usleep(). we could take out the + * intentional Sleep(). we could take out the * justHadDelay bits and continue with the stream, * but this allows us to process other consoles and * then come around and do more on this one. you @@ -5252,8 +5250,7 @@ Spawn(GRPENT *pGE, int msfd) * possibly opens another socket to the port. this really is only * an issue if you use the same port with -p and -b, i think. */ - struct timespec s = {0, 750 * 1000 * 1000}; - nanosleep(&s, NULL); /* pause 0.75 sec to throttle startup a bit */ + Sleep(750000); /* pause 0.75 sec to throttle startup a bit */ pGE->pid = pid; return; case 0: