From 445bbe3469b057c8b518f7c787527128f724cc1b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 30 Oct 2019 20:02:06 +0100 Subject: wayland: track multiple terminals The wayland 'term' member is gone and replaced by a list, 'terms'. This list contains all currently running terminal (windows). --- main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b09b5e3b..ebc35a20 100644 --- a/main.c +++ b/main.c @@ -146,20 +146,22 @@ main(int argc, char *const *argv) if ((term = term_init(&conf, fdm, wayl, argc, argv)) == NULL) goto out; - while (true) { - wl_display_flush(term->wl->display); /* TODO: figure out how to get rid of this */ + while (tll_length(wayl->terms) > 0) { + wl_display_flush(wayl->display); /* TODO: figure out how to get rid of this */ if (!fdm_poll(fdm)) break; } - if (term->quit) - ret = EXIT_SUCCESS; + ret = tll_length(wayl->terms) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; out: shm_fini(); - int child_ret = term_destroy(term); + int child_ret = EXIT_SUCCESS; + tll_foreach(wayl->terms, it) + child_ret = term_destroy(it->item); + wayl_destroy(wayl); fdm_destroy(fdm); config_free(conf); -- cgit v1.3 From b7546abca9828fb9017b801ed00a1d4f97044a2a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 30 Oct 2019 20:26:08 +0100 Subject: main: get exit value from wayland struct --- main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index ebc35a20..9a843b12 100644 --- a/main.c +++ b/main.c @@ -158,9 +158,10 @@ main(int argc, char *const *argv) out: shm_fini(); - int child_ret = EXIT_SUCCESS; tll_foreach(wayl->terms, it) - child_ret = term_destroy(it->item); + term_destroy(it->item); + + int child_ret = wayl->last_exit_value; wayl_destroy(wayl); fdm_destroy(fdm); -- cgit v1.3 From 291a928a49fbf1da3553aec0730ddd987a3f969a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 Nov 2019 20:01:36 +0100 Subject: render: call wl_display_flush() after rendering This allows us to remove that call from the main event loop. --- main.c | 1 - render.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 9a843b12..b9e0e5f7 100644 --- a/main.c +++ b/main.c @@ -147,7 +147,6 @@ main(int argc, char *const *argv) goto out; while (tll_length(wayl->terms) > 0) { - wl_display_flush(wayl->display); /* TODO: figure out how to get rid of this */ if (!fdm_poll(fdm)) break; diff --git a/render.c b/render.c index 29f2ebf0..b58eb7dc 100644 --- a/render.c +++ b/render.c @@ -693,6 +693,7 @@ grid_render(struct terminal *term) if (all_clean) { buf->busy = false; + wl_display_flush(term->wl->display); return; } @@ -727,6 +728,7 @@ grid_render(struct terminal *term) LOG_INFO("frame rendered in %lds %ldus", render_time.tv_sec, render_time.tv_usec); #endif + wl_display_flush(term->wl->display); } static void -- cgit v1.3 From 1e41a25f00aab1038486cff37e286fd5c729a72b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 Nov 2019 20:34:32 +0100 Subject: terminal: call user-defined callback when destroying terminal main uses this to get the exit code of the terminal. --- main.c | 33 +++++++++++++++++++++++---------- terminal.c | 9 ++++++++- terminal.h | 8 +++++++- wayland.h | 1 - 4 files changed, 38 insertions(+), 13 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b9e0e5f7..606b0199 100644 --- a/main.c +++ b/main.c @@ -26,14 +26,27 @@ static void print_usage(const char *prog_name) { - printf("Usage: %s [OPTION]...\n", prog_name); + printf("Usage: %s [OPTIONS]...\n", prog_name); printf("\n"); printf("Options:\n"); printf(" -f,--font=FONT comma separated list of fonts in fontconfig format (monospace)\n" " -t,--term=TERM value to set the environment variable TERM to (foot)\n" " -g,--geometry=WIDTHxHEIGHT set initial width and height\n" + " -s,--server run as a server\n" " -v,--version show the version number and quit\n"); - printf("\n"); +} + +struct shutdown_context { + struct terminal **term; + int exit_code; +}; + +static void +term_shutdown_cb(void *data, int exit_code) +{ + struct shutdown_context *ctx = data; + *ctx->term = NULL; + ctx->exit_code = exit_code; } int @@ -136,6 +149,7 @@ main(int argc, char *const *argv) struct fdm *fdm = NULL; struct wayland *wayl = NULL; struct terminal *term = NULL; + struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE}; if ((fdm = fdm_init()) == NULL) goto out; @@ -143,7 +157,10 @@ main(int argc, char *const *argv) if ((wayl = wayl_init(fdm)) == NULL) goto out; - if ((term = term_init(&conf, fdm, wayl, argc, argv)) == NULL) + if (!as_server && (term = term_init(&conf, fdm, wayl, argc, argv, + &term_shutdown_cb, &shutdown_ctx)) == NULL) + goto out; + goto out; while (tll_length(wayl->terms) > 0) { @@ -157,15 +174,11 @@ main(int argc, char *const *argv) out: shm_fini(); - tll_foreach(wayl->terms, it) - term_destroy(it->item); - - int child_ret = wayl->last_exit_value; - + server_destroy(server); + term_destroy(term); wayl_destroy(wayl); fdm_destroy(fdm); config_free(conf); - return ret == EXIT_SUCCESS ? child_ret : ret; - + return ret == EXIT_SUCCESS && !as_server ? shutdown_ctx.exit_code : ret; } diff --git a/terminal.c b/terminal.c index e0c76708..cbe67b58 100644 --- a/terminal.c +++ b/terminal.c @@ -289,7 +289,8 @@ initialize_fonts(struct terminal *term, const struct config *conf) struct terminal * term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, - int argc, char *const *argv) + int argc, char *const *argv, + void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data) { int ptmx = -1; int flash_fd = -1; @@ -411,6 +412,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, .lower_fd = delay_lower_fd, .upper_fd = delay_upper_fd, }, + .shutdown_cb = shutdown_cb, + .shutdown_data = shutdown_data, }; initialize_color_cube(term); @@ -484,8 +487,12 @@ fdm_shutdown(struct fdm *fdm, int fd, int events, void *data) assert(wayl->focused != term); assert(wayl->moused != term); + void (*cb)(void *, int) = term->shutdown_cb; + void *cb_data = term->shutdown_data; int exit_code = term_destroy(term); + if (cb != NULL) + cb(cb_data, exit_code); return true; } diff --git a/terminal.h b/terminal.h index 5a0473b3..3ec2802c 100644 --- a/terminal.h +++ b/terminal.h @@ -287,12 +287,18 @@ struct terminal { int lower_fd; int upper_fd; } delayed_render_timer; + + bool is_shutting_down; + void (*shutdown_cb)(void *data, int exit_code); + void *shutdown_data; }; struct config; struct terminal *term_init( const struct config *conf, struct fdm *fdm, struct wayland *wayl, - int argc, char *const *argv); + int argc, char *const *argv, + void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data); + bool term_shutdown(struct terminal *term); int term_destroy(struct terminal *term); diff --git a/wayland.h b/wayland.h index 7e7bfd4c..951a0ece 100644 --- a/wayland.h +++ b/wayland.h @@ -150,7 +150,6 @@ struct wayland { tll(struct terminal *) terms; struct terminal *focused; struct terminal *moused; - int last_exit_value; /* TODO: exit value from client(s)? */ }; struct wayland *wayl_init(struct fdm *fdm); -- cgit v1.3 From 32c6ed70699e341256428ffafd214aab1a6f52a2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 Nov 2019 20:35:42 +0100 Subject: main: register signal handlers for SIGINT and SIGTERM --- main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 606b0199..fa69459b 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,14 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) +static volatile sig_atomic_t aborted = 0; + +static void +sig_handler(int signo) +{ + aborted = 1; +} + static void print_usage(const char *prog_name) { @@ -164,6 +173,12 @@ main(int argc, char *const *argv) goto out; while (tll_length(wayl->terms) > 0) { + const struct sigaction sa = {.sa_handler = &sig_handler}; + if (sigaction(SIGINT, &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0) { + LOG_ERRNO("failed to register signal handlers"); + goto out; + } + if (!fdm_poll(fdm)) break; -- cgit v1.3 From a1efd65746cb0c464fac987e076ec3632e632445 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 Nov 2019 20:37:22 +0100 Subject: server: implement a --server mode In this mode, foot listens on a UNIX socket and creates terminal windows when clients connect. A connecting client sends argc/argv to the server, and the server instantiates a new terminal window. When the terminal window is closed, the exit code is sent back to the client. --- main.c | 16 +++- meson.build | 1 + server.c | 310 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ server.h | 9 ++ 4 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 server.c create mode 100644 server.h (limited to 'main.c') diff --git a/main.c b/main.c index fa69459b..f13a45d8 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,7 @@ #include "config.h" #include "fdm.h" #include "font.h" +#include "server.h" #include "shm.h" #include "terminal.h" #include "version.h" @@ -77,11 +78,14 @@ main(int argc, char *const *argv) {"term", required_argument, 0, 't'}, {"font", required_argument, 0, 'f'}, {"geometry", required_argument, 0, 'g'}, + {"server", no_argument, 0, 's'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {NULL, no_argument, 0, 0}, }; + bool as_server = false; + while (true) { int c = getopt_long(argc, argv, ":t:f:g:vh", longopts, NULL); if (c == -1) @@ -127,6 +131,10 @@ main(int argc, char *const *argv) break; } + case 's': + as_server = true; + break; + case 'v': printf("foot version %s\n", FOOT_VERSION); config_free(conf); @@ -158,6 +166,7 @@ main(int argc, char *const *argv) struct fdm *fdm = NULL; struct wayland *wayl = NULL; struct terminal *term = NULL; + struct server *server = NULL; struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE}; if ((fdm = fdm_init()) == NULL) @@ -170,21 +179,24 @@ main(int argc, char *const *argv) &term_shutdown_cb, &shutdown_ctx)) == NULL) goto out; + if (as_server && (server = server_init(&conf, fdm, wayl)) == NULL) goto out; - while (tll_length(wayl->terms) > 0) { const struct sigaction sa = {.sa_handler = &sig_handler}; if (sigaction(SIGINT, &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0) { LOG_ERRNO("failed to register signal handlers"); goto out; } + if (as_server) + LOG_INFO("running as server; launch terminals by running footclient"); + while (!aborted && (as_server || tll_length(wayl->terms) > 0)) { if (!fdm_poll(fdm)) break; } - ret = tll_length(wayl->terms) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + ret = aborted || tll_length(wayl->terms) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; out: shm_fini(); diff --git a/meson.build b/meson.build index da91ff91..bb7ecef3 100644 --- a/meson.build +++ b/meson.build @@ -78,6 +78,7 @@ executable( 'render.c', 'render.h', 'search.c', 'search.h', 'selection.c', 'selection.h', + 'server.c', 'server.h', 'shm.c', 'shm.h', 'slave.c', 'slave.h', 'terminal.c', 'terminal.h', diff --git a/server.c b/server.c new file mode 100644 index 00000000..ae6d678e --- /dev/null +++ b/server.c @@ -0,0 +1,310 @@ +#include "server.h" + +#include + +#include +#include +#include +#include + +#include + +#define LOG_MODULE "server" +#define LOG_ENABLE_DBG 1 +#include "log.h" +#include "terminal.h" +#include "tllist.h" + +struct client; +struct server { + const struct config *conf; + struct fdm *fdm; + struct wayland *wayl; + + int fd; + char *sock_path; + + tll(struct client *) clients; +}; + +struct client { + struct server *server; + int fd; + + struct terminal *term; + int argc; + char **argv; +}; + +static void +client_destroy(struct client *client) +{ + if (client == NULL) + return; + + if (client->term != NULL) { + LOG_WARN("client FD=%d: terminal still alive", client->fd); + term_destroy(client->term); + } + + if (client->argv != NULL) { + for (int i = 0; i < client->argc; i++) + free(client->argv[i]); + free(client->argv); + } + + if (client->fd != -1) { + LOG_DBG("client FD=%d: disconnected", client->fd); + fdm_del(client->server->fdm, client->fd); + } + + tll_foreach(client->server->clients, it) { + if (it->item == client) { + tll_remove(client->server->clients, it); + break; + } + } + + free(client); +} + +static void +client_send_exit_code(struct client *client, int exit_code) +{ + if (client->fd == -1) + return; + + if (write(client->fd, &exit_code, sizeof(exit_code)) != sizeof(exit_code)) + LOG_ERRNO("failed to write slave exit code to client"); +} + +static void +term_shutdown_handler(void *data, int exit_code) +{ + struct client *client = data; + + client_send_exit_code(client, exit_code); + + client->term = NULL; + client_destroy(client); +} + +static bool +fdm_client(struct fdm *fdm, int fd, int events, void *data) +{ + struct client *client = data; + struct server *server = client->server; + + if (events & EPOLLHUP) + goto shutdown; + + assert(events & EPOLLIN); + + if (recv(fd, &client->argc, sizeof(client->argc), 0) != sizeof(client->argc)) + goto shutdown; + + client->argv = calloc(client->argc + 1, sizeof(client->argv[0])); + for (int i = 0; i < client->argc; i++) { + uint16_t len; + if (recv(fd, &len, sizeof(len), 0) != sizeof(len)) + goto shutdown; + + client->argv[i] = malloc(len + 1); + client->argv[i][len] = '\0'; + if (recv(fd, client->argv[i], len, 0) != len) + goto shutdown; + } + + assert(client->term == NULL); + client->term = term_init( + server->conf, server->fdm, server->wayl, client->argc, client->argv, + &term_shutdown_handler, client); + + if (client->term == NULL) { + LOG_ERR("failed to instantiate new terminal"); + goto shutdown; + } + + return true; + +shutdown: + LOG_DBG("client FD=%d: disconnected", client->fd); + + fdm_del(fdm, fd); + client->fd = -1; + + if (client->term != NULL && !client->term->is_shutting_down) + term_shutdown(client->term); + else + client_destroy(client); + + return true; +} + +static bool +fdm_server(struct fdm *fdm, int fd, int events, void *data) +{ + if (events & EPOLLHUP) + return false; + + struct server *server = data; + + struct sockaddr_un addr; + socklen_t addr_size = sizeof(addr); + int client_fd = accept4( + server->fd, (struct sockaddr *)&addr, &addr_size, SOCK_CLOEXEC); + + if (client_fd == -1) { + LOG_ERRNO("failed to accept client connection"); + return false; + } + + struct client *client = malloc(sizeof(*client)); + *client = (struct client) { + .server = server, + .fd = client_fd, + }; + + if (!fdm_add(server->fdm, client_fd, EPOLLIN, &fdm_client, client)) { + LOG_ERR("client FD=%d: failed to add client to FDM", client_fd); + close(client_fd); + free(client); + return false; + } + + LOG_DBG("client FD=%d: connected", client_fd); + tll_push_back(server->clients, client); + return true; +} + +static char * +get_socket_path(void) +{ + const char *xdg_runtime = getenv("XDG_RUNTIME_DIR"); + if (xdg_runtime == NULL) + return strdup("/tmp/foot.sock"); + + char *path = malloc(strlen(xdg_runtime) + 1 + strlen("foot.sock") + 1); + sprintf(path, "%s/foot.sock", xdg_runtime); + return path; +} + +enum connect_status {CONNECT_ERR, CONNECT_FAIL, CONNECT_SUCCESS}; + +static enum connect_status +try_connect(const char *sock_path) +{ + enum connect_status ret = CONNECT_ERR; + + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd == -1) { + LOG_ERRNO("failed to create UNIX socket"); + goto err; + } + + struct sockaddr_un addr = {.sun_family = AF_UNIX}; + strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1); + + ret = connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) < 0 + ? CONNECT_FAIL : CONNECT_SUCCESS; + +err: + if (fd != -1) + close(fd); + return ret; +} + +struct server * +server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl) +{ + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd == -1) { + LOG_ERRNO("failed to create UNIX socket"); + return NULL; + } + + struct server *server = NULL; + char *sock_path = NULL; + + if ((sock_path = get_socket_path()) == NULL) + goto err; + + switch (try_connect(sock_path)) { + case CONNECT_FAIL: + break; + + case CONNECT_SUCCESS: + LOG_ERR("foot --server already running"); + /* FALLTHROUGH */ + + case CONNECT_ERR: + goto err; + } + + unlink(sock_path); + + if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | FD_CLOEXEC) < 0) { + LOG_ERRNO("failed to set FD_CLOEXEC on socket"); + goto err; + } + + struct sockaddr_un addr = {.sun_family = AF_UNIX}; + strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1); + + if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) < 0) { + LOG_ERRNO("%s: failed to bind", addr.sun_path); + goto err; + } + + if (listen(fd, 0) < 0) { + LOG_ERRNO("%s: failed to listen", addr.sun_path); + goto err; + } + + server = malloc(sizeof(*server)); + *server = (struct server) { + .conf = conf, + .fdm = fdm, + .wayl = wayl, + + .fd = fd, + .sock_path = sock_path, + + .clients = tll_init(), + }; + + if (!fdm_add(fdm, fd, EPOLLIN, &fdm_server, server)) { + LOG_ERR("failed to add server FD to the FDM"); + goto err; + } + + return server; + +err: + free(server); + free(sock_path); + if (fd != -1) + close(fd); + return NULL; +} + +void +server_destroy(struct server *server) +{ + if (server == NULL) + return; + + LOG_DBG("server destroy, %zu clients still alive", + tll_length(server->clients)); + + tll_foreach(server->clients, it) { + client_send_exit_code(it->item, 1); + client_destroy(it->item); + } + + tll_free(server->clients); + + fdm_del(server->fdm, server->fd); + free(server->sock_path); + free(server); +} diff --git a/server.h b/server.h new file mode 100644 index 00000000..a5f34071 --- /dev/null +++ b/server.h @@ -0,0 +1,9 @@ +#pragma once + +#include "fdm.h" +#include "config.h" +#include "wayland.h" + +struct server; +struct server *server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl); +void server_destroy(struct server *server); -- cgit v1.3 From 69d62d3cd2918bee089fc879e381820349497483 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 Nov 2019 21:01:15 +0100 Subject: slave: set TERM environment variable in slave process --- main.c | 1 - slave.c | 5 ++++- slave.h | 2 +- terminal.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index f13a45d8..c1abe5bc 100644 --- a/main.c +++ b/main.c @@ -161,7 +161,6 @@ main(int argc, char *const *argv) argv += optind; setlocale(LC_ALL, ""); - setenv("TERM", conf.term, 1); struct fdm *fdm = NULL; struct wayland *wayl = NULL; diff --git a/slave.c b/slave.c index 0e762bf0..1f70a0d8 100644 --- a/slave.c +++ b/slave.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 500 #include "slave.h" + #include #include #include @@ -68,7 +69,7 @@ err: pid_t slave_spawn(int ptmx, int argc, char *const *argv, - const char *conf_shell) + const char *term_env, const char *conf_shell) { int fork_pipe[2]; if (pipe2(fork_pipe, O_CLOEXEC) < 0) { @@ -88,6 +89,8 @@ slave_spawn(int ptmx, int argc, char *const *argv, /* Child */ close(fork_pipe[0]); /* Close read end */ + setenv("TERM", term_env, 1); + char **_shell_argv = NULL; char *const *shell_argv = argv; diff --git a/slave.h b/slave.h index cfb18af2..f1a9848a 100644 --- a/slave.h +++ b/slave.h @@ -4,4 +4,4 @@ #include pid_t slave_spawn( - int ptmx, int argc, char *const *argv, const char *conf_shell); + int ptmx, int argc, char *const *argv, const char *term_env, const char *conf_shell); diff --git a/terminal.c b/terminal.c index cbe67b58..d6aaf4ff 100644 --- a/terminal.c +++ b/terminal.c @@ -428,7 +428,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, conf->shell)) == -1) + if ((term->slave = slave_spawn(term->ptmx, argc, argv, conf->term, conf->shell)) == -1) goto err; /* Initiailze the Wayland window backend */ -- cgit v1.3 From 0bd2ddd8ad60a77e27cdb459da8e319647fd6f59 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 Nov 2019 21:03:08 +0100 Subject: term_init(): initialize slave TERM from term_init() argument --- main.c | 2 +- server.c | 4 ++-- terminal.c | 4 ++-- terminal.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index c1abe5bc..26a8f300 100644 --- a/main.c +++ b/main.c @@ -174,7 +174,7 @@ main(int argc, char *const *argv) if ((wayl = wayl_init(fdm)) == NULL) goto out; - if (!as_server && (term = term_init(&conf, fdm, wayl, argc, argv, + if (!as_server && (term = term_init(&conf, fdm, wayl, conf.term, argc, argv, &term_shutdown_cb, &shutdown_ctx)) == NULL) goto out; diff --git a/server.c b/server.c index ae6d678e..f48ed262 100644 --- a/server.c +++ b/server.c @@ -117,8 +117,8 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) assert(client->term == NULL); client->term = term_init( - server->conf, server->fdm, server->wayl, client->argc, client->argv, - &term_shutdown_handler, client); + server->conf, server->fdm, server->wayl, server->conf->term, + client->argc, client->argv, &term_shutdown_handler, client); if (client->term == NULL) { LOG_ERR("failed to instantiate new terminal"); diff --git a/terminal.c b/terminal.c index d6aaf4ff..f71d90a6 100644 --- a/terminal.c +++ b/terminal.c @@ -289,7 +289,7 @@ initialize_fonts(struct terminal *term, const struct config *conf) struct terminal * term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, - int argc, char *const *argv, + const char *term_env, int argc, char *const *argv, void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data) { int ptmx = -1; @@ -428,7 +428,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, conf->term, conf->shell)) == -1) + if ((term->slave = slave_spawn(term->ptmx, argc, argv, term_env, conf->shell)) == -1) goto err; /* Initiailze the Wayland window backend */ diff --git a/terminal.h b/terminal.h index 3ec2802c..11571519 100644 --- a/terminal.h +++ b/terminal.h @@ -296,7 +296,7 @@ struct terminal { struct config; struct terminal *term_init( const struct config *conf, struct fdm *fdm, struct wayland *wayl, - int argc, char *const *argv, + const char *term_env, int argc, char *const *argv, void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data); bool term_shutdown(struct terminal *term); -- cgit v1.3