aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2026-11-12 10:50:55 +0000
committerDaniel Eklöf <daniel@ekloef.se>2026-11-12 11:01:00 +0000
commitf51f18d33557ea9078f7781f4a4235706228f5c9 (patch)
tree7d518d3abac3ecc8bf2e38518c7c5ecbb6ee40a9 /server.c
parentime: reset view & cancel selection on text commit (diff)
spawn-terminal: spawn with all the original command line optionsspawn-terminal-cmdline-arguments
Before this, spawn-terminal would spawn a new foot or footclient, but *without* any of the command line options the user started the original foot/footclient with. We did have a hack for --config, but all other options were forgotten in the new instance. This patch fixes this. * term_init() stores the raw argc/argv in the terminal struct. * term_spawn_new() calls spawn() with the stored argc/argv. * for single instances, main() calls term_init() with the unparsed argc/argv. * the client/server protocol is extended to always send the raw argc/argv to the server. * the server calls term_init() with the argc/argv from the client. * bonus: on linux, we now use /proc/self/exe to determine which binary to launch. This means if you run e.g. a foot from your build tree, spawn-terminal will exec _that_ foot, not the system foot. A couple of behavioral changes, and/or side-effects, caused by the above (not exhaustive): * footclient -E: spawn-terminal will not use the _exact_ environment from the original footclient, but will simply pass -E to the new footclient. This means the new instance will inherit the *current* environment of the original instance. * foot htop: spawn-instance will _also_ launch a new foot+htop. Before this patch, spawn-instance would launch a new foot+shell. Closes #1622
Diffstat (limited to 'server.c')
-rw-r--r--server.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/server.c b/server.c
index 46560d5c..3b9455cf 100644
--- a/server.c
+++ b/server.c
@@ -146,7 +146,8 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
struct client *client = data;
struct server *server = client->server;
- char **argv = NULL;
+ char **foot_argv = NULL;
+ char **slave_argv = NULL;
config_override_t overrides = tll_init();
char **envp = NULL;
@@ -302,6 +303,10 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
memcpy(&cdata, p, sizeof(cdata));
p += sizeof(cdata);
+ CHECK_BUF_AND_NULL(cdata.exe_len);
+ const char *footclient_exe = (const char *)p; p += cdata.exe_len;
+ LOG_DBG("EXE = %.*s", cdata.exe_len, footclient_exe);
+
CHECK_BUF_AND_NULL(cdata.cwd_len);
const char *cwd = (const char *)p; p += cdata.cwd_len;
LOG_DBG("CWD = %.*s", cdata.cwd_len, cwd);
@@ -330,16 +335,28 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
tll_push_back(overrides, xstrdup(str));
}
- /* argv */
- argv = xcalloc(cdata.argc + 1, sizeof(argv[0]));
- for (uint16_t i = 0; i < cdata.argc; i++) {
+ /* foot argv (for spawn-terminal) */
+ foot_argv = xcalloc(cdata.foot_argc + 1, sizeof(foot_argv[0]));
+ for (uint16_t i = 0; i < cdata.foot_argc; i++) {
+ struct client_string arg;
+ CHECK_BUF(sizeof(arg));
+ memcpy(&arg, p, sizeof(arg)); p += sizeof(arg);
+
+ CHECK_BUF_AND_NULL(arg.len);
+ foot_argv[i] = (char *)p; p += arg.len;
+ LOG_DBG("foot argv[%hu] = %.*s", i, arg.len, foot_argv[i]);
+ }
+
+ /* slave argv */
+ slave_argv = xcalloc(cdata.slave_argc + 1, sizeof(slave_argv[0]));
+ for (uint16_t i = 0; i < cdata.slave_argc; i++) {
struct client_string arg;
CHECK_BUF(sizeof(arg));
memcpy(&arg, p, sizeof(arg)); p += sizeof(arg);
CHECK_BUF_AND_NULL(arg.len);
- argv[i] = (char *)p; p += arg.len;
- LOG_DBG("argv[%hu] = %.*s", i, arg.len, argv[i]);
+ slave_argv[i] = (char *)p; p += arg.len;
+ LOG_DBG("slave argv[%hu] = %.*s", i, arg.len, slave_argv[i]);
}
/* envp */
@@ -390,9 +407,9 @@ 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,
- NULL, cdata.argc, argv, (const char *const *)envp,
- &term_shutdown_handler, instance);
+ server->fdm, server->reaper, server->wayl, footclient_exe, cwd, token,
+ NULL, cdata.slave_argc, slave_argv, (const char *const *)envp,
+ cdata.foot_argc, (const char **)foot_argv, &term_shutdown_handler, instance);
if (instance->terminal == NULL) {
LOG_ERR("failed to instantiate new terminal");
@@ -410,7 +427,8 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
// the instance is attached to the client
instance->client = client;
client->instance = instance;
- free(argv);
+ free(foot_argv);
+ free(slave_argv);
free(envp);
tll_free_and_free(overrides, free);
}
@@ -420,7 +438,8 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
shutdown:
LOG_DBG("client FD=%d: disconnected", client->fd);
- free(argv);
+ free(foot_argv);
+ free(slave_argv);
free(envp);
tll_free_and_free(overrides, free);
fdm_del(fdm, fd);