Commit dc76bc47 authored by Niels Möller's avatar Niels Möller
Browse files

(lsh_pushd): Close fd if stat fails.

(lsh_pushd): Set close-on-exec flag on the fd that may be returned
in *result.
(lsh_pushd): Fixed EINTR handling for fchdir.

Rev: src/io.c:1.218
parent a5fff3ba
......@@ -1225,10 +1225,13 @@ lsh_pushd(const char *directory,
if (fd < 0)
return -1;
io_set_close_on_exec(fd);
if (fstat(fd, &sbuf) < 0)
{
werror("io.c: Failed to stat `%z'.\n"
" %e\n", directory, errno);
close(fd);
return -1;
}
......@@ -1287,11 +1290,12 @@ lsh_pushd(const char *directory,
* probably fchdir back to old_cd later. */
while (fchdir(fd) < 0)
{
close(fd);
close(old_cd);
return -1;
}
if (errno != EINTR)
{
close(fd);
close(old_cd);
return -1;
}
if (result)
*result = fd;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment