diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-04-11 10:19:40 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-04-12 13:07:40 +0000 |
| commit | d02124902b4e27c3ed3ef48442ce17c5e0af9d56 (patch) | |
| tree | 517a07bdc4b2f26a2c3d30fcb1ee102c87622e7e /server.c | |
| parent | csi: reduce duplication in code handling SGR 38 and 48 sequences (diff) | |
client: add -E,--client-environment
When this option is used, the child process in the new terminal
instance will inherit its environment from the footclient process,
instead of the foot server’s.
Implemented by sending (yet another) dynamic string list as part of
the client -> server setup packet. When the new option is *not* used,
the setup packet is now 2 bytes larger than before.
On the server side, the slave process now uses execvpe() instead of
execvp(). There’s plumbing to propagate a new ‘envp’ argument from
term_init() all the way down to slave_exec(). If ‘envp’ is NULL, we
use ‘environ’ instead (thus matching the old behavior of execvp()).
Closes #1004
Diffstat (limited to 'server.c')
| -rw-r--r-- | server.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -146,6 +146,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) char **argv = NULL; config_override_t overrides = tll_init(); + char **envp = NULL; if (events & EPOLLHUP) goto shutdown; @@ -281,7 +282,21 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) argv[i] = (char *)p; p += arg.len; LOG_DBG("argv[%hu] = %.*s", i, arg.len, argv[i]); } - argv[cdata.argc] = NULL; + + /* envp */ + envp = cdata.env_count != 0 + ? xcalloc(cdata.env_count + 1, sizeof(envp[0])) + : NULL; + + for (uint16_t i = 0; i < cdata.env_count; i++) { + struct client_string e; + CHECK_BUF(sizeof(e)); + memcpy(&e, p, sizeof(e)); p += sizeof(e); + + CHECK_BUF_AND_NULL(e.len); + envp[i] = (char *)p; p += e.len; + LOG_DBG("env[%hu] = %.*s", i, e.len, envp[i]); + } #undef CHECK_BUF_AND_NULL #undef CHECK_BUF @@ -317,7 +332,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) instance->terminal = term_init( conf != NULL ? conf : server->conf, server->fdm, server->reaper, server->wayl, "footclient", cwd, token, - cdata.argc, argv, &term_shutdown_handler, instance); + cdata.argc, argv, envp, &term_shutdown_handler, instance); if (instance->terminal == NULL) { LOG_ERR("failed to instantiate new terminal"); @@ -336,6 +351,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) instance->client = client; client->instance = instance; free(argv); + free(envp); tll_free_and_free(overrides, free); } @@ -345,6 +361,7 @@ shutdown: LOG_DBG("client FD=%d: disconnected", client->fd); free(argv); + free(envp); tll_free_and_free(overrides, free); fdm_del(fdm, fd); client->fd = -1; |
