🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98300

lock-buffer not working over network

#98300
From: John S
Date: Thu, 10 Oct 1991 03:50
233 lines
6974 bytes
RE: lock-buffer not working over network

Here are may changes to filelock.c to make it work over the network.
current_lock_owner() doesn't check if the process that locked the file
exists since it may be on a remote host.  That is were is was broken
before ie it would assume the lock was old if it didn't find the
process running on the local host when infact it was an emacs running
on a remote host that locked file.

It would be nice to find a good way to check the remote host for the
running process.  I could do it with RPC but there may be other ways
to do it.  If not it could at least determine if the remote host is the
same as the local host and then go ahead and check for the process.

				-jsb

*** filelock.c	Thu Oct 10 10:38:47 1991
--- filelock.c.new	Thu Oct 10 10:35:15 1991
***************
*** 1,7 ****
  /* Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
- 
  This file is part of GNU Emacs.
  
  GNU Emacs is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY.  No author or distributor
  accepts responsibility to anyone for the consequences of using it
--- 1,9 ----
+ /*
+  * %W%
+  */
  /* Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  This file is part of GNU Emacs.
  
  GNU Emacs is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY.  No author or distributor
  accepts responsibility to anyone for the consequences of using it
***************
*** 45,59 ****
  static Lisp_Object
  lock_file_owner_name (lfname)
  {
    struct stat s;
    struct passwd *the_pw;
    extern struct passwd *getpwuid ();
  
    if (lstat (lfname, &s) == 0)
      the_pw = getpwuid (s.st_uid);
!   return (the_pw == 0 ? Qnil : build_string (the_pw->pw_name));
  }
  
  
  /* lock_file locks file fn,
     meaning it serves notice on the world that you intend to edit that file.
--- 47,89 ----
  static Lisp_Object
  lock_file_owner_name (lfname)
  {
    struct stat s;
    struct passwd *the_pw;
+   char	buffer[64];
+   char	owner[64];
+   char	*host;
+   int	fd;
    extern struct passwd *getpwuid ();
  
    if (lstat (lfname, &s) == 0)
      the_pw = getpwuid (s.st_uid);
! 
!   if ((fd = open (lfname, O_RDONLY)) >= 0)
!   {
! 	  /*
! 	   * Get pid and hostname of process that locked the file, see
! 	   * lock_file_1()
! 	   */
! 	  bzero(buffer, sizeof(buffer));
! 	  read(fd, buffer, sizeof(buffer));
! 	  close (fd);
! 	  host = (char *)index(buffer, '@');
!   }
!   else
! 	  host = 0;
! 
!   /*
!    * Make owner nil incase we have nothing to put in it.
!    */
!   *owner = '\0';
!   if( the_pw )
! 	  strcpy(owner, the_pw->pw_name);
!   if( host )
! 	  strcat(owner, host);
! 
!   return (!*owner ? Qnil : build_string (owner));
  }
  
  
  /* lock_file locks file fn,
     meaning it serves notice on the world that you intend to edit that file.
***************
*** 106,116 ****
  		  lock_file_owner_name (lfname));
    if (!NULL (attack))
      /* User says take the lock */
      {
        lock_superlock (lfname);
!       lock_file_1 (lfname, O_WRONLY) ;
        unlink (PATH_SUPERLOCK);
        return;
      }
    /* User says ignore the lock */
  }
--- 136,147 ----
  		  lock_file_owner_name (lfname));
    if (!NULL (attack))
      /* User says take the lock */
      {
        lock_superlock (lfname);
!       unlink(lfname);
!       lock_file_1 (lfname, O_WRONLY | O_CREAT );
        unlink (PATH_SUPERLOCK);
        return;
      }
    /* User says ignore the lock */
  }
***************
*** 118,133 ****
  fill_in_lock_file_name (lockfile, fn)
       register char *lockfile;
       register Lisp_Object fn;
  {
    register char *p;
  
    strcpy (lockfile, PATH_LOCK);
  
    p = lockfile + strlen (lockfile);
  
!   strcpy (p, XSTRING (fn)->data);
  
    for (; *p; p++)
      {
        if (*p == '/')
  	*p = '!';
--- 149,170 ----
  fill_in_lock_file_name (lockfile, fn)
       register char *lockfile;
       register Lisp_Object fn;
  {
    register char *p;
+   register char	*s;
  
    strcpy (lockfile, PATH_LOCK);
  
    p = lockfile + strlen (lockfile);
  
!   /*
!    * Remove  "/tmp_mnt" from from of path name for automounter
!    */
!   s = XSTRING (fn)->data;
!   if( strncmp(s, "/tmp_mnt", 8) == 0) s += 8;
!   strcpy (p, s);
  
    for (; *p; p++)
      {
        if (*p == '/')
  	*p = '!';
***************
*** 146,157 ****
    register int fd;
    char buf[20];
  
    if ((fd = open (lfname, mode, 0666)) >= 0)
      {
        fchmod (fd, 0666);
!       sprintf (buf, "%d ", getpid ());
        write (fd, buf, strlen (buf));
        close (fd);
        return 1;
      }
    else
--- 183,204 ----
    register int fd;
    char buf[20];
  
    if ((fd = open (lfname, mode, 0666)) >= 0)
      {
+       Lisp_Object hostName;
+ 
+       hostName = Fsystem_name();
        fchmod (fd, 0666);
!       /*
!        * Add host name to end of pid before writing to the lock file
!        * so can see how locked the file.
!        * File should contain
!        * 	<pid>@<hostname>
!        */
!       sprintf (buf, "%d@%s", getpid (),
! 	       (hostName == Qnil) ? "" : (char *)XSTRING (hostName)->data);
        write (fd, buf, strlen (buf));
        close (fd);
        return 1;
      }
    else
***************
*** 192,203 ****
       char *lfname;
  {
    int owner = current_lock_owner_1 (lfname);
    if (owner == 0 && errno == ENOENT)
      return (0);
!   /* Is it locked by a process that exists?  */
!   if (owner != 0 && (kill (owner, 0) >= 0 || errno == EPERM))
      return (owner);
    if (unlink (lfname) < 0)
      return (-1);
    return (0);
  }
--- 239,254 ----
       char *lfname;
  {
    int owner = current_lock_owner_1 (lfname);
    if (owner == 0 && errno == ENOENT)
      return (0);
!   /*
!    * Should see if locked by a process that exists but can only check
!    * existence of the process on the local host so don't check at all.
!    * Later will find a way to check for a process on the remote host.
!    */
!   if (owner != 0)
      return (owner);
    if (unlink (lfname) < 0)
      return (-1);
    return (0);
  }
Technical Details
Message-ID: <9110101750.AA06961@c3po.sm-alc.af.mil>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!yale.edu!qt.cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!c3po.sm-alc.af.mil!basrai%kanga.dnet

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,70c4a9144ea0dc29
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-10-09 20:50:00 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!yale.edu!qt.cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!c3po.sm-alc.af.mil!basrai%kanga.dnet
From: basrai%kanga.dnet@c3po.sm-alc.af.mil (John S)
Newsgroups: gnu.emacs.bug
Subject: lock-buffer not working over network
Message-ID: <9110101750.AA06961@c3po.sm-alc.af.mil>
Date: 10 Oct 91 03:50:00 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 233
Approved: bug-gnu-emacs@prep.ai.mit.edu