From d7702d8443dae6073597f2cc4fa49f85dfeaaed2 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 1 Sep 2009 11:18:07 +0200 Subject: [PATCH] fts: fts_close now fails also when closing a dir file descriptor fails * lib/fts.c (fts_close): Detect close failure, not just fchdir failure, and propagate to caller, along with errno. --- ChangeLog | 4 ++++ lib/fts.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ff10df6cf..89cf0ee671 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-09-01 Jim Meyering + fts: fts_close now fails also when closing a dir file descriptor fails + * lib/fts.c (fts_close): Detect close failure, not just fchdir failure, + and propagate to caller, along with errno. + announce-gen: correct formatting in --help output * build-aux/announce-gen (usage): Move the one-line description in --help output "up", to where it belongs, just after Usage:. diff --git a/lib/fts.c b/lib/fts.c index bbcd1ff1f1..a30e38a32b 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -606,14 +606,20 @@ fts_close (FTS *sp) if (ISSET(FTS_CWDFD)) { if (0 <= sp->fts_cwd_fd) - close (sp->fts_cwd_fd); + if (close (sp->fts_cwd_fd)) + saved_errno = errno; } else if (!ISSET(FTS_NOCHDIR)) { /* Return to original directory, save errno if necessary. */ if (fchdir(sp->fts_rfd)) saved_errno = errno; - close(sp->fts_rfd); + + /* If close fails, record errno only if saved_errno is zero, + so that we report the probably-more-meaningful fchdir errno. */ + if (close (sp->fts_rfd)) + if (saved_errno == 0) + saved_errno = errno; } fd_ring_clear (&sp->fts_fd_ring); -- 2.30.2