Change to the new working directory even if getcwd fails, GitHub issue 5658.

This commit is contained in:
nicm
2026-10-02 13:20:42 +00:00
committed by tmux update bot
parent 556235fbe2
commit a8523db838

18
spawn.c
View File

@@ -1,4 +1,4 @@
/* $OpenBSD: spawn.c,v 1.53 2026/09/21 12:43:36 nicm Exp $ */
/* $OpenBSD: spawn.c,v 1.54 2026/10/02 13:20:42 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -467,14 +467,14 @@ spawn_pane(struct spawn_context *sc, char **cause)
new_wp->flags &= ~PANE_EMPTY;
/* Store current working directory and change to new one. */
if (getcwd(path, sizeof path) != NULL) {
if (chdir(new_wp->cwd) == 0)
actual_cwd = new_wp->cwd;
else if (home != NULL && chdir(home) == 0)
actual_cwd = home;
else if (chdir("/") == 0)
actual_cwd = "/";
}
if (getcwd(path, sizeof path) == NULL)
strlcpy(path, "/", sizeof path);
if (chdir(new_wp->cwd) == 0)
actual_cwd = new_wp->cwd;
else if (home != NULL && chdir(home) == 0)
actual_cwd = home;
else if (chdir("/") == 0)
actual_cwd = "/";
/* Fork the new process. */
new_wp->pid = fdforkpty(ptm_fd, &new_wp->fd, new_wp->tty, NULL, &ws);