changeset 45850:9534de20358f stable

chg: do not close dir fd while iterating It works so long as the dp is the last entry, but readdir(dp) would fail with EBADF. Let's not do that and close the dir fd explicitly.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 03 Nov 2020 11:15:50 +0900
parents 731ea8fa1f11
children 81da6feb5000
files contrib/chg/chg.c
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/chg.c	Tue Nov 03 11:12:25 2020 +0900
+++ b/contrib/chg/chg.c	Tue Nov 03 11:15:50 2020 +0900
@@ -288,7 +288,7 @@
 				         de->d_name);
 				continue;
 			}
-			if (fd_value > STDERR_FILENO) {
+			if (fd_value > STDERR_FILENO && fd_value != dirfd(dp)) {
 				debugmsg("closing fd %ld", fd_value);
 				int res = close(fd_value);
 				if (res) {
@@ -298,6 +298,7 @@
 				}
 			}
 		}
+		closedir(dp);
 	}
 
 	if (putenv("CHGINTERNALMARK=") != 0)