unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: control@bugs.debian.org, 3911@emacsbugs.donarmstrong.com
Cc: Chong Yidong <cyd@stupidchicken.com>
Subject: bug#3911: get-free-disk-space when default-directory doesn't exist
Date: Thu, 20 Aug 2009 08:03:42 +1000	[thread overview]
Message-ID: <87r5v7xxz5.fsf@blah.blah> (raw)
In-Reply-To: 87my5yexy4.fsf@stupidchicken.com

[-- Attachment #1: Type: text/plain, Size: 1983 bytes --]

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  <user42@zip.com.au>

	* 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.)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: files.el.disk-space-root-2.diff --]
[-- Type: text/x-diff, Size: 1028 bytes --]

*** 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

  parent reply	other threads:[~2009-08-19 22:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <871vnclhoz.fsf@cyd.mit.edu>
2009-07-23 22:19 ` bug#3911: 23.1.50; get-free-disk-space relative to non-existent default-directory Kevin Ryde
2009-08-16  0:40   ` bug#3911: marked as done (23.1.50; get-free-disk-space relative to non-existent default-directory) Emacs bug Tracking System
2009-10-02  0:35   ` bug#3911: marked as done (get-free-disk-space race condition on default-directory test) Emacs bug Tracking System
2009-08-18  0:23 ` bug#3911: get-free-disk-space when default-directory doesn't exist Kevin Ryde
2009-08-18  1:02   ` Chong Yidong
2009-08-19 21:43     ` Kevin Ryde
2009-08-19 22:03     ` Kevin Ryde [this message]
2009-08-22  3:57       ` Stefan Monnier
2009-08-24 23:45         ` Kevin Ryde
2009-08-25 18:29           ` Stefan Monnier
2009-08-29  1:32             ` Kevin Ryde
2009-08-29  3:37               ` Stefan Monnier
2009-09-01  1:37                 ` Kevin Ryde
2009-09-01  6:05                   ` Stefan Monnier
2009-09-07  0:28                     ` Kevin Ryde
     [not found] <87d4cjzf89.fsf@cyd.mit.edu>
2009-03-10 22:24 ` bug#2631: " Kevin Ryde
2009-03-11  2:10   ` Stefan Monnier
2009-03-11  4:23     ` Eli Zaretskii
2009-03-11 21:00     ` Kevin Ryde
2009-03-15  2:40   ` bug#2631: marked as done (get-free-disk-space when default-directory doesn't exist) Emacs bug Tracking System
2009-08-16  0:40   ` bug#2631: marked as done (get-free-disk-space when home dir also " Emacs bug Tracking System
2009-03-17  0:02 ` bug#2631: get-free-disk-space when default-directory doesn't exist Kevin Ryde
2009-03-17  4:05   ` Eli Zaretskii
2009-03-27 23:32     ` Kevin Ryde
2009-03-27 23:17   ` Kevin Ryde
2009-03-27 23:25     ` Processed: " Emacs bug Tracking System

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r5v7xxz5.fsf@blah.blah \
    --to=user42@zip.com.au \
    --cc=3911@emacsbugs.donarmstrong.com \
    --cc=control@bugs.debian.org \
    --cc=cyd@stupidchicken.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).