From: james Date: Fri, 15 Feb 2008 23:52:12 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=sympathy.git;a=commitdiff_plain;h=ded21942fccb9fde8c3264c8f9a3dcdbc6ae1c38 *** empty log message *** --- diff --git a/apps/clients.c b/apps/clients.c index 01d5995..04aafc1 100644 --- a/apps/clients.c +++ b/apps/clients.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.7 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.6 2008/02/15 03:32:07 james * *** empty log message *** * @@ -56,6 +59,9 @@ client_msg (IPC_Msg * m, Context * c) case IPC_MSG_TYPE_SETFLOW: tty_set_flow (c->t, m->setflow.flow); break; + case IPC_MSG_TYPE_HANGUP: + tty_hangup (c->t); + break; default: fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); } diff --git a/apps/sympathyd.c b/apps/sympathyd.c index bdf8132..65ef1f9 100644 --- a/apps/sympathyd.c +++ b/apps/sympathyd.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.13 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.12 2008/02/15 03:32:07 james * *** empty log message *** * @@ -196,6 +199,7 @@ do_line (char *ptr, int lines, int line) return ptr; lname = line_to_name (line); + *(ptr++) = ' '; while (*lname) *(ptr++) = *(lname++); @@ -292,7 +296,8 @@ main (int argc, char *argv[]) s = socket_listen ("socket"); - c.t = ptty_open (NULL, NULL); +// c.t = ptty_open (NULL, NULL); + c.t = serial_open ("/dev/cellmodem", 0); c.v = vt102_new (); c.h = history_new (200); c.l = file_log_new ("log"); diff --git a/src/cmd.c b/src/cmd.c index 6017ccb..bf5be83 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.1 2008/02/15 15:14:19 james * *** empty log message *** * @@ -32,6 +35,8 @@ cmd_parse (Cmd * c, Context * ctx, char *buf) ctx->k->set_baud (ctx->k, ctx, atoi (buf + 4)); if (!strncmp (buf, "break", 4)) ctx->k->send_break (ctx->k, ctx); + if (!strncmp (buf, "hangup", 4)) + ctx->k->hangup (ctx->k, ctx); } diff --git a/src/ipc.c b/src/ipc.c index 2a3ad7c..b30bef0 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.2 2008/02/15 03:32:07 james * *** empty log message *** * @@ -188,3 +191,13 @@ ipc_msg_send_setflow (Socket * s, int flow) m.flow = flow; return ipc_msg_send (s, (IPC_Msg *) & m); } + +int +ipc_msg_send_hangup (Socket * s) +{ + IPC_Msg_hangup m; + + m.size = sizeof (m); + m.type = IPC_MSG_TYPE_HANGUP; + return ipc_msg_send (s, (IPC_Msg *) & m); +} diff --git a/src/ipc.h b/src/ipc.h index b83f736..2713de7 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.3 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.2 2008/02/15 03:32:07 james * *** empty log message *** * @@ -35,6 +38,7 @@ #define IPC_MSG_TYPE_SETBAUD 7 #define IPC_MSG_TYPE_SENDBREAK 8 #define IPC_MSG_TYPE_SETFLOW 9 +#define IPC_MSG_TYPE_HANGUP 10 typedef struct { @@ -120,6 +124,13 @@ typedef struct } IPC_Msg_setflow; +typedef struct +{ + int32_t size; + int32_t type; +} IPC_Msg_hangup; + + typedef union { @@ -134,6 +145,7 @@ IPC_Msg_status status; IPC_Msg_setbaud setbaud; IPC_Msg_sendbreak sendbreak; IPC_Msg_setflow setflow; +IPC_Msg_hangup hangup; } IPC_Msg; diff --git a/src/keydis.c b/src/keydis.c index 33eef20..c8883a7 100644 --- a/src/keydis.c +++ b/src/keydis.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.2 2008/02/15 03:32:07 james * *** empty log message *** * @@ -83,6 +86,17 @@ keydis_ipc_set_flow (KeyDis * _t, Context * c, int flow) return 0; } + +static int +keydis_ipc_hangup (KeyDis * _t, Context * c) +{ + KeyDis_IPC *t = (KeyDis_IPC *) _t; + + ipc_msg_send_hangup (t->s); + + return 0; +} + static int keydis_vt102_key (KeyDis * _t, Context * c, int key) { @@ -123,6 +137,17 @@ keydis_vt102_set_flow (KeyDis * _t, Context * c, int flow) } +static int +keydis_vt102_hangup (KeyDis * _t, Context * c) +{ + KeyDis_VT102 *t = (KeyDis_VT102 *) _t; + + tty_hangup (c->t); + + return 0; +} + + KeyDis * keydis_vt102_new (void) @@ -133,6 +158,7 @@ keydis_vt102_new (void) t->set_baud = keydis_vt102_set_baud; t->send_break = keydis_vt102_send_break; t->set_flow = keydis_vt102_set_flow; + t->hangup = keydis_vt102_hangup; return (KeyDis *) t; } @@ -146,6 +172,7 @@ keydis_ipc_new (Socket * s) t->set_baud = keydis_ipc_set_baud; t->send_break = keydis_ipc_send_break; t->set_flow = keydis_ipc_set_flow; + t->hangup = keydis_ipc_hangup; t->s = s; return (KeyDis *) t; } diff --git a/src/keydis.h b/src/keydis.h index dafc5da..4ccfb7d 100644 --- a/src/keydis.h +++ b/src/keydis.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.3 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.2 2008/02/15 03:32:07 james * *** empty log message *** * @@ -34,7 +37,8 @@ struct Context_struct; int (*key)(struct KeyDis_struct *,struct Context_struct *,int key); \ int (*set_baud)(struct KeyDis_struct *,struct Context_struct *,int rate); \ int (*send_break)(struct KeyDis_struct *,struct Context_struct *); \ - int (*set_flow)(struct KeyDis_struct *,struct Context_struct *,int flow) + int (*set_flow)(struct KeyDis_struct *,struct Context_struct *,int flow); \ + int (*hangup)(struct KeyDis_struct *,struct Context_struct *) diff --git a/src/lockfile.c b/src/lockfile.c index b325274..ce37079 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.9 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.8 2008/02/15 20:52:36 james * *** empty log message *** * @@ -39,6 +42,8 @@ static char rcsid[] = "$Id$"; #define LOCK_ASCII #undef LOCK_BINARY +#define STALE_CHECK_INTERVAL 10 + #include #include #include @@ -51,6 +56,8 @@ static char rcsid[] = "$Id$"; #include #include #include +#include +#include #include "lockfile.h" @@ -208,7 +215,7 @@ lockfile_add_places (Filelist * fl, char *leaf) char *lock_dirs[] = { "/var/lock/uucp", "/var/spool/lock", "/var/spool/uucp", "/etc/locks", "/usr/spool/uucp", "/var/spool/locks", "/usr/spool/lock", - "/usr/spool/locks", "/usr/spool/uucp/LCK" + "/usr/spool/locks", "/usr/spool/uucp/LCK", "/var/lock" }; int i; @@ -457,7 +464,7 @@ serial_lock_check (Serial_lock * l) if (l->mode == SERIAL_LOCK_ACTIVE) return 0; - for (fle = l->locks_to_check; fle; fle = fle->next) + for (fle = l->locks_to_check->head; fle; fle = fle->next) { if (!stat (fle->name, &buf)) locks_found++; @@ -466,7 +473,7 @@ serial_lock_check (Serial_lock * l) if (!locks_found) return 0; - getimeofday (&now, NULL); + gettimeofday (&now, NULL); timersub (&now, &l->last_stale_purge, &dif); if (dif.tv_sec > STALE_CHECK_INTERVAL) @@ -503,10 +510,13 @@ Serial_lock * serial_lock_new (char *dev, int mode) { Filelist *fl = lockfile_make_list (dev); + Serial_lock *l; if (!fl) return NULL; + l = (Serial_lock *) malloc (sizeof (Serial_lock)); + l->mode = mode; l->locks_to_check = fl; l->locks_held = NULL; @@ -526,7 +536,7 @@ serial_lock_new (char *dev, int mode) } -#if 1 +#if 0 int main (int argc, char *argv[]) { diff --git a/src/lockfile.h b/src/lockfile.h index ddfdd25..eb089ed 100644 --- a/src/lockfile.h +++ b/src/lockfile.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.6 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.5 2008/02/15 20:52:36 james * *** empty log message *** * @@ -52,8 +55,8 @@ typedef struct int mode; int i; struct timeval last_stale_purge; - Filelist locks_to_check; - Filelist locks_held; + Filelist *locks_to_check; + Filelist *locks_held; } Serial_lock; diff --git a/src/ptty.c b/src/ptty.c index 63d1e44..1e3ce36 100644 --- a/src/ptty.c +++ b/src/ptty.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.5 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.4 2008/02/14 10:39:14 james * *** empty log message *** * @@ -168,6 +171,7 @@ ptty_open (char *path, char *argv[]) t->size.x = winsize.ws_row; t->size.y = winsize.ws_col; t->blocked = 0; + t->hanging_up = 0; return (TTY *) t; } diff --git a/src/serial.c b/src/serial.c index 2e67d3d..bd4450c 100644 --- a/src/serial.c +++ b/src/serial.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.7 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.6 2008/02/15 19:51:30 james * *** empty log message *** * @@ -79,6 +82,7 @@ serial_close (TTY * _t) if (!t) return; + tcflush (t->fd, TCIOFLUSH); close (t->fd); free (t); } @@ -116,7 +120,7 @@ serial_read (TTY * _t, void *buf, int len) static int -ptty_write (TTY * _t, void *buf, int len) +serial_write (TTY * _t, void *buf, int len) { int writ, done = 0; Serial *t = (Serial *) _t; @@ -161,7 +165,7 @@ serial_open (char *path, int lock_mode) default_termios (&termios); - fd = open (path, O_RDWR); + fd = open (path, O_RDWR | O_NOCTTY | O_NONBLOCK); set_nonblocking (fd); @@ -173,7 +177,7 @@ serial_open (char *path, int lock_mode) t->name[sizeof (t->name) - 1] = 0; t->recv = serial_read; - //t->xmit = serial_write; + t->xmit = serial_write; t->close = serial_close; t->fd = fd; t->rfd = t->fd; @@ -181,6 +185,7 @@ serial_open (char *path, int lock_mode) t->size.x = VT102_COLS; t->size.y = VT102_ROWS; t->blocked = serial_lock_check (t->lock); + t->hanging_up = 0; return (TTY *) t; } diff --git a/src/tty.c b/src/tty.c index 82fd9ed..de1bdca 100644 --- a/src/tty.c +++ b/src/tty.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.10 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.9 2008/02/15 03:32:07 james * *** empty log message *** * @@ -210,6 +213,25 @@ baud_to_speed_t (int baud) void tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds) { + int line; + struct timeval now, dif; + + if (t->hanging_up) + { + + gettimeofday (&now, NULL); + timersub (&now, &t->hangup_clock, &dif); + if (dif.tv_sec) + { + fprintf (stderr, "+DTR\n"); + + line = TIOCM_DTR; + ioctl (t->rfd, TIOCMBIS, &line); + t->hanging_up = 0; + } + } + + FD_SET (t->rfd, rfds); } @@ -219,6 +241,8 @@ tty_get_status (TTY * t, TTY_Status * s) s->lines = 0; ioctl (t->rfd, TIOCMGET, &s->lines); + if (t->hanging_up) + fprintf (stderr, "s->lines & TIOCM_DTR=%x\n", s->lines & TIOCM_DTR); if (tcgetattr (t->rfd, &s->termios)) return -1; @@ -271,6 +295,20 @@ tty_set_flow (TTY * t, int flow) } +void +tty_hangup (TTY * t) +{ + int line; + + line = TIOCM_DTR; + ioctl (t->rfd, TIOCMBIC, &line); + + t->hanging_up = 1; + gettimeofday (&t->hangup_clock, NULL); + fprintf (stderr, "-DTR\n"); + +} + #if 0 int diff --git a/src/tty.h b/src/tty.h index 9b73c9c..2ad1003 100644 --- a/src/tty.h +++ b/src/tty.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.8 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.7 2008/02/14 10:36:18 james * *** empty log message *** * @@ -46,7 +49,9 @@ int (*recv)(struct TTY_struct *,void *buf,int len); \ int (*xmit)(struct TTY_struct *,void *buf,int len); \ int rfd; \ - int wfd + int wfd; \ + int hanging_up; \ + struct timeval hangup_clock typedef struct TTY_struct { diff --git a/test/test.c b/test/test.c index af12ee9..8cb6be1 100644 --- a/test/test.c +++ b/test/test.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.6 2008/02/15 23:52:12 james + * *** empty log message *** + * * Revision 1.5 2008/02/14 10:34:30 james * *** empty log message *** * @@ -52,7 +55,7 @@ main (int argc, char *argv[]) c.v = vt102_new (); c.h = history_new (200); c.l = file_log_new ("log"); - c.k = keydis_vt102_new (&c); + c.k = keydis_vt102_new (); terminal_register_handlers (); a.terminal = terminal_open (0, 1);