Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions app/consapp/rtkrcv/rtkrcv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ static void *con_thread(void *arg)
}
}
vt_close(con->vt);
con->vt = NULL;
return 0;
}
/* open console --------------------------------------------------------------*/
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
58 changes: 50 additions & 8 deletions app/consapp/rtkrcv/vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;i<MAXHIST;i++) {
vt->hist[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
Expand All @@ -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;i<MAXHIST;i++) {
vt->hist[i]=NULL;
Expand All @@ -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 */
Expand All @@ -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;i<MAXHIST;i++) {
free(vt->hist[i]);
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion app/consapp/rtkrcv/vt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand Down