Re: [PATCH] Editor file locking



On Wed, Apr 02, 2003 at 02:48:07PM -0500, Pavel Roskin wrote:
> I've applied your patch.  The snapshot is ready.

After ten times of 'cvs up' I can see it now :)

> differently.  Ideally, mc should show all the data separately - host, user
> and PID (and maybe timestamp).

Ok, see the attached patch.
BTW I don't see a point in dividing host and user. Why?

> One bug that needs to be fixed - if I use Enter to modify the file and I
> get a "file locked" message, the old current line is not repainted.  Try
> it to see what I mean.

I see. I don't know why it happens. I haven't changed anything in
editor main code. It has to have something to do with
edit_query_dialog. I don't have time to debug it now...

Regards
Adam

-- 

  _.|._ |_  _.   :  Adam Byrtek /alpha               alpha debian org
 (_|||_)| |(_|   :  http://krakow.linux.org.pl/        pgp 0xB25952C0
     |           
? .project.sl
? mc.prj
? mc.pws
Index: edit/editlock.c
===================================================================
RCS file: /cvs/gnome/mc/edit/editlock.c,v
retrieving revision 1.1
diff -u -r1.1 editlock.c
--- edit/editlock.c	2 Apr 2003 19:36:10 -0000	1.1
+++ edit/editlock.c	2 Apr 2003 22:07:20 -0000
@@ -30,6 +30,11 @@
 #define BUF_SIZE 255
 #define PID_BUF_SIZE 10
 
+struct lock_s {
+    char *who;
+    pid_t pid;
+};
+
 /* Locking scheme used in mcedit is based on a documentation found
    in JED editor sources. Abstract from lock.c file (by John E. Davis):
 
@@ -61,24 +66,34 @@
 }
 
 /* Extract pid from user host domain pid string */
-static pid_t
-lock_extract_pid (char *str)
+static struct lock_s *
+lock_extract_info (char *str)
 {
     int i;
-    char *p, pid[PID_BUF_SIZE];
+    char *p, *s;
+    static char pid[PID_BUF_SIZE], who[BUF_SIZE];
+    static struct lock_s lock;
 
-    /* Treat text between '.' and ':' or '\0' as pid */
     for (p = str + strlen (str) - 1; p >= str; p--)
 	if (*p == '.')
 	    break;
 
+    /* Everything before last '.' is user host */
+    i = 0;
+    for (s = str; s < p && i < BUF_SIZE; s++)
+	who[i++] = *s;
+    who[i] = '\0';
+    
+    /* Treat text between '.' and ':' or '\0' as pid */
     i = 0;
     for (p = p + 1;
 	 p < str + strlen (str) && *p != ':' && i < PID_BUF_SIZE; p++)
 	pid[i++] = *p;
     pid[i] = '\0';
-
-    return (pid_t) atol (pid);
+    
+    lock.pid = (pid_t) atol (pid);
+    lock.who = who;
+    return &lock;
 }
 
 /* Extract user host domain pid from lock file (static string)  */
@@ -103,7 +118,7 @@
 {
     char *lockfname, *newlock, *msg, *lock;
     struct stat statbuf;
-    pid_t pid;
+    struct lock_s *lockinfo;
 
     /* Just to be sure (and don't lock new file) */
     if (!fname || !*fname)
@@ -117,13 +132,13 @@
 	    g_free (lockfname);
 	    return 0;
 	}
-	pid = lock_extract_pid (lock);
+	lockinfo = lock_extract_info (lock);
 
 	/* Check if locking process alive, ask user if required */
-	if (!pid || !(kill (pid, 0) == -1 && errno == ESRCH)) {
+	if (!lockinfo->pid || !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH)) {
 	    msg =
-		g_strdup_printf (_("File %s is locked by lock %s"), fname,
-				 lock);
+		g_strdup_printf (_("File %s is locked by %s (pid %d)"), 
+				 fname, lockinfo->who, lockinfo->pid);
 	    /* TODO: Implement "Abort" - needs to rewind undo stack */
 	    switch (edit_query_dialog2
 		    (_("File locked"), msg, _("&Grab lock"),
@@ -177,7 +192,7 @@
     lock = lock_get_info (lockfname);
     if (lock) {
 	/* Don't touch if lock is not ours */
-	if (lock_extract_pid (lock) != getpid ()) {
+	if (lock_extract_info (lock)->pid != getpid ()) {
 	    g_free (lockfname);
 	    return 0;
 	}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]