chiark / gitweb /
*** empty log message ***
authorjames <james>
Fri, 15 Feb 2008 23:52:12 +0000 (23:52 +0000)
committerjames <james>
Fri, 15 Feb 2008 23:52:12 +0000 (23:52 +0000)
14 files changed:
apps/clients.c
apps/sympathyd.c
src/cmd.c
src/ipc.c
src/ipc.h
src/keydis.c
src/keydis.h
src/lockfile.c
src/lockfile.h
src/ptty.c
src/serial.c
src/tty.c
src/tty.h
test/test.c

index 01d5995a94ddf0cab9b79cf6224e177a75dc1541..04aafc1706b67b5e31082605bc18d6a743c31dcc 100644 (file)
@@ -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);
     }
index bdf81323008ab1e7967169d7d91c814bcc677493..65ef1f99ab655294d4d3d8772a75caedd5d04388 100644 (file)
@@ -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");
index 6017ccb488b051f0068597dee371bb59d3869a6d..bf5be83ebba0f06d22824ad12cfa2842f2635140 100644 (file)
--- 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);
 
 }
 
index 2a3ad7c62146ee56ea11cd7ecc92022b81696ca1..b30bef00d93a3d9a7f03da00a00679a32412b45f 100644 (file)
--- 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);
+}
index b83f7369941d68bb6ea497f3e8ccc0b8e6c79e18..2713de7a35e266cff68f9a4202605fe02039ad68 100644 (file)
--- 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;
 
 
index 33eef20c7d9278880c118242041f2df5016b1a70..c8883a7f5fabccb65b5c9f215c25d9c86ce454bf 100644 (file)
@@ -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;
 }
index dafc5da7c8432d5e14e14ee72624f719d5ff34ce..4ccfb7d15da41dd304590e447356f7993816d920 100644 (file)
@@ -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 *)
 
        
 
index b3252746a902fcb82aa01be5e9d5bbaaa26bac6a..ce37079bf4eff7b3b54c540f50ccb6be4d49a00c 100644 (file)
@@ -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 <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -51,6 +56,8 @@ static char rcsid[] = "$Id$";
 #include <fcntl.h>
 #include <dirent.h>
 #include <errno.h>
+#include <time.h>
+#include <sys/time.h>
 
 #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[])
 {
index ddfdd25a4d494e4f39db1c3c667f5658d8a0735c..eb089edb5a89f44dd48d173f7fb7dc05b1a30d1e 100644 (file)
@@ -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;
 
 
index 63d1e44738f7ff240a1523d898f42995e686b75c..1e3ce3693d6bf4a081f5313c336a2b7f516adeb4 100644 (file)
@@ -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;
 }
index 2e67d3dd75e5f465876a37784baf64070dea991f..bd4450cfa92738e7fc0c0e30e67124179aa647a6 100644 (file)
@@ -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;
 }
index 82fd9edc3f5df683ce7a38f135455a085041c699..de1bdcaf6b4b096a07ff1ac7c84f2c7eaafb0f77 100644 (file)
--- 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
index 9b73c9c1497057053390797157c740540306d304..2ad10038c2da971f4afe2c6f97866eaff9c186c7 100644 (file)
--- 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
 {
index af12ee9857acb021ab49e91eb914f6ecfe50facc..8cb6be13751e84f8610bc6d5260e8894e79db235 100644 (file)
@@ -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);