chiark / gitweb /
*** empty log message ***
authorjames <james>
Fri, 15 Feb 2008 16:48:56 +0000 (16:48 +0000)
committerjames <james>
Fri, 15 Feb 2008 16:48:56 +0000 (16:48 +0000)
src/Makefile.am
src/lockfile.c
src/lockfile.h
src/serial.c

index 2f99fe0035e2f3e070913e1e2799aec90b6a74d1..d162ccd2c7936da9b511161dd89dec682ca90fde 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.15  2008/02/15 16:48:56  james
+# *** empty log message ***
+#
 # Revision 1.14  2008/02/15 03:32:07  james
 # *** empty log message ***
 #
@@ -58,14 +61,14 @@ INCLUDES=
 
 # 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 cmd.h context.h \
+               log.h ipc.h symsocket.h keydis.h cmd.h lockfile.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  serial.c cmd.c
+       slide.c symsocket.c  serial.c cmd.c lockfile.c
 
 CPROTO=cproto
 
index 4f94c579601082c945a396bc1bcdd86cb6855049..9dd292554c7fea557ea765096d5e5b4b00088a11 100644 (file)
@@ -10,8 +10,160 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/15 16:48:56  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/15 15:09:17  james
  * *** empty log message ***
  *
  */
 
+#define LOCK_ASCII
+#undef LOCK_BINARY
+
+
+Filelist *filelist_new(void)
+{
+
+
+
+}
+
+
+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
+lockfile_make
+{
+  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
+lockfile_add_name_from_path (File_list *fl,char *ptr)
+{
+  printf ("lock by file %s\n", ptr);
+}
+
+void
+lockfile_add_name_from_dev (File_list *fl,dev_t dev)
+{
+  printf ("lock by dev %x\n", dev);
+}
+
+void lockfile_check_dir_for_dev(File_list *fl,char *dir,dev_t dev)
+{
+  char buf[1024];
+  struct stat ent_stat;
+  struct dirent *de;
+  DIR *d;
+
+  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)
+        continue;
+
+      lockfile_add_name_from_path (fl,buf);
+
+    }
+  closedir (d);
+}
+
+File_list *
+construct_possible_lock_files (char *device)
+{
+  struct stat dev_stat;
+  File_list *ret=NULL;
+
+
+  if (stat (device, &dev_stat))
+    return ret;
+  if (!S_ISCHR (dev_stat.st_mode))
+    return ret;
+
+  ret=filelist_new();
+
+  lockfile_add_name_from_dev (ret,dev_stat.st_rdev);
+
+  lockfile_add_name_from_path (ret,device);
+
+  lockfile_check_dir_for_dev(ret,"/dev/",dev_stat.st_rdev);
+  lockfile_check_dir_for_dev(ret,"/dev/usb/",dev_stat.st_rdev);
+  lockfile_check_dir_for_dev(ret,"/dev/tts/",dev_stat.st_rdev);
+
+  return ret;
+}
+
+
+
index 660490cbe03873ed3225c9083ef0ba4bdf087049..03d5ed31ef56f3f34bcb86d319ca86ca348e22c5 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/15 16:48:56  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/15 15:09:17  james
  * *** empty log message ***
  *
 #ifndef __LOCKFILE_H__
 #define __LOCKFILE_H__
 
+typedef struct Filelist_ent {
+       char name[1024];
+       struct Filelist_ent *next;
+} Filelist_ent;
+
+typedef struct {
+       Filelist_ent *head;
+} Filelist;
+
 #endif /* __LOCKFILE_H__ */
index c2c53b8d07eaa8b9a2e092c4ec45faf4c15a4ae7..429c2e3771652165ff34b27adb5202dd0d5742c0 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.4  2008/02/15 16:48:56  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/15 03:32:07  james
  * *** empty log message ***
  *
@@ -53,9 +56,6 @@ static char rcsid[] = "$Id$";
 #include <dirent.h>
 #include <sys/stat.h>
 
-#define LOCK_ASCII
-#undef LOCK_BINARY
-
 #define NLOCKFILES     10
 
 typedef struct
@@ -73,136 +73,6 @@ typedef struct
 } 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)
 {