Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Aug 2015 15:53:03 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r286534 - stable/10/lib/libc/gen
Message-ID:  <201508091553.t79Fr307001947@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Aug  9 15:53:02 2015
New Revision: 286534
URL: https://svnweb.freebsd.org/changeset/base/286534

Log:
  MFC r284649: fts_children: preserve errno after running close/fchdir
  
  PR:		200942
  Submitted by:	Conrad Meyer

Modified:
  stable/10/lib/libc/gen/fts.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/fts.c
==============================================================================
--- stable/10/lib/libc/gen/fts.c	Sun Aug  9 15:51:56 2015	(r286533)
+++ stable/10/lib/libc/gen/fts.c	Sun Aug  9 15:53:02 2015	(r286534)
@@ -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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508091553.t79Fr307001947>