From 7ff76751f63b5bb54e2aa6f080a6adce78d1c8da Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Mon, 18 Sep 2023 08:23:30 +0200 Subject: [PATCH 1/2] Fix compile errors when WOLFSSH_TERM is undefined --- examples/client/client.c | 6 ++++++ src/ssh.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/examples/client/client.c b/examples/client/client.c index d38d316d..a0ad03b1 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -190,6 +190,7 @@ typedef struct thread_args { #endif +#ifdef WOLFSSH_TERM static int sendCurrentWindowSize(thread_args* args) { int ret; @@ -221,6 +222,7 @@ static int sendCurrentWindowSize(thread_args* args) return ret; } +#endif #ifndef _MSC_VER @@ -260,7 +262,9 @@ static THREAD_RET windowMonitor(void* in) if (args->quit) { break; } +#ifdef WOLFSSH_TERM ret = sendCurrentWindowSize(args); +#endif (void)ret; } while (1); @@ -877,6 +881,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) sem_init(&windowSem, 0, 0); #endif +#ifdef WOLFSSH_TERM if (cmd) { int err; @@ -887,6 +892,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) fprintf(stderr, "Issue sending exec initial terminal size\n\r"); } } +#endif signal(SIGWINCH, WindowChangeSignal); pthread_create(&thread[0], NULL, windowMonitor, (void*)&arg); diff --git a/src/ssh.c b/src/ssh.c index 75bd8d1f..6c11e834 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -1315,6 +1315,7 @@ void* wolfSSH_GetPublicKeyCheckCtx(WOLFSSH* ssh) return NULL; } +#ifdef WOLFSSH_TERM /* Used to resize terminal window with shell connections * returns WS_SUCCESS on success */ @@ -1350,6 +1351,8 @@ void wolfSSH_SetTerminalResizeCtx(WOLFSSH* ssh, void* usrCtx) ssh->termCtx = usrCtx; } +#endif + /* Used to set the channel request type sent in wolfSSH connect. The default * type set is shell if this function is not called. From 481c334a39494897c6dd0b9acde935ad0aa37283 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 22 Sep 2023 16:26:23 -0700 Subject: [PATCH 2/2] Fix No Term 1. Widened the scope of a couple of the guards for WOLFSSH_TERM. 2. Added a pthread_join for one of the threads in the example client. --- examples/client/client.c | 18 +++++++++++------- src/internal.c | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/client/client.c b/examples/client/client.c index a0ad03b1..f6134ee0 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -225,6 +225,7 @@ static int sendCurrentWindowSize(thread_args* args) #endif +#ifdef WOLFSSH_TERM #ifndef _MSC_VER #if (defined(__OSX__) || defined(__APPLE__)) @@ -262,15 +263,13 @@ static THREAD_RET windowMonitor(void* in) if (args->quit) { break; } -#ifdef WOLFSSH_TERM ret = sendCurrentWindowSize(args); -#endif (void)ret; } while (1); return THREAD_RET_SUCCESS; } -#else +#else /* _MSC_VER */ /* no SIGWINCH on Windows, poll current terminal size */ static word32 prevCol, prevRow; @@ -296,7 +295,8 @@ static int windowMonitor(thread_args* args) return ret; } -#endif +#endif /* _MSC_VER */ +#endif /* WOLFSSH_TERM */ static THREAD_RET readInput(void* in) @@ -875,13 +875,13 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) arg.ssh = ssh; arg.quit = 0; wc_InitMutex(&arg.lock); +#ifdef WOLFSSH_TERM #if (defined(__OSX__) || defined(__APPLE__)) windowSem = dispatch_semaphore_create(0); #else sem_init(&windowSem, 0, 0); #endif -#ifdef WOLFSSH_TERM if (cmd) { int err; @@ -892,13 +892,13 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) fprintf(stderr, "Issue sending exec initial terminal size\n\r"); } } -#endif - signal(SIGWINCH, WindowChangeSignal); pthread_create(&thread[0], NULL, windowMonitor, (void*)&arg); +#endif /* WOLFSSH_TERM */ pthread_create(&thread[1], NULL, readInput, (void*)&arg); pthread_create(&thread[2], NULL, readPeer, (void*)&arg); pthread_join(thread[2], NULL); +#ifdef WOLFSSH_TERM /* Wake the windowMonitor thread so it can exit. */ arg.quit = 1; #if (defined(__OSX__) || defined(__APPLE__)) @@ -907,12 +907,16 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) sem_post(&windowSem); #endif pthread_join(thread[0], NULL); +#endif /* WOLFSSH_TERM */ pthread_cancel(thread[1]); + pthread_join(thread[1], NULL); +#ifdef WOLFSSH_TERM #if (defined(__OSX__) || defined(__APPLE__)) dispatch_release(windowSem); #else sem_destroy(&windowSem); #endif +#endif /* WOLFSSH_TERM */ #elif defined(_MSC_VER) thread_args arg; HANDLE thread[2]; diff --git a/src/internal.c b/src/internal.c index 1c42618b..76fccf59 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6875,7 +6875,7 @@ static int DoChannelRequest(WOLFSSH* ssh, WLOG(WS_LOG_AGENT, "Agent callback not set, not using."); } #endif /* WOLFSSH_AGENT */ -#ifdef WOLFSSH_SHELL +#if defined(WOLFSSH_SHELL) && defined(WOLFSSH_TERM) else if (WSTRNCMP(type, "window-change", typeSz) == 0) { word32 widthChar, heightRows, widthPixels, heightPixels; @@ -6902,7 +6902,7 @@ static int DoChannelRequest(WOLFSSH* ssh, } } } -#endif +#endif /* WOLFSSH_SHELL && WOLFSSH_TERM */ } if (ret == WS_SUCCESS)