Mercurial > emacs
comparison src/filelock.c @ 9996:478f14a61aba
(lock_dir, superlock_file, MAKE_LOCK_NAME):
Renamed from lock_path, superlock_path, MAKE_LOCK_PATH.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 17 Nov 1994 17:28:35 +0000 |
parents | 5666a2d5b2bc |
children | 6e28a6ff9a41 |
comparison
equal
deleted
inserted
replaced
9995:e797886a4244 | 9996:478f14a61aba |
---|---|
75 #endif | 75 #endif |
76 | 76 |
77 | 77 |
78 /* The name of the directory in which we keep lock files, with a '/' | 78 /* The name of the directory in which we keep lock files, with a '/' |
79 appended. */ | 79 appended. */ |
80 char *lock_path; | 80 char *lock_dir; |
81 | 81 |
82 /* The name of the file in the lock directory which is used to | 82 /* The name of the file in the lock directory which is used to |
83 arbitrate access to the entire directory. */ | 83 arbitrate access to the entire directory. */ |
84 #define SUPERLOCK_NAME "!!!SuperLock!!!" | 84 #define SUPERLOCK_NAME "!!!SuperLock!!!" |
85 | 85 |
86 /* The path to the superlock file. This is SUPERLOCK_NAME appended to | 86 /* The name of the superlock file. This is SUPERLOCK_NAME appended to |
87 lock_path. */ | 87 lock_dir. */ |
88 char *superlock_path; | 88 char *superlock_file; |
89 | 89 |
90 /* Set LOCK to the name of the lock file for the filename FILE. | 90 /* Set LOCK to the name of the lock file for the filename FILE. |
91 char *LOCK; Lisp_Object FILE; */ | 91 char *LOCK; Lisp_Object FILE; */ |
92 | 92 |
93 #ifndef HAVE_LONG_FILE_NAMES | 93 #ifndef HAVE_LONG_FILE_NAMES |
94 | 94 |
95 #define MAKE_LOCK_PATH(lock, file) \ | 95 #define MAKE_LOCK_NAME(lock, file) \ |
96 (lock = (char *) alloca (14 + strlen (lock_path) + 1), \ | 96 (lock = (char *) alloca (14 + strlen (lock_dir) + 1), \ |
97 fill_in_lock_short_file_name (lock, (file))) | 97 fill_in_lock_short_file_name (lock, (file))) |
98 | 98 |
99 | 99 |
100 fill_in_lock_short_file_name (lockfile, fn) | 100 fill_in_lock_short_file_name (lockfile, fn) |
101 register char *lockfile; | 101 register char *lockfile; |
122 crc.byte[3] = crc.byte[2] + new; | 122 crc.byte[3] = crc.byte[2] + new; |
123 crc.byte[2] = crc.byte[1]; | 123 crc.byte[2] = crc.byte[1]; |
124 crc.byte[1] = crc.byte[0]; | 124 crc.byte[1] = crc.byte[0]; |
125 crc.byte[0] = new; | 125 crc.byte[0] = new; |
126 } | 126 } |
127 sprintf (lockfile, "%s%.2x%.2x%.2x%.2x%.2x%.2x%.2x", lock_path, | 127 sprintf (lockfile, "%s%.2x%.2x%.2x%.2x%.2x%.2x%.2x", lock_dir, |
128 crc.byte[0], crc.byte[1], crc.byte[2], crc.byte[3], | 128 crc.byte[0], crc.byte[1], crc.byte[2], crc.byte[3], |
129 crc.byte[4], crc.byte[5], crc.byte[6]); | 129 crc.byte[4], crc.byte[5], crc.byte[6]); |
130 } | 130 } |
131 | 131 |
132 #else /* defined HAVE_LONG_FILE_NAMES */ | 132 #else /* defined HAVE_LONG_FILE_NAMES */ |
133 | 133 |
134 #define MAKE_LOCK_PATH(lock, file) \ | 134 #define MAKE_LOCK_NAME(lock, file) \ |
135 (lock = (char *) alloca (XSTRING (file)->size + strlen (lock_path) + 1), \ | 135 (lock = (char *) alloca (XSTRING (file)->size + strlen (lock_dir) + 1), \ |
136 fill_in_lock_file_name (lock, (file))) | 136 fill_in_lock_file_name (lock, (file))) |
137 | 137 |
138 | 138 |
139 fill_in_lock_file_name (lockfile, fn) | 139 fill_in_lock_file_name (lockfile, fn) |
140 register char *lockfile; | 140 register char *lockfile; |
141 register Lisp_Object fn; | 141 register Lisp_Object fn; |
142 { | 142 { |
143 register char *p; | 143 register char *p; |
144 | 144 |
145 strcpy (lockfile, lock_path); | 145 strcpy (lockfile, lock_dir); |
146 | 146 |
147 p = lockfile + strlen (lockfile); | 147 p = lockfile + strlen (lockfile); |
148 | 148 |
149 strcpy (p, XSTRING (fn)->data); | 149 strcpy (p, XSTRING (fn)->data); |
150 | 150 |
200 register Lisp_Object fn; | 200 register Lisp_Object fn; |
201 { | 201 { |
202 register Lisp_Object attack; | 202 register Lisp_Object attack; |
203 register char *lfname; | 203 register char *lfname; |
204 | 204 |
205 MAKE_LOCK_PATH (lfname, fn); | 205 MAKE_LOCK_NAME (lfname, fn); |
206 | 206 |
207 /* See if this file is visited and has changed on disk since it was | 207 /* See if this file is visited and has changed on disk since it was |
208 visited. */ | 208 visited. */ |
209 { | 209 { |
210 register Lisp_Object subject_buf; | 210 register Lisp_Object subject_buf; |
226 if (!NILP (attack)) | 226 if (!NILP (attack)) |
227 /* User says take the lock */ | 227 /* User says take the lock */ |
228 { | 228 { |
229 lock_superlock (lfname); | 229 lock_superlock (lfname); |
230 lock_file_1 (lfname, O_WRONLY) ; | 230 lock_file_1 (lfname, O_WRONLY) ; |
231 unlink (superlock_path); | 231 unlink (superlock_file); |
232 return; | 232 return; |
233 } | 233 } |
234 /* User says ignore the lock */ | 234 /* User says ignore the lock */ |
235 } | 235 } |
236 | 236 |
327 unlock_file (fn) | 327 unlock_file (fn) |
328 register Lisp_Object fn; | 328 register Lisp_Object fn; |
329 { | 329 { |
330 register char *lfname; | 330 register char *lfname; |
331 | 331 |
332 MAKE_LOCK_PATH (lfname, fn); | 332 MAKE_LOCK_NAME (lfname, fn); |
333 | 333 |
334 lock_superlock (lfname); | 334 lock_superlock (lfname); |
335 | 335 |
336 if (current_lock_owner_1 (lfname) == getpid ()) | 336 if (current_lock_owner_1 (lfname) == getpid ()) |
337 unlink (lfname); | 337 unlink (lfname); |
338 | 338 |
339 unlink (superlock_path); | 339 unlink (superlock_file); |
340 } | 340 } |
341 | 341 |
342 lock_superlock (lfname) | 342 lock_superlock (lfname) |
343 char *lfname; | 343 char *lfname; |
344 { | 344 { |
345 register int i, fd; | 345 register int i, fd; |
346 DIR *lockdir; | 346 DIR *lockdir; |
347 | 347 |
348 for (i = -20; i < 0 && (fd = open (superlock_path, | 348 for (i = -20; i < 0 && (fd = open (superlock_file, |
349 O_WRONLY | O_EXCL | O_CREAT, 0666)) < 0; | 349 O_WRONLY | O_EXCL | O_CREAT, 0666)) < 0; |
350 i++) | 350 i++) |
351 { | 351 { |
352 if (errno != EEXIST) | 352 if (errno != EEXIST) |
353 return; | 353 return; |
354 | 354 |
355 /* This seems to be necessary to prevent Emacs from hanging when the | 355 /* This seems to be necessary to prevent Emacs from hanging when the |
356 competing process has already deleted the superlock, but it's still | 356 competing process has already deleted the superlock, but it's still |
357 in the NFS cache. So we force NFS to synchronize the cache. */ | 357 in the NFS cache. So we force NFS to synchronize the cache. */ |
358 if (lockdir = opendir (lock_path)) | 358 if (lockdir = opendir (lock_dir)) |
359 closedir (lockdir); | 359 closedir (lockdir); |
360 | 360 |
361 sleep (1); | 361 sleep (1); |
362 } | 362 } |
363 if (fd >= 0) | 363 if (fd >= 0) |
364 { | 364 { |
365 #ifdef USG | 365 #ifdef USG |
366 chmod (superlock_path, 0666); | 366 chmod (superlock_file, 0666); |
367 #else | 367 #else |
368 fchmod (fd, 0666); | 368 fchmod (fd, 0666); |
369 #endif | 369 #endif |
370 write (fd, lfname, strlen (lfname)); | 370 write (fd, lfname, strlen (lfname)); |
371 close (fd); | 371 close (fd); |
437 register char *lfname; | 437 register char *lfname; |
438 int owner; | 438 int owner; |
439 | 439 |
440 fn = Fexpand_file_name (fn, Qnil); | 440 fn = Fexpand_file_name (fn, Qnil); |
441 | 441 |
442 MAKE_LOCK_PATH (lfname, fn); | 442 MAKE_LOCK_NAME (lfname, fn); |
443 | 443 |
444 owner = current_lock_owner (lfname); | 444 owner = current_lock_owner (lfname); |
445 if (owner <= 0) | 445 if (owner <= 0) |
446 return (Qnil); | 446 return (Qnil); |
447 else if (owner == getpid ()) | 447 else if (owner == getpid ()) |
453 | 453 |
454 /* Initialization functions. */ | 454 /* Initialization functions. */ |
455 | 455 |
456 init_filelock () | 456 init_filelock () |
457 { | 457 { |
458 char *new_path | 458 char *new_name |
459 | 459 |
460 lock_path = egetenv ("EMACSLOCKDIR"); | 460 lock_dir = egetenv ("EMACSLOCKDIR"); |
461 if (! lock_path) | 461 if (! lock_dir) |
462 lock_path = PATH_LOCK; | 462 lock_dir = PATH_LOCK; |
463 | 463 |
464 /* Copy the path in case egetenv got it from a Lisp string. */ | 464 /* Copy the name in case egetenv got it from a Lisp string. */ |
465 new_path = (char *) xmalloc (strlen (lock_path) + 2); | 465 new_name = (char *) xmalloc (strlen (lock_dir) + 2); |
466 strcpy (new_path, lock_path); | 466 strcpy (new_name, lock_dir); |
467 lock_path = new_path; | 467 lock_dir = new_name; |
468 | 468 |
469 /* Make sure it ends with a slash. */ | 469 /* Make sure it ends with a slash. */ |
470 if (lock_path[strlen (lock_path) - 1] != '/') | 470 if (lock_dir[strlen (lock_dir) - 1] != '/') |
471 strcat (lock_path, "/"); | 471 strcat (lock_dir, "/"); |
472 | 472 |
473 superlock_path = (char *) xmalloc ((strlen (lock_path) | 473 superlock_file = (char *) xmalloc ((strlen (lock_dir) |
474 + sizeof (SUPERLOCK_NAME))); | 474 + sizeof (SUPERLOCK_NAME))); |
475 strcpy (superlock_path, lock_path); | 475 strcpy (superlock_file, lock_dir); |
476 strcat (superlock_path, SUPERLOCK_NAME); | 476 strcat (superlock_file, SUPERLOCK_NAME); |
477 } | 477 } |
478 | 478 |
479 syms_of_filelock () | 479 syms_of_filelock () |
480 { | 480 { |
481 defsubr (&Sunlock_buffer); | 481 defsubr (&Sunlock_buffer); |