bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] df: use open(2) to trigger automounting


From: Jim Meyering
Subject: Re: [PATCH] df: use open(2) to trigger automounting
Date: Tue, 28 Apr 2009 14:08:19 +0200

Tomáš Smetana wrote:
>   there is a problem with df when run on an automounted volume:
>
> $ df /misc/test; df /misc/test
> Filesystem           1K-blocks      Used Available Use% Mounted on
> -                            0         0         0   -  /misc
> Filesystem           1K-blocks      Used Available Use% Mounted on
> /tmp                  15013664   7302844   6935860  52% /misc/test
>
> The /misc/test is an automounted filesystem and as you can see the first run
> did not trigger the automount.  According to Ian Kent (autofs maintainer), an
> indirect map that uses the browse option won't trigger mounts for system
> calls such as stat(2), statfs(2) etc. to avoid mount storms when using such
> things as colour ls.  He also suggested to use some other call before stat(2)
> to make df automount the filesytem.  The following patch is a paraphrase of
> his suggestion rewritten according to Jim Meyering's instructions.
>
> ---
> From 4c064d1b4cc0666bdc5835a72ddf6018f08b4c2c Mon Sep 17 00:00:00 2001
> From: Tomas Smetana <address@hidden>
> Date: Tue, 28 Apr 2009 11:21:49 +0200
> Subject: [PATCH] df: use open(2) to trigger automounting
...

Thank you.
I've made some small aesthetic changes.
Also, I will add a NEWS entry, since this is a user-visible change.

>From a27b44357faab93989a6a048d90a249ae81dcab1 Mon Sep 17 00:00:00 2001
From: Tomas Smetana <address@hidden>
Date: Tue, 28 Apr 2009 11:21:49 +0200
Subject: [PATCH] df: use open(2), not stat, to trigger automounting

* src/df.c (main): When iterating over command-line arguments,
attempting to ensure each backing file system is mounted, use
open, not stat.  stat is no longer sufficient to trigger
automounting, in some cases.
More details in http://bugzilla.redhat.com/497830
---
 src/df.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/df.c b/src/df.c
index 7b8a082..a3eb98a 100644
--- a/src/df.c
+++ b/src/df.c
@@ -1,5 +1,5 @@
 /* df - summarize free disk space
-   Copyright (C) 91, 1995-2008 Free Software Foundation, Inc.
+   Copyright (C) 91, 1995-2009 Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -993,12 +993,15 @@ main (int argc, char **argv)
       stats = xnmalloc (argc - optind, sizeof *stats);
       for (i = optind; i < argc; ++i)
        {
-         if (stat (argv[i], &stats[i - optind]))
+         int fd = open (argv[i], O_RDONLY | O_NOCTTY);
+         if (fd < 0 || fstat (fd, &stats[i - optind]))
            {
              error (0, errno, "%s", quote (argv[i]));
              exit_status = EXIT_FAILURE;
              argv[i] = NULL;
            }
+         if (0 <= fd)
+           close (fd);
        }
     }

--
1.6.3.rc3.184.g9852e




reply via email to

[Prev in Thread] Current Thread [Next in Thread]