chiark / gitweb /
*** empty log message ***
authorjames <james>
Thu, 14 Feb 2008 16:21:17 +0000 (16:21 +0000)
committerjames <james>
Thu, 14 Feb 2008 16:21:17 +0000 (16:21 +0000)
apps/sympathyd.c
src/Makefile.am
src/serial.c

index 41a39f270297dcf151f221487bd2656309c3b2e0..81ea2f010ccc23ecc30caeee316cda7ac21f3714 100644 (file)
@@ -11,6 +11,9 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.11  2008/02/14 16:21:17  james
+ * *** empty log message ***
+ *
  * Revision 1.10  2008/02/14 10:39:14  james
  * *** empty log message ***
  *
@@ -274,6 +277,9 @@ main (int argc, char *argv[])
   Clients *clients;
 
 
+       construct_possible_lock_files("/dev/modem");
+       return 0;
+
   s = socket_listen ("socket");
 
   c.t = ptty_open (NULL, NULL);
index 92a0e88a76ebccb891428a7aefdcf3c60217b118..c783d064faf33a0a1d850107feb4d7434a4b8566 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.13  2008/02/14 16:21:17  james
+# *** empty log message ***
+#
 # Revision 1.12  2008/02/14 02:46:44  james
 # *** empty log message ***
 #
 
 INCLUDES=
 
-PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h log.h ipc.h symsocket.h keydis.h context.h  prototypes.h
+# NB order here matters.
+PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h \
+               log.h ipc.h symsocket.h keydis.h context.h prototypes.h
 
 HDRS=project.h 
 
-SRCS=ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c keydis.c \
-       history.c ring.c ptty.c terminal.c util.c log.c ipc.c slide.c symsocket.c
+SRCS=ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c \
+       keydis.c history.c ring.c ptty.c terminal.c util.c log.c ipc.c \
+       slide.c symsocket.c  serial.c
 
 CPROTO=cproto
 
index 5fff1bd5a9409a9f177e4d1e0eb66ba61b12cc68..c8e2295190d42fa74955c9873bf50d413e298b08 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ptty.c:
+ * serial.c:
  *
  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
  * All rights reserved.
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/14 16:21:17  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/14 12:51:14  james
  * *** empty log message ***
  *
@@ -43,20 +46,151 @@ static char rcsid[] = "$Id$";
  */
 
 #include "project.h"
+#include <pwd.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#define LOCK_ASCII
+#undef LOCK_BINARY
+
+#define NLOCKFILES     10
 
+typedef struct {
+char *lockfiles[NLOCKFILES];
+char *potential_lockfiles[NLOCKFILES];
+struct timeval last_content_check;
+} Serial_lock;
 
 typedef struct
 {
   TTY_SIGNATURE;
+  Serial_lock lock;
   int fd;
-  pid_t child;
-} PTTY;
+} Serial;
+
+
+
+static int
+chown_uucp(fd)
+int fd;
+{
+    static int uuid = -1, ugid;
+    struct passwd *pw;
+
+    if (uuid <0) {
+        if (pw = getpwnam("uucp")) {
+            uuid = pw->pw_uid;
+            ugid = pw->pw_gid;
+        } else {
+               return -1;
+       }
+    }
+    return fchown(fd, uuid, ugid);
+}
+
+int make_lockfile(char *name)
+{
+char buf[1024],tmpfn[1024];
+char *ptr;
+int fd;
+int i;
+
+strcpy(tmpfn,name);
+
+ptr=rindex(tmpfn,'/');
+if (!ptr) return -1;
+
+ptr++;
+
+ptr+=sprintf(ptr,"LTMP.%d",getpid());
+*ptr=0;
+
+i=sprintf(buf,"%10d\n",getpid());
+
+fd=open(tmpfn,O_WRONLY|O_CREAT|O_TRUNC,0444);
+if (fd<0) {
+       unlink(tmpfn);
+       return -1;
+}
+
+write(fd,buf,i);
+fchmod(fd,044);
+if( chown_uucp(fd)) {
+       close(fd);
+       unlink(tmpfn);
+       return -1;
+}
+
+close(fd);
+
+if (link(tmpfn,name)<0) {
+       unlink(tmpfn);
+       return -1;
+}
+
+unlink(tmpfn);
+return 0;
+}
+
+
+
+void construct_lock_file_name_by_name(char *ptr)
+{
+
+printf("lock by file %s\n",ptr);
+
+}
+void construct_lock_file_name_by_device(dev_t dev)
+{
+
+printf("lock by dev %x\n",dev);
+}
+
+
+#define DEV "/dev/"
+int construct_possible_lock_files(char *device)
+{
+int nl;
+struct dirent *de;
+DIR *d;
+struct stat dev_stat,ent_stat;
+char buf[1024];
+
+
+if (stat(device,&dev_stat)) return -1;
+if (!S_ISCHR(dev_stat.st_mode)) return -1;
+
+construct_lock_file_name_by_device(dev_stat.st_rdev);
+
+construct_lock_file_name_by_name(device);
+
+for (d=opendir(DEV);(de=readdir(d));)
+{
+strcpy(buf,DEV);
+strcat(buf,de->d_name);
+
+if (stat(buf,&ent_stat)) continue;
+if (!S_ISCHR(ent_stat.st_mode)) continue;
+if (ent_stat.st_rdev!=dev_stat.st_rdev) continue;
+
+construct_lock_file_name_by_name(buf);
+
+}
+closedir(d);
+
+}
+
+
+static void 
+serial_check_lock(Serial *t)
+{
+}
 
 
 static void
