Hi,

Loganaden Velvindron wrote on Sat, Dec 31, 2011 at 11:39:23AM -0500:

> In du.c, fts_close() is missing before exit.
> fts_close() may also return -1 on hitting an
> error.

Looking at fts.c, fts_close(3) does three things:

 1) lots of free(3)
 2) close(2)
 3) fchdir(2) back to the directory it was started in.

When exiting a process, 1) and 2) are automatic, and 3) has no lasting
effect.  The only thing that can make fts_close(3) fail is 3), in case
the directory was removed or access permissions changed since fts_open(3).
But why should it be an error to do:

 $ cd /some/large/tree
 $ du -s &
 $ cd
 $ sudo chown root:wheel /some/large
 $ sudo chmod 700 /some/large

Besides, that prevents printing of the "total" line with your diff.

Yours,
  Ingo


> Index: usr.bin/du/du.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/du/du.c,v
> retrieving revision 1.23
> diff -u -p -r1.23 du.c
> --- usr.bin/du/du.c   27 Apr 2011 07:52:11 -0000      1.23
> +++ usr.bin/du/du.c   31 Dec 2011 16:29:26 -0000
> @@ -202,6 +202,10 @@ main(int argc, char *argv[])
>               }
>       if (errno)
>               err(1, "fts_read");
> +     
> +     if (fts_close(fts) == -1)
> +             err(1, "fts_close");
> +     
>       if (cflag) {
>               prtout((quad_t)howmany(totalblocks, blocksize), "total", hflag);
>       }

Reply via email to