summaryrefslogtreecommitdiffstats
path: root/spawn.c
diff options
context:
space:
mode:
authornicm <nicm>2020-01-28 10:21:21 +0000
committernicm <nicm>2020-01-28 10:21:21 +0000
commit32816eaebd4ccd712cc7f7291a587146d122a9ff (patch)
tree4f48b9e736d8ab91f2af053d1a60608e92aeaef7 /spawn.c
parent24350879cdfb9ef23dee0da409b621e9830d8baf (diff)
Set up working directory before killing the existing pane on respawn.
Diffstat (limited to 'spawn.c')
-rw-r--r--spawn.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/spawn.c b/spawn.c
index 75995221..933f0c6a 100644
--- a/spawn.c
+++ b/spawn.c
@@ -226,6 +226,17 @@ spawn_pane(struct spawn_context *sc, char **cause)
spawn_log(__func__, sc);
/*
+ * Work out the current working directory. If respawning, use
+ * the pane's stored one unless specified.
+ */
+ if (sc->cwd != NULL)
+ cwd = format_single(item, sc->cwd, c, s, NULL, NULL);
+ else if (~sc->flags & SPAWN_RESPAWN)
+ cwd = xstrdup(server_client_get_cwd(c, s));
+ else
+ cwd = NULL;
+
+ /*
* If we are respawning then get rid of the old process. Otherwise
* either create a new cell or assign to the one we are given.
*/
@@ -235,6 +246,7 @@ spawn_pane(struct spawn_context *sc, char **cause)
window_pane_index(sc->wp0, &idx);
xasprintf(cause, "pane %s:%d.%u still active",
s->name, sc->wl->idx, idx);
+ free(cwd);
return (NULL);
}
if (sc->wp0->fd != -1) {
@@ -255,8 +267,8 @@ spawn_pane(struct spawn_context *sc, char **cause)
}
/*
- * Now we have a pane with nothing running in it ready for the new
- * process. Work out the command and arguments.
+ * Now we have a pane with nothing running in it ready for the new process.
+ * Work out the command and arguments and store the working directory.
*/
if (sc->argc == 0 && (~sc->flags & SPAWN_RESPAWN)) {
cmd = options_get_string(s->options, "default-command");
@@ -271,6 +283,10 @@ spawn_pane(struct spawn_context *sc, char **cause)
argc = sc->argc;
argv = sc->argv;
}
+ if (cwd != NULL) {
+ free(new_wp->cwd);
+ new_wp->cwd = cwd;
+ }
/*
* Replace the stored arguments if there are new ones. If not, the
@@ -282,21 +298,6 @@ spawn_pane(struct spawn_context *sc, char **cause)
new_wp->argv = cmd_copy_argv(argc, argv);
}
- /*
- * Work out the current working directory. If respawning, use
- * the pane's stored one unless specified.
- */
- if (sc->cwd != NULL)
- cwd = format_single(item, sc->cwd, c, s, NULL, NULL);
- else if (~sc->flags & SPAWN_RESPAWN)
- cwd = xstrdup(server_client_get_cwd(c, s));
- else
- cwd = NULL;
- if (cwd != NULL) {
- free(new_wp->cwd);
- new_wp->cwd = cwd;
- }
-
/* Create an environment for this pane. */
child = environ_for_session(s, 0);
if (sc->environ != NULL)