From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Bug in filelock.c Date: Sat, 23 Feb 2013 11:39:43 -0800 Organization: UCLA Computer Science Department Message-ID: <51291AFF.2000602@cs.ucla.edu> References: <83zjyukfxe.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1361648401 856 80.91.229.3 (23 Feb 2013 19:40:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Feb 2013 19:40:01 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 23 20:40:24 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U9KxH-00060X-Dp for ged-emacs-devel@m.gmane.org; Sat, 23 Feb 2013 20:40:19 +0100 Original-Received: from localhost ([::1]:52587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9Kww-0000KV-FH for ged-emacs-devel@m.gmane.org; Sat, 23 Feb 2013 14:39:58 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:55684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9Kwo-0000JF-AT for emacs-devel@gnu.org; Sat, 23 Feb 2013 14:39:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9Kwl-00038S-8l for emacs-devel@gnu.org; Sat, 23 Feb 2013 14:39:50 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:33579) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9Kwi-00037C-T8; Sat, 23 Feb 2013 14:39:45 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 0DF84A60003; Sat, 23 Feb 2013 11:39:44 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BGJAQFzJsddu; Sat, 23 Feb 2013 11:39:43 -0800 (PST) Original-Received: from [192.168.1.9] (pool-71-189-154-249.lsanca.fios.verizon.net [71.189.154.249]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 93BFDA60002; Sat, 23 Feb 2013 11:39:43 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 In-Reply-To: <83zjyukfxe.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:157280 Archived-At: On 02/23/2013 11:07 AM, Eli Zaretskii wrote: > Am I missing something? No, it looks like a clear bug. Thanks for catching it! Also, that "p != lockfile" business is bogus; p can never equal lockfile. Since the code has obviously never worked and evidently never been needed and slows Emacs down with unnecessary syscalls, I propose that we remove it, as follows: === modified file 'src/filelock.c' --- src/filelock.c 2013-02-01 06:30:51 +0000 +++ src/filelock.c 2013-02-23 19:37:31 +0000 @@ -289,44 +289,31 @@ typedef struct /* Write the name of the lock file for FN into LFNAME. Length will be - that of FN plus two more for the leading `.#' plus 1 for the - trailing period plus one for the digit after it plus one for the + that of FN plus two more for the leading `.#' plus one for the null. */ #define MAKE_LOCK_NAME(lock, file) \ - (lock = alloca (SBYTES (file) + 2 + 1 + 1 + 1), \ + (lock = alloca (SBYTES (file) + 2 + 1), \ fill_in_lock_file_name (lock, (file))) static void fill_in_lock_file_name (register char *lockfile, register Lisp_Object fn) { ptrdiff_t length = SBYTES (fn); - register char *p; - struct stat st; - int count = 0; + char *p; strcpy (lockfile, SSDATA (fn)); /* Shift the nondirectory part of the file name (including the null) right two characters. Here is one of the places where we'd have to do something to support 14-character-max file names. */ - for (p = lockfile + length; p != lockfile && *p != '/'; p--) + p = lockfile + length; + do p[2] = *p; + while (*--p != '/'); /* Insert the `.#'. */ p[1] = '.'; p[2] = '#'; - - p = p + length + 2; - - while (lstat (lockfile, &st) == 0 && !S_ISLNK (st.st_mode)) - { - if (count > 9) - { - *p = '\0'; - return; - } - sprintf (p, ".%d", count++); - } } /* Lock the lock file named LFNAME.