slave: check return value of chdir()

This commit is contained in:
Daniel Eklöf 2020-02-20 18:46:35 +01:00
parent 01f8719c77
commit f1b1ac39f6
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -103,7 +103,12 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
/* Child */
close(fork_pipe[0]); /* Close read end */
chdir(cwd);
if (chdir(cwd) < 0) {
const int _errno = errno;
LOG_ERRNO("failed to change working directory");
(void)!write(fork_pipe[1], &_errno, sizeof(_errno));
_exit(_errno);
}
/* Restore signals */
const struct sigaction sa = {.sa_handler = SIG_DFL};