or an errno value if something is wrong with the locking mechanism. */
static int
- current_lock_owner (lock_info_type *owner, char *lfname)
+ current_lock_owner (lock_info_type *owner, Lisp_Object lfname)
{
- int ret;
lock_info_type local_owner;
ptrdiff_t lfinfolen;
intmax_t pid, boot_time;
\f
/* Lock the lock named LFNAME if possible.
Return 0 in that case.
- Return negative if some other process owns the lock, and info about
+ Return ANOTHER_OWNS_IT if some other process owns the lock, and info about
that process in CLASHER.
- Return positive errno value if cannot lock for any other reason. */
+ Return errno value if cannot lock for any other reason. */
static int
- lock_if_free (lock_info_type *clasher, char *lfname)
+ lock_if_free (lock_info_type *clasher, Lisp_Object lfname)
{
int err;
while ((err = lock_file_1 (lfname, 0)) == EEXIST)
if (!NILP (subject_buf)
&& NILP (Fverify_visited_file_modtime (subject_buf))
&& !NILP (Ffile_exists_p (fn))
- && !(lfname && (current_lock_owner (NULL, lfname) == I_OWN_IT)))
- && !(!NILP (lfname) && current_lock_owner (NULL, lfname) == -2))
++ && !(!NILP (lfname) && current_lock_owner (NULL, lfname) == I_OWN_IT))
call1 (intern ("userlock--ask-user-about-supersession-threat"), fn);
/* Don't do locking if the user has opted out. */
- if (lfname)
+ if (!NILP (lfname))
{
/* Try to lock the lock. FIXME: This ignores errors when
-- lock_if_free returns a positive errno value. */
- if (lock_if_free (&lock_info, lfname) < 0)
++ lock_if_free returns an errno value. */
+ if (lock_if_free (&lock_info, lfname) == ANOTHER_OWNS_IT)
{
/* Someone else has the lock. Consider breaking it. */
Lisp_Object attack;
static Lisp_Object
unlock_file (Lisp_Object fn)
{
- char *lfname;
-
- Lisp_Object lock_filename = make_lock_file_name (fn);
- if (NILP (lock_filename))
+ Lisp_Object lfname = make_lock_file_name (fn);
+ if (NILP (lfname))
return Qnil;
- lfname = SSDATA (ENCODE_FILE (lock_filename));
int err = current_lock_owner (0, lfname);
- if (err == -2 && unlink (SSDATA (lfname)) != 0 && errno != ENOENT)
- err = errno;
- if (0 < err)
+ if (! (err == 0 || err == ANOTHER_OWNS_IT
+ || (err == I_OWN_IT
- && (unlink (lfname) == 0 || (err = errno) == ENOENT))))
++ && (unlink (SSDATA (lfname)) == 0 || (err = errno) == ENOENT))))
report_file_errno ("Unlocking file", fn, err);
return Qnil;