comparison contrib/chg/chg.c @ 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
comparison
equal deleted inserted replaced
45849:731ea8fa1f11 45850:9534de20358f
286 debugmsg("tried to parse %s, but range error " 286 debugmsg("tried to parse %s, but range error "
287 "occurred", 287 "occurred",
288 de->d_name); 288 de->d_name);
289 continue; 289 continue;
290 } 290 }
291 if (fd_value > STDERR_FILENO) { 291 if (fd_value > STDERR_FILENO && fd_value != dirfd(dp)) {
292 debugmsg("closing fd %ld", fd_value); 292 debugmsg("closing fd %ld", fd_value);
293 int res = close(fd_value); 293 int res = close(fd_value);
294 if (res) { 294 if (res) {
295 debugmsg("tried to close fd %ld: %d " 295 debugmsg("tried to close fd %ld: %d "
296 "(errno: %d)", 296 "(errno: %d)",
297 fd_value, res, errno); 297 fd_value, res, errno);
298 } 298 }
299 } 299 }
300 } 300 }
301 closedir(dp);
301 } 302 }
302 303
303 if (putenv("CHGINTERNALMARK=") != 0) 304 if (putenv("CHGINTERNALMARK=") != 0)
304 abortmsgerrno("failed to putenv"); 305 abortmsgerrno("failed to putenv");
305 if (execvp(hgcmd, (char **)argv) < 0) 306 if (execvp(hgcmd, (char **)argv) < 0)