]> code.delx.au - gnu-emacs/blobdiff - src/filelock.c
(Fnext_property_change): Properly offset interval
[gnu-emacs] / src / filelock.c
index 116f96eacd157e85a8b98763b3fae2c8986b0e67..6876cbdb5c1991af5cd72066f031451e062bbbfd 100644 (file)
@@ -20,6 +20,7 @@ Boston, MA 02111-1307, USA.  */
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <signal.h>
 #include <config.h>
 
 #ifdef VMS
@@ -34,17 +35,24 @@ Boston, MA 02111-1307, USA.  */
 #include <string.h>
 #endif /* USG */
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #include "lisp.h"
 #include "buffer.h"
+#include "charset.h"
+#include "coding.h"
 
 #include <time.h>
-#include <utmp.h>
 #include <errno.h>
 #ifndef errno
 extern int errno;
 #endif
 
 #ifdef CLASH_DETECTION
+
+#include <utmp.h>
   
 /* The strategy: to lock a file FN, create a symlink .#FN in FN's
    directory, with link data `user@host.pid'.  This avoids a single
@@ -96,16 +104,30 @@ get_boot_time ()
     return boot_time;
 
   utmpname ("/var/log/wtmp");
-  ut.ut_type = BOOT_TIME;
-  utp = getutid (&ut);
+  setutent ();
+  boot_time = 1;
+  while (1)
+    {
+      /* Find the next reboot record.  */
+      ut.ut_type = BOOT_TIME;
+      utp = getutid (&ut);
+      if (! utp)
+       break;
+      /* Compare reboot times and use the newest one.  */
+      if (utp->ut_time > boot_time)
+       boot_time = utp->ut_time;
+      /* Advance on element in the file
+        so that getutid won't repeat the same one.  */
+      utp = getutent ();
+      if (! utp)
+       break;
+    }
   endutent ();
 
-  if (!utp)
-    return boot_time = 1;
-  return boot_time = utp->ut_time;
+  return boot_time;
 #else
   return 0;
-#endif;
+#endif
 }
 \f
 /* Here is the structure that stores information about a lock.  */
@@ -129,7 +151,7 @@ typedef struct
 /* Write the name of the lock file for FN into LFNAME.  Length will be
    that of FN plus two more for the leading `.#' plus one for the null.  */
 #define MAKE_LOCK_NAME(lock, file) \
-  (lock = (char *) alloca (XSTRING (file)->size_byte + 2 + 1), \
+  (lock = (char *) alloca (STRING_BYTES (XSTRING (file)) + 2 + 1), \
    fill_in_lock_file_name (lock, (file)))
 
 static void
@@ -362,27 +384,34 @@ lock_if_free (clasher, lfname)
 
 void
 lock_file (fn)
-    register Lisp_Object fn;
+     Lisp_Object fn;
 {
-  register Lisp_Object attack, orig_fn;
+  register Lisp_Object attack, orig_fn, encoded_fn;
   register char *lfname, *locker;
   lock_info_type lock_info;
 
   orig_fn = fn;
   fn = Fexpand_file_name (fn, Qnil);
+  encoded_fn = ENCODE_FILE (fn);
 
   /* Create the name of the lock-file for file fn */
-  MAKE_LOCK_NAME (lfname, fn);
+  MAKE_LOCK_NAME (lfname, encoded_fn);
 
   /* See if this file is visited and has changed on disk since it was
      visited.  */
   {
     register Lisp_Object subject_buf;
+    struct gcpro gcpro1;
+
     subject_buf = get_truename_buffer (orig_fn);
+    GCPRO1 (fn);
+
     if (!NILP (subject_buf)
        && NILP (Fverify_visited_file_modtime (subject_buf))
        && !NILP (Ffile_exists_p (fn)))
       call1 (intern ("ask-user-about-supersession-threat"), fn);
+
+    UNGCPRO;
   }
 
   /* Try to lock the lock. */
@@ -414,6 +443,7 @@ unlock_file (fn)
   register char *lfname;
 
   fn = Fexpand_file_name (fn, Qnil);
+  fn = ENCODE_FILE (fn);
 
   MAKE_LOCK_NAME (lfname, fn);
 
@@ -514,6 +544,7 @@ t if it is locked by you, else a string of the name of the locker.")
 \f
 /* Initialization functions.  */
 
+void
 syms_of_filelock ()
 {
   defsubr (&Sunlock_buffer);