summaryrefslogtreecommitdiffstats
path: root/spawn.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2020-01-28 11:17:08 +0000
committerThomas Adam <thomas@xteddy.org>2020-01-28 11:17:08 +0000
commitee3d3db364b6c2469c1acaa88bb64341090d3af1 (patch)
treed3dcea5e527c32fa9948be6c74aa8bcbd8779970 /spawn.c
parent7cdf5ee9bc2fa114a7d830b73e2088d1a2dc5174 (diff)
parentf165221dc4641837ee9f589bb666d310a495904c (diff)
Merge branch 'obsd-master'
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 e7838816..d49d3adb 100644
--- a/spawn.c
+++ b/spawn.c
@@ -224,6 +224,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.
*/
@@ -233,6 +244,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) {
@@ -253,8 +265,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");
@@ -269,6 +281,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
@@ -280,21 +296,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)