From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.emacs.bugs Subject: bug#3911: get-free-disk-space when default-directory doesn't exist Date: Thu, 20 Aug 2009 08:03:42 +1000 Message-ID: <87r5v7xxz5.fsf@blah.blah> References: <871vnclhoz.fsf@cyd.mit.edu> <87bpme9dhv.fsf@blah.blah> <87my5yexy4.fsf@stupidchicken.com> Reply-To: Kevin Ryde , 3911@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1250803116 11877 80.91.229.12 (20 Aug 2009 21:18:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Aug 2009 21:18:36 +0000 (UTC) Cc: Chong Yidong To: control@bugs.debian.org, 3911@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 20 23:18:28 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MeF1g-0007QB-F9 for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Aug 2009 23:18:28 +0200 Original-Received: from localhost ([127.0.0.1]:60009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeF1f-0007Jm-SM for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Aug 2009 17:18:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeF1R-0007G1-5h for bug-gnu-emacs@gnu.org; Thu, 20 Aug 2009 17:18:13 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeF1N-0007Ec-5E for bug-gnu-emacs@gnu.org; Thu, 20 Aug 2009 17:18:12 -0400 Original-Received: from [199.232.76.173] (port=58711 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeF1N-0007EW-0Q for bug-gnu-emacs@gnu.org; Thu, 20 Aug 2009 17:18:09 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:52315) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MeF1M-0007El-Ir for bug-gnu-emacs@gnu.org; Thu, 20 Aug 2009 17:18:08 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7KKkpoe019227; Thu, 20 Aug 2009 13:48:05 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n7KKb0rx017372; Thu, 20 Aug 2009 13:37:00 -0700 Resent-Date: Thu, 20 Aug 2009 13:37:00 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Kevin Ryde Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Thu, 20 Aug 2009 20:37:00 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 3911 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Original-Received: via spool by 3911-submit@emacsbugs.donarmstrong.com id=B3911.125071944231617 (code B ref 3911); Thu, 20 Aug 2009 20:37:00 +0000 Original-Received: (at 3911) by emacsbugs.donarmstrong.com; 19 Aug 2009 22:04:02 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from mailout1.pacific.net.au (mailout1-1.pacific.net.au [61.8.2.208]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7JM409k031614 for <3911@emacsbugs.donarmstrong.com>; Wed, 19 Aug 2009 15:04:01 -0700 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.2.163]) by mailout1.pacific.net.au (Postfix) with ESMTP id 1148E5035B2; Thu, 20 Aug 2009 08:03:59 +1000 (EST) Original-Received: from blah.blah (ppp27D5.dyn.pacific.net.au [61.8.39.213]) by mailproxy2.pacific.net.au (Postfix) with ESMTP id 394852742D; Thu, 20 Aug 2009 08:03:58 +1000 (EST) Original-Received: from gg by blah.blah with local (Exim 4.69) (envelope-from ) id 1MdtFu-0001bQ-SF; Thu, 20 Aug 2009 08:03:42 +1000 User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.3 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Thu, 20 Aug 2009 17:18:12 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:30373 Archived-At: --=-=-= reopen 3911 retitle 3911 get-free-disk-space race condition on default-directory test tags 3911 +patch thanks If the default-directory is flicking in and out of existence then the code in get-free-disk-space which chooses between default-directory and "/" can suffer a race condition. default-directory can exist for the test, but then be gone by the time call-process tries to use it. I can provoke this on my pc with one emacs making a directory flicker, (while t (make-directory "/tmp/somedir") (delete-directory "/tmp/somedir")) And in another emacs a loop (while t (let ((default-directory "/tmp/somedir/")) (get-free-disk-space "/"))) The latter loop errors out after 5 or 10 minutes. I hoped that asking get-free-disk-space about the space on some directory would not depend on the value of default-directory. The problem can be provoked much quicker with a (sit-for 0.1) between the test and the call-process. Otherwise I presume it requires a random context switch just at the inopportune time. The perils of "test before use" come up in shell scripts often (because it's hard to do better), and in sloppy perl code. Alas the tendency is to work most of the time, but lack robustness in special circumstances. I suppose the rule for call-process would be: if the operation is not related to default-directory then go to "/" so as to be independent of default-directory's existence, or bouncing in and out of existence. I expect that's why other places have "/". It sounds fairly simple, dunno if that's too obvious to have a crib in the manual (under "Subprocess Creation"). At any rate, umm, third time lucky with what I posted first ... 2009-08-20 Kevin Ryde * files.el (get-free-disk-space): Bind default-directory to "/", to be independent of default-directory existence. (Cannot test usability of default-directory first since it may disappear in between the test and the call-process.) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=files.el.disk-space-root-2.diff *** files.el 18 Aug 2009 08:51:19 +1000 1.1068 --- files.el 20 Aug 2009 08:03:13 +1000 *************** *** 5398,5409 **** (when (and directory-free-space-program ;; Avoid failure if the default directory does ;; not exist (Bug#2631, Bug#3911). ! (let ((default-directory default-directory)) ! (setq dir (expand-file-name dir)) ! (unless (and (not (file-remote-p default-directory)) ! (file-directory-p default-directory) ! (file-readable-p default-directory)) ! (setq default-directory "/")) (eq (call-process directory-free-space-program nil t nil directory-free-space-args --- 5398,5405 ---- (when (and directory-free-space-program ;; Avoid failure if the default directory does ;; not exist (Bug#2631, Bug#3911). ! (setq dir (expand-file-name dir)) ! (let ((default-directory "/")) (eq (call-process directory-free-space-program nil t nil directory-free-space-args --=-=-=--