annotate src/filelock.c @ 665:fdefd0186b75

[xemacs-hg @ 2001-09-20 06:28:42 by ben] The great integral types renaming. The purpose of this is to rationalize the names used for various integral types, so that they match their intended uses and follow consist conventions, and eliminate types that were not semantically different from each other. The conventions are: -- All integral types that measure quantities of anything are signed. Some people disagree vociferously with this, but their arguments are mostly theoretical, and are vastly outweighed by the practical headaches of mixing signed and unsigned values, and more importantly by the far increased likelihood of inadvertent bugs: Because of the broken "viral" nature of unsigned quantities in C (operations involving mixed signed/unsigned are done unsigned, when exactly the opposite is nearly always wanted), even a single error in declaring a quantity unsigned that should be signed, or even the even more subtle error of comparing signed and unsigned values and forgetting the necessary cast, can be catastrophic, as comparisons will yield wrong results. -Wsign-compare is turned on specifically to catch this, but this tends to result in a great number of warnings when mixing signed and unsigned, and the casts are annoying. More has been written on this elsewhere. -- All such quantity types just mentioned boil down to EMACS_INT, which is 32 bits on 32-bit machines and 64 bits on 64-bit machines. This is guaranteed to be the same size as Lisp objects of type `int', and (as far as I can tell) of size_t (unsigned!) and ssize_t. The only type below that is not an EMACS_INT is Hashcode, which is an unsigned value of the same size as EMACS_INT. -- Type names should be relatively short (no more than 10 characters or so), with the first letter capitalized and no underscores if they can at all be avoided. -- "count" == a zero-based measurement of some quantity. Includes sizes, offsets, and indexes. -- "bpos" == a one-based measurement of a position in a buffer. "Charbpos" and "Bytebpos" count text in the buffer, rather than bytes in memory; thus Bytebpos does not directly correspond to the memory representation. Use "Membpos" for this. -- "Char" refers to internal-format characters, not to the C type "char", which is really a byte. -- For the actual name changes, see the script below. I ran the following script to do the conversion. (NOTE: This script is idempotent. You can safely run it multiple times and it will not screw up previous results -- in fact, it will do nothing if nothing has changed. Thus, it can be run repeatedly as necessary to handle patches coming in from old workspaces, or old branches.) There are two tags, just before and just after the change: `pre-integral-type-rename' and `post-integral-type-rename'. When merging code from the main trunk into a branch, the best thing to do is first merge up to `pre-integral-type-rename', then apply the script and associated changes, then merge from `post-integral-type-change' to the present. (Alternatively, just do the merging in one operation; but you may then have a lot of conflicts needing to be resolved by hand.) Script `fixtypes.sh' follows: ----------------------------------- cut ------------------------------------ files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]" gr Memory_Count Bytecount $files gr Lstream_Data_Count Bytecount $files gr Element_Count Elemcount $files gr Hash_Code Hashcode $files gr extcount bytecount $files gr bufpos charbpos $files gr bytind bytebpos $files gr memind membpos $files gr bufbyte intbyte $files gr Extcount Bytecount $files gr Bufpos Charbpos $files gr Bytind Bytebpos $files gr Memind Membpos $files gr Bufbyte Intbyte $files gr EXTCOUNT BYTECOUNT $files gr BUFPOS CHARBPOS $files gr BYTIND BYTEBPOS $files gr MEMIND MEMBPOS $files gr BUFBYTE INTBYTE $files gr MEMORY_COUNT BYTECOUNT $files gr LSTREAM_DATA_COUNT BYTECOUNT $files gr ELEMENT_COUNT ELEMCOUNT $files gr HASH_CODE HASHCODE $files ----------------------------------- cut ------------------------------------ `fixtypes.sh' is a Bourne-shell script; it uses 'gr': ----------------------------------- cut ------------------------------------ #!/bin/sh # Usage is like this: # gr FROM TO FILES ... # globally replace FROM with TO in FILES. FROM and TO are regular expressions. # backup files are stored in the `backup' directory. from="$1" to="$2" shift 2 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g" ----------------------------------- cut ------------------------------------ `gr' in turn uses a Perl script to do its real work, `global-replace', which follows: ----------------------------------- cut ------------------------------------ : #-*- Perl -*- ### global-modify --- modify the contents of a file by a Perl expression ## Copyright (C) 1999 Martin Buchholz. ## Copyright (C) 2001 Ben Wing. ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org> ## Maintainer: Ben Wing <ben@xemacs.org> ## Current Version: 1.0, May 5, 2001 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XEmacs; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. eval 'exec perl -w -S $0 ${1+"$@"}' if 0; use strict; use FileHandle; use Carp; use Getopt::Long; use File::Basename; (my $myName = $0) =~ s@.*/@@; my $usage=" Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode] PERLEXPR FILE ... Globally modify a file, either line by line or in one big hunk. Typical usage is like this: [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc. in file names] find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n [with non-GNU print, xargs] find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n The file is read in, either line by line (with --line-mode specified) or in one big hunk (with --hunk-mode specified; it's the default), and the Perl expression is then evalled with \$_ set to the line or hunk of text, including the terminating newline if there is one. It should destructively modify the value there, storing the changed result in \$_. Files in which any modifications are made are backed up to the directory specified using --backup-dir, or to `backup' by default. To disable this, use --backup-dir= with no argument. Hunk mode is the default because it is MUCH MUCH faster than line-by-line. Use line-by-line only when it matters, e.g. you want to do a replacement only once per line (the default without the `g' argument). Conversely, when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one replacement in the entire file! "; my %options = (); $Getopt::Long::ignorecase = 0; &GetOptions ( \%options, 'help', 'backup-dir=s', 'line-mode', 'hunk-mode', ); die $usage if $options{"help"} or @ARGV <= 1; my $code = shift; die $usage if grep (-d || ! -w, @ARGV); sub SafeOpen { open ((my $fh = new FileHandle), $_[0]); confess "Can't open $_[0]: $!" if ! defined $fh; return $fh; } sub SafeClose { close $_[0] or confess "Can't close $_[0]: $!"; } sub FileContents { my $fh = SafeOpen ("< $_[0]"); my $olddollarslash = $/; local $/ = undef; my $contents = <$fh>; $/ = $olddollarslash; return $contents; } sub WriteStringToFile { my $fh = SafeOpen ("> $_[0]"); binmode $fh; print $fh $_[1] or confess "$_[0]: $!\n"; SafeClose $fh; } foreach my $file (@ARGV) { my $changed_p = 0; my $new_contents = ""; if ($options{"line-mode"}) { my $fh = SafeOpen $file; while (<$fh>) { my $save_line = $_; eval $code; $changed_p = 1 if $save_line ne $_; $new_contents .= $_; } } else { my $orig_contents = $_ = FileContents $file; eval $code; if ($_ ne $orig_contents) { $changed_p = 1; $new_contents = $_; } } if ($changed_p) { my $backdir = $options{"backup-dir"}; $backdir = "backup" if !defined ($backdir); if ($backdir) { my ($name, $path, $suffix) = fileparse ($file, ""); my $backfulldir = $path . $backdir; my $backfile = "$backfulldir/$name"; mkdir $backfulldir, 0755 unless -d $backfulldir; print "modifying $file (original saved in $backfile)\n"; rename $file, $backfile; } WriteStringToFile ($file, $new_contents); } } ----------------------------------- cut ------------------------------------ In addition to those programs, I needed to fix up a few other things, particularly relating to the duplicate definitions of types, now that some types merged with others. Specifically: 1. in lisp.h, removed duplicate declarations of Bytecount. The changed code should now look like this: (In each code snippet below, the first and last lines are the same as the original, as are all lines outside of those lines. That allows you to locate the section to be replaced, and replace the stuff in that section, verifying that there isn't anything new added that would need to be kept.) --------------------------------- snip ------------------------------------- /* Counts of bytes or chars */ typedef EMACS_INT Bytecount; typedef EMACS_INT Charcount; /* Counts of elements */ typedef EMACS_INT Elemcount; /* Hash codes */ typedef unsigned long Hashcode; /* ------------------------ dynamic arrays ------------------- */ --------------------------------- snip ------------------------------------- 2. in lstream.h, removed duplicate declaration of Bytecount. Rewrote the comment about this type. The changed code should now look like this: --------------------------------- snip ------------------------------------- #endif /* The have been some arguments over the what the type should be that specifies a count of bytes in a data block to be written out or read in, using Lstream_read(), Lstream_write(), and related functions. Originally it was long, which worked fine; Martin "corrected" these to size_t and ssize_t on the grounds that this is theoretically cleaner and is in keeping with the C standards. Unfortunately, this practice is horribly error-prone due to design flaws in the way that mixed signed/unsigned arithmetic happens. In fact, by doing this change, Martin introduced a subtle but fatal error that caused the operation of sending large mail messages to the SMTP server under Windows to fail. By putting all values back to be signed, avoiding any signed/unsigned mixing, the bug immediately went away. The type then in use was Lstream_Data_Count, so that it be reverted cleanly if a vote came to that. Now it is Bytecount. Some earlier comments about why the type must be signed: This MUST BE SIGNED, since it also is used in functions that return the number of bytes actually read to or written from in an operation, and these functions can return -1 to signal error. Note that the standard Unix read() and write() functions define the count going in as a size_t, which is UNSIGNED, and the count going out as an ssize_t, which is SIGNED. This is a horrible design flaw. Not only is it highly likely to lead to logic errors when a -1 gets interpreted as a large positive number, but operations are bound to fail in all sorts of horrible ways when a number in the upper-half of the size_t range is passed in -- this number is unrepresentable as an ssize_t, so code that checks to see how many bytes are actually written (which is mandatory if you are dealing with certain types of devices) will get completely screwed up. --ben */ typedef enum lstream_buffering --------------------------------- snip ------------------------------------- 3. in dumper.c, there are four places, all inside of switch() statements, where XD_BYTECOUNT appears twice as a case tag. In each case, the two case blocks contain identical code, and you should *REMOVE THE SECOND* and leave the first.
author ben
date Thu, 20 Sep 2001 06:31:11 +0000
parents b39c14581166
children 943eaba38521
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Copyright (C) 1985, 86, 87, 93, 94, 96 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
3 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
5 XEmacs is free software; you can redistribute it and/or modify
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
10 XEmacs is distributed in the hope that it will be useful,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
16 along with XEmacs; see the file COPYING. If not, write to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 /* Synced with FSF 20.2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include <paths.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "sysfile.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "sysdir.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "syspwd.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "syssignal.h" /* for kill */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 Lisp_Object Qask_user_about_supersession_threat;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 Lisp_Object Qask_user_about_lock;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
35 int inhibit_clash_detection;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #ifdef CLASH_DETECTION
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
38
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 /* The strategy: to lock a file FN, create a symlink .#FN in FN's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 directory, with link data `user@host.pid'. This avoids a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 mount (== failure) point for lock files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 When the host in the lock data is the current host, we can check if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 the pid is valid with kill.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
45
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Otherwise, we could look at a separate file that maps hostnames to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 reboot times to see if the remote pid can possibly be valid, since we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 don't want Emacs to have to communicate via pipes or sockets or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 whatever to other processes, either locally or remotely; rms says
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 that's too unreliable. Hence the separate file, which could
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 theoretically be updated by daemons running separately -- but this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 whole idea is unimplemented; in practice, at least in our
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 environment, it seems such stale locks arise fairly infrequently, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 Emacs' standard methods of dealing with clashes suffice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 We use symlinks instead of normal files because (1) they can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 stored more efficiently on the filesystem, since the kernel knows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 they will be small, and (2) all the info about the lock can be read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 in a single system call (readlink). Although we could use regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 files to be useful on old systems lacking symlinks, nowadays
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 virtually all such systems are probably single-user anyway, so it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 didn't seem worth the complication.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 Similarly, we don't worry about a possible 14-character limit on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 file names, because those are all the same systems that don't have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 symlinks.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
67
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 This is compatible with the locking scheme used by Interleaf (which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 has contributed this implementation for Emacs), and was designed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 Ethan Jacobson, Kimbo Mundy, and others.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
71
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 --karl@cs.umb.edu/karl@hq.ileaf.com. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
74 /* Note that muleization is provided by using mule-encapsulated
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
75 versions of the system calls we use like symlink(), unlink(), etc... */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
76
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 /* Here is the structure that stores information about a lock. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 char *user;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 char *host;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
84 pid_t pid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 } lock_info_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 /* When we read the info back, we might need this much more,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 enough for decimal representation plus null. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
89 #define LOCK_PID_MAX (4 * sizeof (pid_t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 /* Free the two dynamically-allocated pieces in PTR. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #define FREE_LOCK_INFO(i) do { xfree ((i).user); xfree ((i).host); } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 /* Write the name of the lock file for FN into LFNAME. Length will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 that of FN plus two more for the leading `.#' plus one for the null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #define MAKE_LOCK_NAME(lock, file) \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
97 (lock = (char *) alloca (XSTRING_LENGTH (file) + 2 + 1), \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
98 fill_in_lock_file_name ((Intbyte *) (lock), (file)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
101 fill_in_lock_file_name (Intbyte *lockfile, Lisp_Object fn)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
103 Intbyte *file_name = XSTRING_DATA (fn);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
104 Intbyte *p;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
105 Bytecount dirlen;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
107 for (p = file_name + XSTRING_LENGTH (fn) - 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
108 p > file_name && !IS_ANY_SEP (p[-1]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
109 p--)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
110 ;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
111 dirlen = p - file_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
113 memcpy (lockfile, file_name, dirlen);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
114 p = lockfile + dirlen;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
115 *(p++) = '.';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
116 *(p++) = '#';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
117 memcpy (p, file_name + dirlen, XSTRING_LENGTH (fn) - dirlen + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 /* Lock the lock file named LFNAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 If FORCE is nonzero, we do so even if it is already locked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 Return 1 if successful, 0 if not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
125 lock_file_1 (char *lfname, int force)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
127 /* Does not GC. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
128 int err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
129 char *lock_info_str;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 char *host_name;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
131 char *user_name = user_login_name (NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
133 if (user_name == NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 user_name = "";
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
135
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
136 if (STRINGP (Vsystem_name))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
137 host_name = (char *) XSTRING_DATA (Vsystem_name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 host_name = "";
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
140
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 + LOCK_PID_MAX + 5);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
144 sprintf (lock_info_str, "%s@%s.%d", user_name, host_name, getpid ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 err = symlink (lock_info_str, lfname);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
147 if (err != 0 && errno == EEXIST && force)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 unlink (lfname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 err = symlink (lock_info_str, lfname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 return err == 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 /* Return 0 if nobody owns the lock file LFNAME or the lock is obsolete,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 1 if another process owns it (and set OWNER (if non-null) to info),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 2 if the current process owns it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 or -1 if something is wrong with the locking mechanism. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 current_lock_owner (lock_info_type *owner, char *lfname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
164 /* Does not GC. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
165 int len, ret;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 int local_owner = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 char *at, *dot;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 char *lfinfo = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 int bufsize = 50;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 /* Read arbitrarily-long contents of symlink. Similar code in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 file-symlink-p in fileio.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 bufsize *= 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 lfinfo = (char *) xrealloc (lfinfo, bufsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 len = readlink (lfname, lfinfo, bufsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 while (len >= bufsize);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
179
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 /* If nonexistent lock file, all is well; otherwise, got strange error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 if (len == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 xfree (lfinfo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 return errno == ENOENT ? 0 : -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 /* Link info exists, so `len' is its length. Null terminate. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 lfinfo[len] = 0;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
189
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 /* Even if the caller doesn't want the owner info, we still have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 read it to determine return value, so allocate it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 if (!owner)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 owner = (lock_info_type *) alloca (sizeof (lock_info_type));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 local_owner = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
197
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 /* Parse USER@HOST.PID. If can't parse, return -1. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 /* The USER is everything before the first @. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 at = strchr (lfinfo, '@');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 dot = strrchr (lfinfo, '.');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 if (!at || !dot) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 xfree (lfinfo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 len = at - lfinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 owner->user = (char *) xmalloc (len + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 strncpy (owner->user, lfinfo, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 owner->user[len] = 0;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
210
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 /* The PID is everything after the last `.'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 owner->pid = atoi (dot + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 /* The host is everything in between. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 len = dot - at - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 owner->host = (char *) xmalloc (len + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 strncpy (owner->host, at + 1, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 owner->host[len] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 /* We're done looking at the link info. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 xfree (lfinfo);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
222
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /* On current host? */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
224 if (STRINGP (Fsystem_name ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
225 && strcmp (owner->host, (char *) XSTRING_DATA (Fsystem_name ())) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 if (owner->pid == getpid ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ret = 2; /* We own it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 else if (owner->pid > 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 && (kill (owner->pid, 0) >= 0 || errno == EPERM))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 ret = 1; /* An existing process on this machine owns it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 /* The owner process is dead or has a strange pid (<=0), so try to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 zap the lockfile. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 else if (unlink (lfname) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 ret = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ret = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 { /* If we wanted to support the check for stale locks on remote machines,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 here's where we'd do it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 ret = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
244
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 /* Avoid garbage. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 if (local_owner || ret <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 FREE_LOCK_INFO (*owner);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 return ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 /* Lock the lock named LFNAME if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 Return 0 in that case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 Return positive if some other process owns the lock, and info about
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 that process in CLASHER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 Return -1 if cannot lock for any other reason. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 lock_if_free (lock_info_type *clasher, char *lfname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
262 /* Does not GC. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 if (lock_file_1 (lfname, 0) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 int locker;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 if (errno != EEXIST)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 return -1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
269
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 locker = current_lock_owner (clasher, lfname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 if (locker == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 FREE_LOCK_INFO (*clasher);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 return 0; /* We ourselves locked it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 else if (locker == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 return 1; /* Someone else has it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 return -1; /* Something's wrong. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 /* lock_file locks file FN,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 meaning it serves notice on the world that you intend to edit that file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 This should be done only when about to modify a file-visiting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 buffer previously unmodified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 Do not (normally) call this for a buffer already modified,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 as either the file is already locked, or the user has already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 decided to go ahead without locking.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 When this returns, either the lock is locked for us,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 or the user has said to go ahead without locking.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 If the file is locked by someone else, this calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 ask-user-about-lock (a Lisp function) with two arguments,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 the file name and info about the user who did the locking.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 This function can signal an error, or return t meaning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 take away the lock, or return nil meaning ignore the lock. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 lock_file (Lisp_Object fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
304 /* This function can GC. GC checked 7-11-00 ben */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 /* dmoore - and can destroy current_buffer and all sorts of other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 mean nasty things with pointy teeth. If you call this make sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 you protect things right. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
308 /* Somebody updated the code in this function and removed the previous
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 comment. -slb */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 register Lisp_Object attack, orig_fn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 register char *lfname, *locker;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 lock_info_type lock_info;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
314 struct gcpro gcpro1, gcpro2, gcpro3;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
315 Lisp_Object old_current_buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 Lisp_Object subject_buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
318 if (inhibit_clash_detection)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
319 return;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
320
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
321 XSETBUFFER (old_current_buffer, current_buffer);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
322 subject_buf = Qnil;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
323 GCPRO3 (fn, subject_buf, old_current_buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 orig_fn = fn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 fn = Fexpand_file_name (fn, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 /* Create the name of the lock-file for file fn */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 MAKE_LOCK_NAME (lfname, fn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 /* See if this file is visited and has changed on disk since it was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 visited. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 subject_buf = get_truename_buffer (orig_fn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 if (!NILP (subject_buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 && NILP (Fverify_visited_file_modtime (subject_buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 && !NILP (Ffile_exists_p (fn)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
337 call1_in_buffer (XBUFFER (subject_buf),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
338 Qask_user_about_supersession_threat, fn);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 /* Try to lock the lock. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
342 if (current_buffer != XBUFFER (old_current_buffer)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
343 || lock_if_free (&lock_info, lfname) <= 0)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
344 /* Return now if we have locked it, or if lock creation failed
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
345 or current buffer is killed. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 /* Else consider breaking the lock */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 + LOCK_PID_MAX + 9);
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
351 sprintf (locker, "%s@%s (pid %d)", lock_info.user, lock_info.host,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 lock_info.pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 FREE_LOCK_INFO (lock_info);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
354
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 attack = call2_in_buffer (BUFFERP (subject_buf) ? XBUFFER (subject_buf) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 current_buffer, Qask_user_about_lock , fn,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 build_string (locker));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
358 if (!NILP (attack) && current_buffer == XBUFFER (old_current_buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 /* User says take the lock */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 lock_file_1 (lfname, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 /* User says ignore the lock */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 unlock_file (Lisp_Object fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
372 /* This can GC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 register char *lfname;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
374 struct gcpro gcpro1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
375
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
376 GCPRO1 (fn);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 fn = Fexpand_file_name (fn, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 MAKE_LOCK_NAME (lfname, fn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 if (current_lock_owner (0, lfname) == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 unlink (lfname);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
384
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
385 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
389 unlock_all_files (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 register Lisp_Object tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
393 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
395 struct buffer *b = XBUFFER (XCDR (XCAR (tail)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 if (STRINGP (b->file_truename) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 unlock_file (b->file_truename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 DEFUN ("lock-buffer", Flock_buffer, 0, 1, 0, /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
402 Lock FILE, if current buffer is modified.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
403 FILE defaults to current buffer's visited file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 or else nothing is done if current buffer isn't visiting a file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
406 (file))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 if (NILP (file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 file = current_buffer->file_truename;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 CHECK_STRING (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 && !NILP (file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 lock_file (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 DEFUN ("unlock-buffer", Funlock_buffer, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 Unlock the file visited in the current buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 if it should normally be locked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 /* dmoore - and can destroy current_buffer and all sorts of other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 mean nasty things with pointy teeth. If you call this make sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 you protect things right. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 && STRINGP (current_buffer->file_truename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 unlock_file (current_buffer->file_truename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 /* Unlock the file visited in buffer BUFFER. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 unlock_buffer (struct buffer *buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 /* dmoore - and can destroy current_buffer and all sorts of other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 mean nasty things with pointy teeth. If you call this make sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 you protect things right. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 && STRINGP (buffer->file_truename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 unlock_file (buffer->file_truename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 DEFUN ("file-locked-p", Ffile_locked_p, 0, 1, 0, /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
450 Return nil if the FILENAME is not locked,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 t if it is locked by you, else a string of the name of the locker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
453 (filename))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 Lisp_Object ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 register char *lfname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 int owner;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 lock_info_type locker;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
459 struct gcpro gcpro1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
460
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
461 GCPRO1 (filename);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 filename = Fexpand_file_name (filename, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 MAKE_LOCK_NAME (lfname, filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 owner = current_lock_owner (&locker, lfname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 if (owner <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 ret = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 else if (owner == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 ret = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 ret = build_string (locker.user);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 if (owner > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 FREE_LOCK_INFO (locker);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
478 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
479
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 return ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 /* Initialization functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 syms_of_filelock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 DEFSUBR (Funlock_buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 DEFSUBR (Flock_buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 DEFSUBR (Ffile_locked_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
494 DEFSYMBOL (Qask_user_about_supersession_threat);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
495 DEFSYMBOL (Qask_user_about_lock);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
498 void
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
499 vars_of_filelock (void)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
500 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
501 DEFVAR_BOOL ("inhibit-clash-detection", &inhibit_clash_detection /*
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
502 Non-nil inhibits creation of lock file to detect clash.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
503 */);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
504 inhibit_clash_detection = 0;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
505 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 #endif /* CLASH_DETECTION */