Bug 250077 - RHEL4 du doesn't report size of unreadable sub directories
Summary: RHEL4 du doesn't report size of unreadable sub directories
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: coreutils
Version: 4.5
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Tim Waugh
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 250087 250089
TreeView+ depends on / blocked
 
Reported: 2007-07-30 11:47 UTC by Jose Plans
Modified: 2007-11-23 17:25 UTC (History)
1 user (show)

Fixed In Version: RHBA-2007-0786
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-11-15 16:09:35 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Fix report size of unredable subdirectories. (543 bytes, patch)
2007-07-30 11:47 UTC, Jose Plans
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2007:0786 0 normal SHIPPED_LIVE coreutils bug fix update 2007-11-14 18:38:41 UTC

Description Jose Plans 2007-07-30 11:47:52 UTC
Description of problem:

When using du against a directory target that contains, whithin its tree,
non-accessible directories, du will not report the size of these. Since stat can
get the size, du should do it as well. Moreover, in the code it seems that this
was the intention, but a code bug has prevented this tool to report the size of
these directories:

--
                } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
                        if (ISSET(FTS_STOP))
                                return (NULL);
                        /* If fts_build's call to fts_safe_changedir failed
                           because it was not able to fchdir into a
                           subdirectory, tell the caller.  */

 			   because it was not able to fchdir into a
 			   subdirectory, tell the caller.  */
 			if (p->fts_errno)
-				p->fts_info = FTS_ERR;
+				if (p->fts_info != FTS_DNR)
+			    		p->fts_info = FTS_ERR;
 			/* FIXME: see if this should be in an else block */
 			LEAVE_DIR (sp, p, "2");
 			return (p);
--

fts_build will return NULL on problems, and if it couldn't opendir() a directory
it will set the flag fts_info to FTS_DNR which is an unreadable directory.
So not checking if we just reset the flag and avoid counting the size of that
directory, however, if we remember it, we can then stat and count its size.

Version-Release number of selected component (if applicable):
5.2.1

How reproducible:
Always

Steps to Reproduce:

1. cd /tmp
2. mkdir -p du_test/unreadable
3. du -a -b du_test
   4096    du_test/unreadable
   8192    du_test
4. chmod 000 du_test/unreadable
5. du -b -a du_test
   du: `du_test/unreadable': Permission denied
   4096    du_test
  
Actual results:
   du: `du_test/unreadable': Permission denied
   4096    du_test

Only the directories that can be readable are counted.

Expected results:
  du test
  4       test/dir
  du: cannot read directory `test/unreachable-dir': Permission denied
  12      test

Additional info:
Patch attached by Bryan Mason <bjmason>

Let me know if you need anything else,

Comment 1 Jose Plans 2007-07-30 11:47:53 UTC
Created attachment 160237 [details]
Fix report size of unredable subdirectories.

Comment 2 Jim Meyering 2007-07-30 12:10:30 UTC
Nice one!  Thanks.
That's a bug upstream, too.

Comment 4 RHEL Program Management 2007-07-30 12:33:58 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 5 Jim Meyering 2007-07-30 15:38:58 UTC
FYI, I've just applied Jose's patch in upstream gnulib:
http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=03e1d492b0

Comment 12 Murray McAllister 2007-10-06 08:23:17 UTC
Hi,

I'm writing the errata for this and I'm pretty sure this behavior occurs on Red
Hat Entperise Linux 5:

$ cd /tmp
$ mkdir -p du_test/unreadable
$ du du_test/
8       du_test/unreadable
16      du_test/
$chmod 000 du_test/unreadable/
$du du_test/
du: `du_test/unreadable': Permission denied
8       du_test/

coreutils: version 5.97, release 12.1.el5
kernel: 2.6.18-8.1.8.el5

Sorry if I've read all of this wrong and it is actually the correct behavior.
From this bugzilla I assumed the reponse should be:
  du test
  4       du_test/unreadable
  du: cannot read directory `du_test/unreadable': Permission denied
  12      test

Hope this helps.

Comment 13 Tim Waugh 2007-10-09 12:13:48 UTC
Indeed -- see bug #250087, which this bug blocks.

Comment 14 errata-xmlrpc 2007-11-15 16:09:35 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2007-0786.html



Note You need to log in before you can comment on or make changes to this bug.