-ptty_close (TTY * _t)
+serial_close (TTY * _t)
 {
-  PTTY *t = (PTTY *) _t;
+  Serial *t = (Serial *) _t;
 
   if (!t)
     return;
@@ -68,11 +202,14 @@ ptty_close (TTY * _t)
 
 
 static int
-ptty_read (TTY * _t, void *buf, int len)
+serial_read (TTY * _t, void *buf, int len)
 {
-  PTTY *t = (PTTY *) _t;
+  Serial *t = (Serial *) _t;
   int red, done = 0;
 
+  serial_check_lock(t);
+  if (t->blocked) return 0;
+
   do
     {
 
@@ -97,7 +234,10 @@ static int
 ptty_write (TTY * _t, void *buf, int len)
 {
   int writ, done = 0;
-  PTTY *t = (PTTY *) _t;
+  Serial *t = (Serial *) _t;
+
+  serial_check_lock(t);
+  if (t->blocked) return 0;
 
   do
     {
@@ -119,57 +259,35 @@ ptty_write (TTY * _t, void *buf, int len)
 }
 
 TTY *
-ptty_open (char *path, char *argv[])
+serial_open (char *path)
 {
-  PTTY *t;
+  Serial *t;
   pid_t child;
   char name[1024];
   struct winsize winsize = { 0 };
   struct termios termios;
   int fd;
-  char *default_argv[] = { "-", (char *) 0 };
 
 
   default_termios (&termios);
 
-  winsize.ws_row = VT102_ROWS;
-  winsize.ws_col = VT102_COLS;
-
-  child = forkpty (&fd, name, &termios, &winsize);
-
-  switch (child)
-    {
-    case -1:                   /*boo hiss */
-      return NULL;
-    case 0:                    /*waaah */
-      setenv ("TERM", "vt102", 1);
-      setenv ("LANG", "C", 1);
-      if (!path)
-        path = "/bin/sh";
-
-      if (!argv)
-        argv = default_argv;
-
-      execv (path, argv);
-      _exit (-1);
-    }
+  fd=open(path,O_RDWR);
 
   set_nonblocking (fd);
 
-  t = (PTTY *) malloc (sizeof (PTTY));
+  t = (Serial *) malloc (sizeof (Serial));
 
-  strncpy (t->name, name, sizeof (t->name));
+  strncpy (t->name, path, sizeof (t->name));
   t->name[sizeof (t->name) - 1] = 0;
 
-  t->recv = ptty_read;
-  t->xmit = ptty_write;
-  t->close = ptty_close;
+  t->recv = serial_read;
+  //t->xmit = serial_write;
+  t->close = serial_close;
   t->fd = fd;
-  t->child = child;
   t->rfd = t->fd;
   t->wfd = t->fd;
-  t->size.x = winsize.ws_row;
-  t->size.y = winsize.ws_col;
+  t->size.x = VT102_COLS;
+  t->size.y = VT102_ROWS;
   t->blocked = 0;
 
   return (TTY *) t;