svn commit: r284649 - head/lib/libc/gen
Jilles Tjoelker
jilles at FreeBSD.org
Sat Jun 20 20:54:06 UTC 2015
Author: jilles
Date: Sat Jun 20 20:54:05 2015
New Revision: 284649
URL: https://svnweb.freebsd.org/changeset/base/284649
Log:
fts_children: preserve errno after running close/fchdir
PR: 200942
Submitted by: Conrad Meyer
Differential Revision: https://reviews.freebsd.org/D2852
MFC after: 1 week
Modified:
head/lib/libc/gen/fts.c
Modified: head/lib/libc/gen/fts.c
==============================================================================
--- head/lib/libc/gen/fts.c Sat Jun 20 19:34:50 2015 (r284648)
+++ head/lib/libc/gen/fts.c Sat Jun 20 20:54:05 2015 (r284649)
@@ -515,7 +515,7 @@ FTSENT *
fts_children(FTS *sp, int instr)
{
FTSENT *p;
- int fd;
+ int fd, rc, serrno;
if (instr != 0 && instr != FTS_NAMEONLY) {
errno = EINVAL;
@@ -571,11 +571,14 @@ fts_children(FTS *sp, int instr)
if ((fd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
return (NULL);
sp->fts_child = fts_build(sp, instr);
- if (fchdir(fd)) {
- (void)_close(fd);
- return (NULL);
- }
+ serrno = (sp->fts_child == NULL) ? errno : 0;
+ rc = fchdir(fd);
+ if (rc < 0 && serrno == 0)
+ serrno = errno;
(void)_close(fd);
+ errno = serrno;
+ if (rc < 0)
+ return (NULL);
return (sp->fts_child);
}
More information about the svn-src-all
mailing list