comparison src/filelock.c @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children 1ccc32a20af4
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
30 #include "syspwd.h" 30 #include "syspwd.h"
31 #include "syssignal.h" /* for kill */ 31 #include "syssignal.h" /* for kill */
32 32
33 Lisp_Object Qask_user_about_supersession_threat; 33 Lisp_Object Qask_user_about_supersession_threat;
34 Lisp_Object Qask_user_about_lock; 34 Lisp_Object Qask_user_about_lock;
35 int inhibit_clash_detection;
35 36
36 #ifdef CLASH_DETECTION 37 #ifdef CLASH_DETECTION
37 38
38 /* The strategy: to lock a file FN, create a symlink .#FN in FN's 39 /* The strategy: to lock a file FN, create a symlink .#FN in FN's
39 directory, with link data `user@host.pid'. This avoids a single 40 directory, with link data `user@host.pid'. This avoids a single
309 comment. -slb */ 310 comment. -slb */
310 311
311 register Lisp_Object attack, orig_fn; 312 register Lisp_Object attack, orig_fn;
312 register char *lfname, *locker; 313 register char *lfname, *locker;
313 lock_info_type lock_info; 314 lock_info_type lock_info;
314 struct gcpro gcpro1,gcpro2; 315 struct gcpro gcpro1, gcpro2, gcpro3;
316 Lisp_Object old_current_buffer;
315 Lisp_Object subject_buf; 317 Lisp_Object subject_buf;
316 318
317 GCPRO2 (fn, subject_buf); 319 if (inhibit_clash_detection)
320 return;
321
322 XSETBUFFER (old_current_buffer, current_buffer);
323 GCPRO3 (fn, subject_buf, old_current_buffer);
318 orig_fn = fn; 324 orig_fn = fn;
319 fn = Fexpand_file_name (fn, Qnil); 325 fn = Fexpand_file_name (fn, Qnil);
320 326
321 /* Create the name of the lock-file for file fn */ 327 /* Create the name of the lock-file for file fn */
322 MAKE_LOCK_NAME (lfname, fn); 328 MAKE_LOCK_NAME (lfname, fn);
331 call1_in_buffer (XBUFFER (subject_buf), 337 call1_in_buffer (XBUFFER (subject_buf),
332 Qask_user_about_supersession_threat, fn); 338 Qask_user_about_supersession_threat, fn);
333 } 339 }
334 340
335 /* Try to lock the lock. */ 341 /* Try to lock the lock. */
336 if (lock_if_free (&lock_info, lfname) <= 0) 342 if (current_buffer != XBUFFER (old_current_buffer)
337 /* Return now if we have locked it, or if lock creation failed */ 343 || lock_if_free (&lock_info, lfname) <= 0)
344 /* Return now if we have locked it, or if lock creation failed
345 or current buffer is killed. */
338 goto done; 346 goto done;
339 347
340 /* Else consider breaking the lock */ 348 /* Else consider breaking the lock */
341 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) 349 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host)
342 + LOCK_PID_MAX + 9); 350 + LOCK_PID_MAX + 9);
345 FREE_LOCK_INFO (lock_info); 353 FREE_LOCK_INFO (lock_info);
346 354
347 attack = call2_in_buffer (BUFFERP (subject_buf) ? XBUFFER (subject_buf) : 355 attack = call2_in_buffer (BUFFERP (subject_buf) ? XBUFFER (subject_buf) :
348 current_buffer, Qask_user_about_lock , fn, 356 current_buffer, Qask_user_about_lock , fn,
349 build_string (locker)); 357 build_string (locker));
350 if (!NILP (attack)) 358 if (!NILP (attack) && current_buffer == XBUFFER (old_current_buffer))
351 /* User says take the lock */ 359 /* User says take the lock */
352 { 360 {
353 lock_file_1 (lfname, 1); 361 lock_file_1 (lfname, 1);
354 goto done; 362 goto done;
355 } 363 }
486 defsymbol (&Qask_user_about_supersession_threat, 494 defsymbol (&Qask_user_about_supersession_threat,
487 "ask-user-about-supersession-threat"); 495 "ask-user-about-supersession-threat");
488 defsymbol (&Qask_user_about_lock, "ask-user-about-lock"); 496 defsymbol (&Qask_user_about_lock, "ask-user-about-lock");
489 } 497 }
490 498
499 void
500 vars_of_filelock (void)
501 {
502 DEFVAR_BOOL ("inhibit-clash-detection", &inhibit_clash_detection /*
503 Non-nil inhibits creation of lock file to detect clash.
504 */);
505 inhibit_clash_detection = 0;
506 }
491 507
492 #endif /* CLASH_DETECTION */ 508 #endif /* CLASH_DETECTION */