From 39146fac5cb7db4d0b68ba685722ca4713ddf722 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 21 Dec 2019 19:57:28 +0100 Subject: term: term_init: add 'cwd' argument This is used when spawning the slave, to set its current working directory just before we exec() the client. In a regular foot instance, we set the cwd from getcwd(). In a foot server instance, each connecting client sends its cwd to the server, and we use that. --- terminal.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index f7f98407..eb87661c 100644 --- a/terminal.c +++ b/terminal.c @@ -465,7 +465,8 @@ initialize_fonts(struct terminal *term, const struct config *conf) struct terminal * term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, - const char *term_env, const char *foot_exe, int argc, char *const *argv, + const char *term_env, const char *foot_exe, const char *cwd, + int argc, char *const *argv, void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data) { int ptmx = -1; @@ -601,18 +602,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, .shutdown_cb = shutdown_cb, .shutdown_data = shutdown_data, .foot_exe = strdup(foot_exe), - .cwd = NULL, + .cwd = strdup(cwd), }; - { - size_t buf_len = 1024; - do { - term->cwd = realloc(term->cwd, buf_len); - getcwd(term->cwd, buf_len); - buf_len *= 2; - } while (errno == ERANGE); - } - initialize_color_cube(term); if (!initialize_render_workers(term)) goto err; @@ -626,7 +618,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height); /* Start the slave/client */ - if ((term->slave = slave_spawn(term->ptmx, argc, argv, term_env, conf->shell)) == -1) + if ((term->slave = slave_spawn(term->ptmx, argc, term->cwd, argv, term_env, conf->shell)) == -1) goto err; /* Initiailze the Wayland window backend */ -- cgit v1.3