#include #include #include #include #include #include #include #include #include #include "mconsole.m" static struct termios origterm; static void vconsole_setterm() { tcsetattr (0,TCSANOW,&origterm); } int main (int argc, char *argv[]) { glocal const char *sockpath = "/var/run/mconsole.sock"; glocal bool openlog = false; glocal bool dump = false; glocal const char *logfile = NULL; int ret = (argc,argv,"mconsole"); setproginfo ("vconsole",PACKAGE_REV ,MSG_U(I_VCONSOLE,"View one serial console using the mconsole server\n" "\n" "vconsole name\n" "name is serial port (argument passed to mconsole)\n" "\n" "Use control-x to send a BREAK sequence\n")); setarg ('l',"logfile",MSG_U(I_LOGFILE,"Log the session to a file"),glocal.logfile,false); setarg ('d',"dump",MSG_U(I_DUMP,"Dump status of the mconsole server"),glocal.dump,false); setarg ('o',"reopenlog",MSG_U(I_OPENLOG,"Request mconsole to close and reopen its logfiles"),glocal.openlog,false); setarg ('s',"socket",MSG_U(I_SOCKET,"Unix socket path"),glocal.sockpath,false); fprintf (stderr,"%s\n",msg); if (glocal.openlog || glocal.dump){ ("unix:",glocal.sockpath,10); if (glocal.openlog){ sendf ("openlog\n"); } if (glocal.dump){ sendf ("dump\n"); } printf ("%s\n",line); }else{ usage(); } glocal int ret = -1; if (argc != 1){ tlmp_error (MSG_U(E_SERIAL,"One serial device name needed")); }else{ glocal FILE *flog = NULL; glocal const char *tty = argv[0]; if (glocal.logfile != NULL){ glocal.flog = fopen (glocal.logfile,"a"); if (glocal.flog == NULL){ tlmp_error (MSG_U(E_OPENLOGFILE,"Can't open log file %s (%s)\n") ,glocal.logfile,strerror(errno)); } } debug_printf("tty=%s\n",glocal.tty); debug_printf("tty2=%s\n",glocal.sockpath); ("unix:",glocal.sockpath); glocal.ret = 0; sendf ("connect %s\n",glocal.tty); setrawmode(true); write (1,line,info.linelen); if (glocal.flog != NULL){ fwrite (line,1,info.linelen,glocal.flog); fflush (glocal.flog); } tlmp_error (MSG_U(E_CANTCONNECT ,"Can't connect to mconsole server at %s\n") ,glocal.sockpath); exit (-1); exit (-1); { struct termios term; tcgetattr (0,&term); tcgetattr (0,&origterm); atexit (vconsole_setterm); cfmakeraw (&term); tcsetattr (0,TCSANOW,&term); } glocal TCPCONNECT *s = &serv; (0); #if 0 for (int i=0; i\n"); #endif if (line[0] == 'x' - 'a' + 1){ if (glocal.flog != NULL) fclose (glocal.flog); exit(0); } glocal.s->send (line,info.linelen); tty.setrawmode (true); (); ev.add (serv); ev.add (tty); ev.loop(10); } return glocal.ret; return 0; return ret; }