From ac30da7a01b55ec4778f96c70dc3b8b6ab791272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 30 Aug 2021 17:55:36 +0200 Subject: [PATCH] =?UTF-8?q?spawn:=20don=E2=80=99t=20error=20out=20if=20we?= =?UTF-8?q?=20fail=20to=20chdir()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ spawn.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51f06141..e168cdc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,8 @@ now translated to pixel values using the monitor’s scaling factor when `dpi-aware=no`, or `dpi-aware=auto` and the scaling factor is larger than 1 (https://codeberg.org/dnkl/foot/issues/680). +* Spawning a new terminal with a working directory that does not exist + is no longer a fatal error. ### Removed diff --git a/spawn.c b/spawn.c index 8adef19d..d02ab131 100644 --- a/spawn.c +++ b/spawn.c @@ -48,6 +48,11 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[], if (sigaction(SIGHUP, &(struct sigaction){.sa_handler = SIG_DFL}, NULL) < 0) goto child_err; + if (cwd != NULL && chdir(cwd) < 0) { + LOG_WARN("failed to change working directory to %s: %s", + cwd, strerror(errno)); + } + bool close_stderr = stderr_fd >= 0; bool close_stdout = stdout_fd >= 0 && stdout_fd != stderr_fd; bool close_stdin = stdin_fd >= 0 && stdin_fd != stdout_fd && stdin_fd != stderr_fd; @@ -58,7 +63,6 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[], || (close_stdout && close(stdout_fd) < 0))) || (stderr_fd >= 0 && (dup2(stderr_fd, STDERR_FILENO) < 0 || (close_stderr && close(stderr_fd) < 0))) || - (cwd != NULL && chdir(cwd) < 0) || execvp(argv[0], argv) < 0) { goto child_err;