From 870775005f7b779fba9abf25ffaaedc9589eb5c4 Mon Sep 17 00:00:00 2001 From: chombier <> Date: Sat, 17 Mar 2001 15:18:30 +0000 Subject: [PATCH] use current thread context in GUSITTY --- lsh/MacOS/lsh.mcp | Bin 714344 -> 721880 bytes lsh/MacOS/src/GUSITTY.cp | 19 +++++----- lsh/MacOS/src/GUSITTY.h | 14 +++++--- lsh/MacOS/src/lsh_dll.c | 35 ++++++++++++------- lsh/MacOS/src/macosmain.c | 20 +++++------ macssh/source/ssh/GUSIPatch1.cp | 4 +-- macssh/source/ssh/console.stubs.c | 56 ++++++++++++------------------ 7 files changed, 76 insertions(+), 72 deletions(-) diff --git a/lsh/MacOS/lsh.mcp b/lsh/MacOS/lsh.mcp index 01c09c5d62f4162721dc9192193d9bb0a0e6b20e..54c2ad5a72b13dc35fed2a4a5e077b7e138525d6 100755 GIT binary patch delta 8197 zcmeHLdw3Pa72nypyZ1?M0s%r2Bs>HJ3=bthYUH6p5rG>)1r$gEgd!${L=cE@1InWy zkIM!Yc|WRPKNaL6i&_n~XaS+2KA<2dHPxz(AZ^u(+VnRw=Z0|0*M9B4?R?+t@9giK znVr`;J2Rgi>-@XLUD78^oA!{VXgH=>ZDfP(-CyY*d+`B%mVJIL zb9plY&?CF7QoSvz=XS*bJxsbJ=#bsk2fkKzMHy>q9oE}M%Xz8GZuU73+Q$v%jT)X2 z+{+l6gUqaa|A9ub?Lia{YOGhZeZbGnoM$zyxMj3ga7soN6v9;W3jNU7S>$sd+8MGM zP#``){!mB;1cBD?6Pm5|HMNeq6D@vY_vnCbS=U*QrDWP)eC%pxrA3ZLD~J2rSQlzd z>#6B`J?N8Y(l~q1c%ET*IqC{E7Tp9jSXVoqZfn-VO4T zcrv^S>>uOV)gV8OCqD!Ec|2JO@=x*PT9CEz0ou?Rt+aq$1>4j zbQQ@)YT7t1cK6QhNp{GVT9L;lqg z!vLvq`nO9=F2?A@r7QKO=TPc>IM<&t-p84a(OkDZB@O}E&6%QSDr@F=|mxs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W;76g~0mO#x^F~0%Xw29L)cFO8pM!rM{UM-(``+Jy zAA`OT7|MO6`NU%_Pv*iC5^U)EYr(@1m`S_{yI#C}XcG7=L4YL#9JGTSugKmAg`{lL z3hMJYP|-<#!R(3P$6H=oco>GPjQgTQ@DsRSmIdBsdHWUk#FgM0NLty8P!At6`;}_& zlPqs*(**Z-Hu8!#!AG0~H#C!!3cE+SuY_KZUa+*bq7XhTO85KF4zFhibiXvk@*4dQ@VM!{g8h;kGIFg9TMy{!;3OJ32mDma^BeIS z*snq(rD@!2zXEZ{O3X2yj^4Zh4%vnp@OhTkUN?vG0B=ytPVkxeR)($jzoEHNJVP*N z=}X+F{TH~^^7dBO`8$6k^H;S&t2?)#y@T&n=d zZE-iOw$_55$9*15nqXMXe;9nR<>kQ9yFIdQF?egn2wK{WyJ1!F6ZjHd&nD=FJ7HCK z5;ErVj5jaBF^1KVeQ>7 z*)W^~wcaqufYzF+_y^eG7`1HzzXZ;qkp%|q`54(xZ3e#-{To0Gt0K6mw2b?$I$XpX zYQMY={Hs`g8xX^4<7)7wJgi8;r8^bbZ-+z1Yt{vd4JJ)6tg1SJU(US_!xRjw{Tlc( z?q7r-cnm8?$|>;hUm}nc7yMvhSUG$jfG@YaHuCU2VYNICGJIABnYR~+VU?2u9wrVX zWg2ufhLz*(>)_3v0Y4jlP%y0QzqN4Qt$^5hwP&HdjZ`INeS-- zdkic6H2BOlJfpb{x(LInl0e2L@&>n*QJ&Dqoo Hx+D63BlFA` diff --git a/lsh/MacOS/src/GUSITTY.cp b/lsh/MacOS/src/GUSITTY.cp index 3f91def..805acb3 100644 --- a/lsh/MacOS/src/GUSITTY.cp +++ b/lsh/MacOS/src/GUSITTY.cp @@ -29,7 +29,6 @@ #include #include #include -/*#include */ class GUSITTYDevice : public GUSIDevice { @@ -78,10 +77,10 @@ public: bool select(bool * canRead, bool * canWrite, bool *); protected: - GUSITTYSocket(int id, int flags); + GUSITTYSocket(int id, void *context); int mId; - int mFlags; + void *mContext; friend class GUSITTYDevice; }; @@ -150,7 +149,7 @@ GUSISocket * GUSITTYDevice::open(GUSIFileToken &file, int flags) } else /*if (file.StrFragEqual(path+7, "err"))*/ { id = 2; } - if ( !(sock = new GUSITTYSocket(id, flags) )) { + if ( !(sock = new GUSITTYSocket(id, pthread_getspecific(ssh2threadkey)) )) { GUSISetPosixError(ENOMEM); } return sock; @@ -161,9 +160,9 @@ GUSISocket * GUSITTYDevice::open(GUSIFileToken &file, int flags) /* * GUSITTYSocket::GUSITTYSocket */ -GUSITTYSocket::GUSITTYSocket(int id, int flags) : mId(id), mFlags(flags) +GUSITTYSocket::GUSITTYSocket(int id, void *context) : mId(id), mContext(context) { - InstallTTY(id, flags); + InstallTTY(id, context); } @@ -172,7 +171,7 @@ GUSITTYSocket::GUSITTYSocket(int id, int flags) : mId(id), mFlags(flags) */ GUSITTYSocket::~GUSITTYSocket() { - RemoveTTY(mId, mFlags); + RemoveTTY(mId, mContext); } /* @@ -183,7 +182,7 @@ ssize_t GUSITTYSocket::read(const GUSIScatterer & buffer) /* FIXME: flush pending output */ /*FlushTTY(mId);*/ return buffer.SetLength( - ReadCharsFromTTY(mId, mFlags, (char *) buffer.Buffer(), (int)buffer.Length())); + ReadCharsFromTTY(mId, mContext, (char *) buffer.Buffer(), (int)buffer.Length())); } /* @@ -191,7 +190,7 @@ ssize_t GUSITTYSocket::read(const GUSIScatterer & buffer) */ ssize_t GUSITTYSocket::write(const GUSIGatherer & buffer) { - return WriteCharsToTTY(mId, mFlags, (char *) buffer.Buffer(), (int)buffer.Length()); + return WriteCharsToTTY(mId, mContext, (char *) buffer.Buffer(), (int)buffer.Length()); } /* @@ -233,7 +232,7 @@ bool GUSITTYSocket::select(bool * canRead, bool * canWrite, bool *) { bool cond = false; if (canRead) - if (*canRead = AvailableFromTTY(mId, mFlags)) + if (*canRead = AvailableFromTTY(mId, mContext)) cond = true; if (canWrite) cond = *canWrite = true; diff --git a/lsh/MacOS/src/GUSITTY.h b/lsh/MacOS/src/GUSITTY.h index 4689c50..b72f606 100644 --- a/lsh/MacOS/src/GUSITTY.h +++ b/lsh/MacOS/src/GUSITTY.h @@ -1,15 +1,19 @@ #ifndef _GUSITTY_ #define _GUSITTY_ +#include + #ifdef __cplusplus extern "C" { #endif -extern int InstallTTY(int id, int flags); -extern void RemoveTTY(int id, int flags); -extern int ReadCharsFromTTY(int id, int flags, char * buffer, int length); -extern int WriteCharsToTTY(int id, int flags, char * buffer, int length); -extern int AvailableFromTTY(int id, int flags); +extern pthread_key_t ssh2threadkey; + +extern int InstallTTY(int id, void *context); +extern void RemoveTTY(int id, void *context); +extern int ReadCharsFromTTY(int id, void *context, char * buffer, int length); +extern int WriteCharsToTTY(int id, void *context, char * buffer, int length); +extern int AvailableFromTTY(int id, void *context); #ifdef __cplusplus } diff --git a/lsh/MacOS/src/lsh_dll.c b/lsh/MacOS/src/lsh_dll.c index 9ec5805..7a3fd82 100755 --- a/lsh/MacOS/src/lsh_dll.c +++ b/lsh/MacOS/src/lsh_dll.c @@ -544,30 +544,37 @@ pascal Ptr PLstrrchr(ConstStr255Param s, short c) /* * InstallTTY */ -int InstallTTY(int fd, int flags) +int InstallTTY(int id, void *ctx) { -#pragma unused (fd) +#pragma unused (id, ctx) return 0; } /* * RemoveTTY */ -void RemoveTTY(int fd, int flags) +void RemoveTTY(int fd, void *ctx) { -#pragma unused (fd) +#pragma unused (id, ctx) } /* * WriteCharsToTTY */ -int WriteCharsToTTY(int fd, int flags, char *buffer, int n) +int WriteCharsToTTY(int id, void *ctx, char *buffer, int n) { long written = 0; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); + lshcontext *context = (lshcontext *)ctx; char *buf = buffer; char c; + if ( id == 2 ) { + // log stderr to console + syslog( 0, "%.*s", n, buffer ); + /*putlln( buffer, n );*/ + return n; + } + if ( !context ) { return 0; } @@ -634,10 +641,11 @@ int WriteCharsToTTY(int fd, int flags, char *buffer, int n) /* * ReadCharsFromTTY */ -int ReadCharsFromTTY(int fd, int flags, char *buffer, int n) +int ReadCharsFromTTY(int id, void *ctx, char *buffer, int n) { +#pragma unused (id) long len = 0; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); + lshcontext *context = (lshcontext *)ctx; if ( !context ) { return 0; @@ -675,9 +683,10 @@ int ReadCharsFromTTY(int fd, int flags, char *buffer, int n) /* * AvailableFromTTY */ -int AvailableFromTTY(int id, int flags) +int AvailableFromTTY(int id, void *ctx) { - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); +#pragma unused (id) + lshcontext *context = (lshcontext *)ctx; if ( !context ) { return 0; @@ -1176,8 +1185,10 @@ void lsh_delete(lshctx *ctx) lshcontext *context = ctx->context; context->_gConsoleInEOF = true; pthread_kill( ctx->pthread, SIGINT ); - ctx->pthread = NULL; - ssh2_sched(); + while (ctx->pthread) { + /* wait for thread to die */ + ssh2_sched(); + } } if ( ctx->argstr != NULL ) { DisposePtr( ctx->argstr ); diff --git a/lsh/MacOS/src/macosmain.c b/lsh/MacOS/src/macosmain.c index a4db78c..4defe7f 100755 --- a/lsh/MacOS/src/macosmain.c +++ b/lsh/MacOS/src/macosmain.c @@ -492,44 +492,44 @@ pascal Ptr PLstrrchr(ConstStr255Param s, short c) /* * InstallTTY */ -int InstallTTY(int id, int flags) +int InstallTTY(int id, void *context) { -#pragma unused (id, flags) +#pragma unused (id, context) return 0; } /* * RemoveTTY */ -void RemoveTTY(int id, int flags) +void RemoveTTY(int id, void *context) { -#pragma unused (id, flags) +#pragma unused (id, context) } /* * WriteCharsToTTY */ -int WriteCharsToTTY(int id, int flags, char *buffer, int n) +int WriteCharsToTTY(int id, void *context, char *buffer, int n) { -#pragma unused (id, flags) +#pragma unused (id, context) return WriteCharsToConsole(buffer, n); } /* * ReadCharsFromTTY */ -int ReadCharsFromTTY(int id, int flags, char *buffer, int n) +int ReadCharsFromTTY(int id, void *context, char *buffer, int n) { -#pragma unused (id, flags) +#pragma unused (id, context) return ReadCharsFromConsole(buffer, n); } /* * AvailableFromTTY */ -int AvailableFromTTY(int id, int flags) +int AvailableFromTTY(int id, void *context) { -#pragma unused (id, flags) +#pragma unused (id, context) extern short gSIOUXBufSize; if ( !gSIOUXBufSize ) { QHdrPtr eventQueue = LMGetEventQueue(); diff --git a/macssh/source/ssh/GUSIPatch1.cp b/macssh/source/ssh/GUSIPatch1.cp index caf6d41..479afde 100755 --- a/macssh/source/ssh/GUSIPatch1.cp +++ b/macssh/source/ssh/GUSIPatch1.cp @@ -90,9 +90,9 @@ void ssh2_init() gethostid(); /*GUSISetupConsole();*/ - sGUSISetup = true; - g_error_fd = open("dev:ttyerr", O_WRONLY ); + + sGUSISetup = true; } } diff --git a/macssh/source/ssh/console.stubs.c b/macssh/source/ssh/console.stubs.c index c6b7e7b..b17e6cc 100755 --- a/macssh/source/ssh/console.stubs.c +++ b/macssh/source/ssh/console.stubs.c @@ -36,8 +36,8 @@ extern void syslog( int priority, const char *format, ...); -static void accept_call(); -static void check_listener(); +static void accept_call(lshcontext *context); +static void check_listener(lshcontext *context); /* @@ -191,13 +191,8 @@ void clrscr() * accept_call */ -static void accept_call() +static void accept_call(lshcontext *context) { - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( !context ) { - return; - } if ( context->_listener != -1 && context->_socket == -1 ) { struct sockaddr peer; socklen_t addr_len = sizeof(peer); @@ -230,13 +225,8 @@ static void accept_call() * check_listener */ -static void check_listener() +static void check_listener(lshcontext *context) { - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( !context ) { - return; - } if ( context->_listener != -1 && context->_socket == -1 ) { struct fd_set rfds; struct timeval timeout; @@ -246,7 +236,7 @@ static void check_listener() timeout.tv_usec = 0; if ( select( 32, &rfds, NULL, NULL, &timeout ) ) { if ( FD_ISSET( context->_listener, &rfds ) ) { - accept_call(); + accept_call(context); } } } @@ -292,43 +282,43 @@ static long read_local_socket(lshcontext *context, char *buffer, long n) /* * InstallTTY */ -int InstallTTY(int fd, int flags) +int InstallTTY(int id, void *ctx) { -#pragma unused (fd) +#pragma unused (id) return 0; } /* * RemoveTTY */ -void RemoveTTY(int fd, int flags) +void RemoveTTY(int id, void *ctx) { -#pragma unused (fd) +#pragma unused (id) } /* * WriteCharsToTTY */ -int WriteCharsToTTY(int fd, int flags, char *buffer, int n) +int WriteCharsToTTY(int id, void *ctx, char *buffer, int n) { long written = 0; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); + lshcontext *context = ctx; char *buf = buffer; char c; - if ( !context ) { - return 0; - } - - if ( fd == 2 ) { + if ( id == 2 ) { // log stderr to console putlln( buffer, n ); return n; } + if ( !context ) { + return 0; + } + if ( context->_listener != -1 ) { /* write data to local socket */ - check_listener(); + check_listener(context); if ( context->_socket != -1 ) { while ( n > 0 && context->_socket != -1 ) { long len = n; @@ -411,10 +401,10 @@ int WriteCharsToTTY(int fd, int flags, char *buffer, int n) /* * ReadCharsFromTTY */ -int ReadCharsFromTTY(int fd, int flags, char *buffer, int n) +int ReadCharsFromTTY(int id, void *ctx, char *buffer, int n) { long len = 0; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); + lshcontext *context = ctx; if ( !context ) { return 0; @@ -440,7 +430,7 @@ int ReadCharsFromTTY(int fd, int flags, char *buffer, int n) ssh2_sched(); if ( context->_listener != -1 ) { /* read data from local socket */ - check_listener(); + check_listener(context); if ( context->_socket != -1 ) { len = read_local_socket(context, buffer, n); if ( context->_socket == -1 && len == 0 ) { @@ -463,9 +453,9 @@ int ReadCharsFromTTY(int fd, int flags, char *buffer, int n) /* * AvailableFromTTY */ -int AvailableFromTTY(int id, int flags) +int AvailableFromTTY(int id, void *ctx) { - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); + lshcontext *context = ctx; if ( !context ) { return 0; @@ -486,7 +476,7 @@ int AvailableFromTTY(int id, int flags) if ( select( 32, &rfds, NULL, &efds, &timeout ) ) { if ( context->_socket == -1 ) { if ( FD_ISSET( context->_listener, &rfds ) ) { - accept_call(); + accept_call(context); } } else { if ( FD_ISSET( context->_socket, &efds ) ) {