diff --git a/app/consapp/rtkrcv/rtkrcv.c b/app/consapp/rtkrcv/rtkrcv.c index d640f5cc6..5b4637ccb 100644 --- a/app/consapp/rtkrcv/rtkrcv.c +++ b/app/consapp/rtkrcv/rtkrcv.c @@ -1407,6 +1407,7 @@ static void *con_thread(void *arg) } } vt_close(con->vt); + con->vt = NULL; return 0; } /* open console --------------------------------------------------------------*/ @@ -1418,9 +1419,16 @@ static con_t *con_open(int sock, const char *dev) if (!(con=(con_t *)malloc(sizeof(con_t)))) return NULL; - if (!(con->vt=vt_open(sock,dev))) { - free(con); - return NULL; + if ( sock == 0 ) { + if (!(con->vt=vt_open_stdout())) { + free(con); + return NULL; + } + } else { + if (!(con->vt=vt_open(sock,dev))) { + free(con); + return NULL; + } } /* start console thread */ con->state=1; @@ -1436,7 +1444,10 @@ static void con_close(con_t *con) trace(3,"con_close:\n"); if (!con) return; - con->state=con->vt->state=0; + con->state=0; + if ( con->vt ) { + con->vt->state = 0; + } pthread_join(con->thread,NULL); free(con); } diff --git a/app/consapp/rtkrcv/vt.c b/app/consapp/rtkrcv/vt.c index 9d397294f..a5e4df0a3 100644 --- a/app/consapp/rtkrcv/vt.c +++ b/app/consapp/rtkrcv/vt.c @@ -50,6 +50,39 @@ #define C_DONT (char)254 /* telnet option negotiation */ #define C_IAC (char)255 /* telnet interpret as command */ +/* open virtual console on stdout -------------------------------------------- +* open virtual console +* args : +* return : virtual console (NULL: error) +*-----------------------------------------------------------------------------*/ +extern vt_t *vt_open_stdout() +{ + vt_t *vt; + int i; + struct termios tio={0}; + + trace(3,"vt_open_stdout\n"); + + if (!(vt=(vt_t *)malloc(sizeof(vt_t)))) { + return NULL; + } + /* set terminal mode echo-off */ + vt->in=fileno(stdin); + vt->out=fileno(stdout); + tcgetattr(vt->in,&vt->tio); + tcsetattr(vt->in,TCSANOW,&tio); + + vt->n=vt->nesc=vt->cur=vt->cur_h=vt->brk=vt->blind=0; + vt->logfp=NULL; + for (i=0;ihist[i]=NULL; + } + vt->type=VT_TYPE_STDOUT; + + vt->state=1; + return vt; +} + /* open virtual console -------------------------------------------------------- * open virtual console * args : vt_t *vt I virtual console @@ -69,7 +102,8 @@ extern vt_t *vt_open(int sock, const char *dev) if (!(vt=(vt_t *)malloc(sizeof(vt_t)))) { return NULL; } - vt->type=vt->n=vt->nesc=vt->cur=vt->cur_h=vt->brk=vt->blind=0; + vt->type=VT_TYPE_DEV; + vt->n=vt->nesc=vt->cur=vt->cur_h=vt->brk=vt->blind=0; vt->logfp=NULL; for (i=0;ihist[i]=NULL; @@ -84,7 +118,7 @@ extern vt_t *vt_open(int sock, const char *dev) tcsetattr(vt->in,TCSANOW,&tio); } else { - vt->type=1; + vt->type=VT_TYPE_TELNET; vt->in=vt->out=sock; /* send telnet character mode */ @@ -106,12 +140,20 @@ extern void vt_close(vt_t *vt) int i; trace(3,"vt_close:\n"); - - /* restore terminal mode */ - if (!vt->type) { - tcsetattr(vt->in,TCSANOW,&vt->tio); + switch ( vt->type ) { + case VT_TYPE_DEV: + tcsetattr(vt->in,TCSANOW,&vt->tio); + close(vt->in); + break; + case VT_TYPE_TELNET: + close(vt->in); + break; + default: + case VT_TYPE_STDOUT: + tcsetattr(vt->in,TCSANOW,&vt->tio); + break; + } - close(vt->in); if (vt->logfp) fclose(vt->logfp); for (i=0;ihist[i]); @@ -273,7 +315,7 @@ extern int vt_getc(vt_t *vt, char *c) if (!(stat=select(vt->in+1,&rs,NULL,NULL,&tv))) return 1; /* no data */ if (stat<0||read(vt->in,c,1)!=1) return 0; /* error */ - if ((vt->type&&*c==C_IAC)||*c==C_ESC) { /* escape or telnet */ + if (( (vt->type==VT_TYPE_TELNET)&&*c==C_IAC)||*c==C_ESC) { /* escape or telnet */ vt->esc[0]=*c; *c='\0'; vt->nesc=1; } diff --git a/app/consapp/rtkrcv/vt.h b/app/consapp/rtkrcv/vt.h index c7bf15b70..4756565f3 100644 --- a/app/consapp/rtkrcv/vt.h +++ b/app/consapp/rtkrcv/vt.h @@ -15,9 +15,15 @@ #define MAXHIST 256 /* size of history buffer */ /* type definitions ----------------------------------------------------------*/ +typedef enum { + VT_TYPE_DEV = 0, + VT_TYPE_TELNET = 1, + VT_TYPE_STDOUT = 2 +} vt_type_t; + typedef struct vt_tag { /* virtual console type */ int state; /* state(0:close,1:open) */ - int type; /* type (0:dev,1:telnet) */ + vt_type_t type; /* type (0:dev,1:telnet,2:stdout) */ int in,out; /* input/output file descriptor */ int n,nesc; /* number of line buffer/escape */ int cur; /* cursor position */ @@ -33,6 +39,7 @@ typedef struct vt_tag { /* virtual console type */ /* function prototypes -------------------------------------------------------*/ extern vt_t *vt_open(int sock, const char *dev); +extern vt_t *vt_open_stdout(); extern void vt_close(vt_t *vt); extern int vt_getc(vt_t *vt, char *c); extern int vt_gets(vt_t *vt, char *buff, int n);