annotate src/filelock.c @ 16698:13920eac02e0

(imenu-generic-expression): Doc fix. (imenu--make-index-alist): Do `widen' and save-restriction here. (imenu): Not here.
author Richard M. Stallman <rms@gnu.org>
date Mon, 16 Dec 1996 07:39:34 +0000
parents b7131e99a796
children 93fc7aff4cc2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7307
cd81dba38a49 Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6499
diff changeset
1 /* Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 This file is part of GNU Emacs.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 GNU Emacs is free software; you can redistribute it and/or modify
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 any later version.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 GNU Emacs is distributed in the hope that it will be useful,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 GNU General Public License for more details.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 along with GNU Emacs; see the file COPYING. If not, write to
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14075
diff changeset
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14075
diff changeset
18 Boston, MA 02111-1307, USA. */
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 #include <sys/types.h>
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 #include <sys/stat.h>
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4680
diff changeset
23 #include <config.h>
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 163
diff changeset
24
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 163
diff changeset
25 #ifdef VMS
559
65e7f842d017 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
26 #include "vms-pwd.h"
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 163
diff changeset
27 #else
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 #include <pwd.h>
372
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 163
diff changeset
29 #endif
481e29c1e27e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 163
diff changeset
30
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 #include <errno.h>
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 #include <sys/file.h>
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 #ifdef USG
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 #include <fcntl.h>
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 #endif /* USG */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 #include "lisp.h"
4701
05f6a91c2801 Include <paths.h>, not "paths.h".
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
38 #include <paths.h>
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 #include "buffer.h"
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
6300
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
41 #ifdef SYSV_SYSTEM_DIR
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
42 #include <dirent.h>
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
43 #else /* not SYSV_SYSTEM_DIR */
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
44 #ifdef NONSYSTEM_DIR_LIBRARY
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
45 #include "ndir.h"
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
46 #else /* not NONSYSTEM_DIR_LIBRARY */
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
47 #ifdef MSDOS
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
48 #include <dirent.h>
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
49 #else
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
50 #include <sys/dir.h>
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
51 #endif
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
52 #endif /* not NONSYSTEM_DIR_LIBRARY */
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
53 #ifndef MSDOS
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
54 extern DIR *opendir ();
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
55 #endif /* not MSDOS */
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
56 #endif /* not SYSV_SYSTEM_DIR */
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
57
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 extern int errno;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
60 extern char *egetenv ();
733
62dd28940dc6 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
61 extern char *strcpy ();
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
62
8776
290f584b7bb1 (getpwuid): Test just DECLARE_GETPWUID_WITH_UID_T, not __bsdi__.
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
63 #ifdef DECLARE_GETPWUID_WITH_UID_T
4618
e4a5c21eb300 (getpwuid): Declare it as in xrdb.c.
Richard M. Stallman <rms@gnu.org>
parents: 4275
diff changeset
64 extern struct passwd *getpwuid (uid_t);
e4a5c21eb300 (getpwuid): Declare it as in xrdb.c.
Richard M. Stallman <rms@gnu.org>
parents: 4275
diff changeset
65 #else
4272
41c85882768c (getpwuid): Declare at top level, and not if __386bsd__.
Richard M. Stallman <rms@gnu.org>
parents: 3602
diff changeset
66 extern struct passwd *getpwuid ();
41c85882768c (getpwuid): Declare at top level, and not if __386bsd__.
Richard M. Stallman <rms@gnu.org>
parents: 3602
diff changeset
67 #endif
41c85882768c (getpwuid): Declare at top level, and not if __386bsd__.
Richard M. Stallman <rms@gnu.org>
parents: 3602
diff changeset
68
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 #ifdef CLASH_DETECTION
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 /* If system does not have symbolic links, it does not have lstat.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 In that case, use ordinary stat instead. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 #ifndef S_IFLNK
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 #define lstat stat
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 #endif
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
78
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
79 /* The name of the directory in which we keep lock files, with a '/'
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
80 appended. */
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
81 char *lock_dir;
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
82
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
83 /* The name of the file in the lock directory which is used to
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
84 arbitrate access to the entire directory. */
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
85 #define SUPERLOCK_NAME "!!!SuperLock!!!"
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
86
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
87 /* The name of the superlock file. This is SUPERLOCK_NAME appended to
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
88 lock_dir. */
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
89 char *superlock_file;
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
90
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
91 /* Set LOCK to the name of the lock file for the filename FILE.
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
92 char *LOCK; Lisp_Object FILE; */
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
93
3602
f71f3f167365 * filelock.c: Test HAVE_LONG_FILE_NAMES, not SHORT_FILE_NAMES, to
Jim Blandy <jimb@redhat.com>
parents: 3537
diff changeset
94 #ifndef HAVE_LONG_FILE_NAMES
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
95
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
96 #define MAKE_LOCK_NAME(lock, file) \
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
97 (lock = (char *) alloca (14 + strlen (lock_dir) + 1), \
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
98 fill_in_lock_short_file_name (lock, (file)))
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
99
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
100
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
101 fill_in_lock_short_file_name (lockfile, fn)
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
102 register char *lockfile;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
103 register Lisp_Object fn;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
104 {
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
105 register union
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
106 {
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
107 unsigned int word [2];
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
108 unsigned char byte [8];
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
109 } crc;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
110 register unsigned char *p, new;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
111
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
112 /* 7-bytes cyclic code for burst correction on byte-by-byte basis.
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
113 the used polynomial is D^7 + D^6 + D^3 +1. pot@cnuce.cnr.it */
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
114
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
115 crc.word[0] = crc.word[1] = 0;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
116
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
117 for (p = XSTRING (fn)->data; new = *p++; )
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
118 {
4680
9d56bce1534a * filelock.c (fill_in_lock_short_file_name): corrected the crc
Francesco Potortì <pot@gnu.org>
parents: 4618
diff changeset
119 new += crc.byte[6];
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
120 crc.byte[6] = crc.byte[5] + new;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
121 crc.byte[5] = crc.byte[4];
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
122 crc.byte[4] = crc.byte[3];
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
123 crc.byte[3] = crc.byte[2] + new;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
124 crc.byte[2] = crc.byte[1];
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
125 crc.byte[1] = crc.byte[0];
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
126 crc.byte[0] = new;
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
127 }
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
128 sprintf (lockfile, "%s%.2x%.2x%.2x%.2x%.2x%.2x%.2x", lock_dir,
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
129 crc.byte[0], crc.byte[1], crc.byte[2], crc.byte[3],
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
130 crc.byte[4], crc.byte[5], crc.byte[6]);
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
131 }
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
132
3602
f71f3f167365 * filelock.c: Test HAVE_LONG_FILE_NAMES, not SHORT_FILE_NAMES, to
Jim Blandy <jimb@redhat.com>
parents: 3537
diff changeset
133 #else /* defined HAVE_LONG_FILE_NAMES */
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
134
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
135 #define MAKE_LOCK_NAME(lock, file) \
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
136 (lock = (char *) alloca (XSTRING (file)->size + strlen (lock_dir) + 1), \
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
137 fill_in_lock_file_name (lock, (file)))
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
138
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
139
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
140 fill_in_lock_file_name (lockfile, fn)
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
141 register char *lockfile;
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
142 register Lisp_Object fn;
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
143 {
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
144 register char *p;
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
145
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
146 strcpy (lockfile, lock_dir);
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
147
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
148 p = lockfile + strlen (lockfile);
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
149
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
150 strcpy (p, XSTRING (fn)->data);
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
151
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
152 for (; *p; p++)
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
153 {
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
154 if (*p == '/')
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
155 *p = '!';
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
156 }
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
157 }
3602
f71f3f167365 * filelock.c: Test HAVE_LONG_FILE_NAMES, not SHORT_FILE_NAMES, to
Jim Blandy <jimb@redhat.com>
parents: 3537
diff changeset
158 #endif /* !defined HAVE_LONG_FILE_NAMES */
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
159
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 static Lisp_Object
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 lock_file_owner_name (lfname)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 struct stat s;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 struct passwd *the_pw;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 if (lstat (lfname, &s) == 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 the_pw = getpwuid (s.st_uid);
15797
24c31fcbcf97 (lock_file_owner_name): Always initialize the_pw.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
169 else
24c31fcbcf97 (lock_file_owner_name): Always initialize the_pw.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
170 the_pw = 0;
24c31fcbcf97 (lock_file_owner_name): Always initialize the_pw.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
171
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 return (the_pw == 0 ? Qnil : build_string (the_pw->pw_name));
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 /* lock_file locks file fn,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 meaning it serves notice on the world that you intend to edit that file.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 This should be done only when about to modify a file-visiting
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 buffer previously unmodified.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 Do not (normally) call lock_buffer for a buffer already modified,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 as either the file is already locked, or the user has already
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 decided to go ahead without locking.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 When lock_buffer returns, either the lock is locked for us,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 or the user has said to go ahead without locking.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 If the file is locked by someone else, lock_buffer calls
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ask-user-about-lock (a Lisp function) with two arguments,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 the file name and the name of the user who did the locking.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 This function can signal an error, or return t meaning
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 take away the lock, or return nil meaning ignore the lock. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 /* The lock file name is the file name with "/" replaced by "!"
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 and put in the Emacs lock directory. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 /* (ie., /ka/king/junk.tex -> /!/!ka!king!junk.tex). */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
3602
f71f3f167365 * filelock.c: Test HAVE_LONG_FILE_NAMES, not SHORT_FILE_NAMES, to
Jim Blandy <jimb@redhat.com>
parents: 3537
diff changeset
197 /* If HAVE_LONG_FILE_NAMES is not defined, the lock file name is the hex
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
198 representation of a 14-bytes CRC generated from the file name
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
199 and put in the Emacs lock directory (not very nice, but it works).
4680
9d56bce1534a * filelock.c (fill_in_lock_short_file_name): corrected the crc
Francesco Potortì <pot@gnu.org>
parents: 4618
diff changeset
200 (ie., /ka/king/junk.tex -> /!/12a82c62f1c6da). */
3537
22055fd47b78 (MAKE_LOCK_PATH): If SHORT_FILE_NAMES allocates
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
201
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 void
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 lock_file (fn)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 register Lisp_Object fn;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 {
12811
11f5ce737c57 (lock_file): Use get_truename_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 12104
diff changeset
206 register Lisp_Object attack, orig_fn;
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 register char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
12811
11f5ce737c57 (lock_file): Use get_truename_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 12104
diff changeset
209 orig_fn = fn;
12104
10197e4b3fb2 (unlock_file, lock_file): Call Fexpand_file_name.
Karl Heuer <kwzh@gnu.org>
parents: 10752
diff changeset
210 fn = Fexpand_file_name (fn, Qnil);
10197e4b3fb2 (unlock_file, lock_file): Call Fexpand_file_name.
Karl Heuer <kwzh@gnu.org>
parents: 10752
diff changeset
211
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
212 MAKE_LOCK_NAME (lfname, fn);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
214 /* See if this file is visited and has changed on disk since it was
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
215 visited. */
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 {
6499
e0bef61003ae (lock_file): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
parents: 6300
diff changeset
217 register Lisp_Object subject_buf;
12811
11f5ce737c57 (lock_file): Use get_truename_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 12104
diff changeset
218 subject_buf = get_truename_buffer (orig_fn);
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
219 if (!NILP (subject_buf)
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
220 && NILP (Fverify_visited_file_modtime (subject_buf))
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
221 && !NILP (Ffile_exists_p (fn)))
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 call1 (intern ("ask-user-about-supersession-threat"), fn);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 /* Try to lock the lock. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 if (lock_if_free (lfname) <= 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 /* Return now if we have locked it, or if lock dir does not exist */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 return;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 /* Else consider breaking the lock */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 attack = call2 (intern ("ask-user-about-lock"), fn,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 lock_file_owner_name (lfname));
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 372
diff changeset
233 if (!NILP (attack))
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 /* User says take the lock */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 lock_superlock (lfname);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 lock_file_1 (lfname, O_WRONLY) ;
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
238 unlink (superlock_file);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 return;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 /* User says ignore the lock */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 /* Lock the lock file named LFNAME.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 If MODE is O_WRONLY, we do so even if it is already locked.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 If MODE is O_WRONLY | O_EXCL | O_CREAT, we do so only if it is free.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 Return 1 if successful, 0 if not. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 int
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 lock_file_1 (lfname, mode)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 int mode; char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 register int fd;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 char buf[20];
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 if ((fd = open (lfname, mode, 0666)) >= 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 #ifdef USG
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 chmod (lfname, 0666);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 #else
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 fchmod (fd, 0666);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 #endif
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 sprintf (buf, "%d ", getpid ());
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 write (fd, buf, strlen (buf));
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 close (fd);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 return 1;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 else
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 return 0;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 /* Lock the lock named LFNAME if possible.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 Return 0 in that case.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 Return positive if lock is really locked by someone else.
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 Return -1 if cannot lock for any other reason. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 int
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 lock_if_free (lfname)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 register char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 register int clasher;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 while (lock_file_1 (lfname, O_WRONLY | O_EXCL | O_CREAT) == 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 if (errno != EEXIST)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 return -1;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 clasher = current_lock_owner (lfname);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 if (clasher != 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 if (clasher != getpid ())
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 return (clasher);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 else return (0);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 /* Try again to lock it */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 return 0;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 /* Return the pid of the process that claims to own the lock file LFNAME,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 or 0 if nobody does or the lock is obsolete,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 or -1 if something is wrong with the locking mechanism. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 int
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 current_lock_owner (lfname)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 int owner = current_lock_owner_1 (lfname);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 if (owner == 0 && errno == ENOENT)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 return (0);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 /* Is it locked by a process that exists? */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 if (owner != 0 && (kill (owner, 0) >= 0 || errno == EPERM))
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 return (owner);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 if (unlink (lfname) < 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 return (-1);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 return (0);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 int
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 current_lock_owner_1 (lfname)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 register int fd;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 char buf[20];
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 int tem;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 fd = open (lfname, O_RDONLY, 0666);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 if (fd < 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 return 0;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 tem = read (fd, buf, sizeof buf);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 close (fd);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 return (tem <= 0 ? 0 : atoi (buf));
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 void
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 unlock_file (fn)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 register Lisp_Object fn;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 register char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338
12104
10197e4b3fb2 (unlock_file, lock_file): Call Fexpand_file_name.
Karl Heuer <kwzh@gnu.org>
parents: 10752
diff changeset
339 fn = Fexpand_file_name (fn, Qnil);
10197e4b3fb2 (unlock_file, lock_file): Call Fexpand_file_name.
Karl Heuer <kwzh@gnu.org>
parents: 10752
diff changeset
340
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
341 MAKE_LOCK_NAME (lfname, fn);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 lock_superlock (lfname);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 if (current_lock_owner_1 (lfname) == getpid ())
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 unlink (lfname);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
348 unlink (superlock_file);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 lock_superlock (lfname)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 register int i, fd;
6300
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
355 DIR *lockdir;
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
356 struct stat first_stat, last_stat;
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
358 for (i = -20; i < 0;
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 i++)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 {
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
361 fd = open (superlock_file,
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
362 O_WRONLY | O_EXCL | O_CREAT, 0666);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
363
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
364 /* If we succeeded in creating the superlock, we win.
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
365 Fill in our info and return. */
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
366 if (fd >= 0)
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
367 {
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
368 #ifdef USG
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
369 chmod (superlock_file, 0666);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
370 #else
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
371 fchmod (fd, 0666);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
372 #endif
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
373 write (fd, lfname, strlen (lfname));
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
374 close (fd);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
375 return;
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
376 }
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
377
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
378 /* If the problem is not just that it is already locked,
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
379 give up. */
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 if (errno != EEXIST)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 return;
6300
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
382
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
383 message ("Superlock file exists, retrying...");
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
384
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
385 if (i == -20)
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
386 stat (superlock_file, &first_stat);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
387
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
388 if (i == -1)
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
389 stat (superlock_file, &last_stat);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
390
6300
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
391 /* This seems to be necessary to prevent Emacs from hanging when the
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
392 competing process has already deleted the superlock, but it's still
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
393 in the NFS cache. So we force NFS to synchronize the cache. */
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
394 lockdir = opendir (lock_dir);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
395
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
396 if (lockdir)
6300
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
397 closedir (lockdir);
0aa51282fbfe (lock_superlock): Synchronize NFS cache.
Karl Heuer <kwzh@gnu.org>
parents: 4701
diff changeset
398
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 sleep (1);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 }
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
401
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
402 if (first_stat.st_ctime == last_stat.st_ctime)
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 {
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
404 int value;
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
405 value = unlink (superlock_file);
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
406
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
407 if (value != -1)
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
408 message ("Superlock file deleted");
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
409 else
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
410 message ("Failed to delete superlock file");
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 }
16172
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
412 else
b7131e99a796 (lock_superlock): Delete superlock file if it stayed
Richard M. Stallman <rms@gnu.org>
parents: 15797
diff changeset
413 message ("Giving up on the superlock file");
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 void
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 unlock_all_files ()
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 register Lisp_Object tail;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 register struct buffer *b;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421
9949
e9d341f235ee (unlock_all_files): Use the new type-test macros.
Karl Heuer <kwzh@gnu.org>
parents: 9130
diff changeset
422 for (tail = Vbuffer_alist; GC_CONSP (tail); tail = XCONS (tail)->cdr)
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 b = XBUFFER (XCONS (XCONS (tail)->car)->cdr);
10752
e4fb5e01090a (unlock_buffer, unlock_all_files, Flock_buffer)
Richard M. Stallman <rms@gnu.org>
parents: 10331
diff changeset
425 if (STRINGP (b->file_truename) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
e4fb5e01090a (unlock_buffer, unlock_all_files, Flock_buffer)
Richard M. Stallman <rms@gnu.org>
parents: 10331
diff changeset
426 unlock_file (b->file_truename);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 DEFUN ("lock-buffer", Flock_buffer, Slock_buffer,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 0, 1, 0,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 "Lock FILE, if current buffer is modified.\n\
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 FILE defaults to current buffer's visited file,\n\
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 or else nothing is done if current buffer isn't visiting a file.")
14075
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
436 (file)
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
437 Lisp_Object file;
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 {
14075
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
439 if (NILP (file))
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
440 file = current_buffer->file_truename;
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 else
14075
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
442 CHECK_STRING (file, 0);
10331
2ae69efc3e8b Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 10017
diff changeset
443 if (SAVE_MODIFF < MODIFF
14075
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
444 && !NILP (file))
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
445 lock_file (file);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 return Qnil;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 DEFUN ("unlock-buffer", Funlock_buffer, Sunlock_buffer,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 0, 0, 0,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 "Unlock the file visited in the current buffer,\n\
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 if it should normally be locked.")
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 ()
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 {
10331
2ae69efc3e8b Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 10017
diff changeset
455 if (SAVE_MODIFF < MODIFF
10752
e4fb5e01090a (unlock_buffer, unlock_all_files, Flock_buffer)
Richard M. Stallman <rms@gnu.org>
parents: 10331
diff changeset
456 && STRINGP (current_buffer->file_truename))
e4fb5e01090a (unlock_buffer, unlock_all_files, Flock_buffer)
Richard M. Stallman <rms@gnu.org>
parents: 10331
diff changeset
457 unlock_file (current_buffer->file_truename);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 return Qnil;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 /* Unlock the file visited in buffer BUFFER. */
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 unlock_buffer (buffer)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 struct buffer *buffer;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 {
10331
2ae69efc3e8b Use SAVE_MODIFF and BUF_SAVE_MODIFF
Richard M. Stallman <rms@gnu.org>
parents: 10017
diff changeset
467 if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer)
10752
e4fb5e01090a (unlock_buffer, unlock_all_files, Flock_buffer)
Richard M. Stallman <rms@gnu.org>
parents: 10331
diff changeset
468 && STRINGP (buffer->file_truename))
e4fb5e01090a (unlock_buffer, unlock_all_files, Flock_buffer)
Richard M. Stallman <rms@gnu.org>
parents: 10331
diff changeset
469 unlock_file (buffer->file_truename);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 DEFUN ("file-locked-p", Ffile_locked_p, Sfile_locked_p, 0, 1, 0,
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 "Return nil if the FILENAME is not locked,\n\
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 t if it is locked by you, else a string of the name of the locker.")
14075
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
475 (filename)
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
476 Lisp_Object filename;
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 register char *lfname;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 int owner;
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480
14075
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
481 filename = Fexpand_file_name (filename, Qnil);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
14075
21a86b6274e6 (Flock_buffer, Ffile_locked_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 12811
diff changeset
483 MAKE_LOCK_NAME (lfname, filename);
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 owner = current_lock_owner (lfname);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 if (owner <= 0)
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 return (Qnil);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 else if (owner == getpid ())
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 return (Qt);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 return (lock_file_owner_name (lfname));
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
494
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
495 /* Initialization functions. */
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
496
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
497 init_filelock ()
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
498 {
10017
6e28a6ff9a41 (init_filelock): Add missing semicolon.
Richard M. Stallman <rms@gnu.org>
parents: 9996
diff changeset
499 char *new_name;
9992
5666a2d5b2bc (init_filelock): Always copy lock_path.
Richard M. Stallman <rms@gnu.org>
parents: 9949
diff changeset
500
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
501 lock_dir = egetenv ("EMACSLOCKDIR");
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
502 if (! lock_dir)
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
503 lock_dir = PATH_LOCK;
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
504
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
505 /* Copy the name in case egetenv got it from a Lisp string. */
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
506 new_name = (char *) xmalloc (strlen (lock_dir) + 2);
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
507 strcpy (new_name, lock_dir);
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
508 lock_dir = new_name;
9992
5666a2d5b2bc (init_filelock): Always copy lock_path.
Richard M. Stallman <rms@gnu.org>
parents: 9949
diff changeset
509
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
510 /* Make sure it ends with a slash. */
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
511 if (lock_dir[strlen (lock_dir) - 1] != '/')
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
512 strcat (lock_dir, "/");
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
513
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
514 superlock_file = (char *) xmalloc ((strlen (lock_dir)
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
515 + sizeof (SUPERLOCK_NAME)));
9996
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
516 strcpy (superlock_file, lock_dir);
478f14a61aba (lock_dir, superlock_file, MAKE_LOCK_NAME):
Richard M. Stallman <rms@gnu.org>
parents: 9992
diff changeset
517 strcat (superlock_file, SUPERLOCK_NAME);
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
518 }
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 559
diff changeset
519
163
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 syms_of_filelock ()
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 {
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 defsubr (&Sunlock_buffer);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 defsubr (&Slock_buffer);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 defsubr (&Sfile_locked_p);
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 }
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526
0f3996cb4ae5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 #endif /* CLASH_DETECTION */