mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-14 05:33:59 -04:00
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.
This commit is contained in:
parent
277735db65
commit
39146fac5c
6 changed files with 28 additions and 18 deletions
18
main.c
18
main.c
|
|
@ -7,6 +7,7 @@
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
|
|
@ -217,6 +218,16 @@ main(int argc, char *const *argv)
|
||||||
struct server *server = NULL;
|
struct server *server = NULL;
|
||||||
struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE};
|
struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE};
|
||||||
|
|
||||||
|
char *cwd = NULL;
|
||||||
|
{
|
||||||
|
size_t buf_len = 1024;
|
||||||
|
do {
|
||||||
|
cwd = realloc(cwd, buf_len);
|
||||||
|
getcwd(cwd, buf_len);
|
||||||
|
buf_len *= 2;
|
||||||
|
} while (errno == ERANGE);
|
||||||
|
}
|
||||||
|
|
||||||
if ((fdm = fdm_init()) == NULL)
|
if ((fdm = fdm_init()) == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -224,9 +235,12 @@ main(int argc, char *const *argv)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!as_server && (term = term_init(
|
if (!as_server && (term = term_init(
|
||||||
&conf, fdm, wayl, conf.term, "foot", argc, argv,
|
&conf, fdm, wayl, conf.term, "foot", cwd, argc, argv,
|
||||||
&term_shutdown_cb, &shutdown_ctx)) == NULL)
|
&term_shutdown_cb, &shutdown_ctx)) == NULL) {
|
||||||
|
free(cwd);
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
free(cwd);
|
||||||
|
|
||||||
if (as_server && (server = server_init(&conf, fdm, wayl)) == NULL)
|
if (as_server && (server = server_init(&conf, fdm, wayl)) == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
2
server.c
2
server.c
|
|
@ -220,7 +220,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
|
||||||
client->term = term_init(
|
client->term = term_init(
|
||||||
server->conf, server->fdm, server->wayl,
|
server->conf, server->fdm, server->wayl,
|
||||||
strlen(term_env) > 0 ? term_env : server->conf->term,
|
strlen(term_env) > 0 ? term_env : server->conf->term,
|
||||||
"footclient", argc, argv, &term_shutdown_handler, client);
|
"footclient", cwd, argc, argv, &term_shutdown_handler, client);
|
||||||
|
|
||||||
if (client->term == NULL) {
|
if (client->term == NULL) {
|
||||||
LOG_ERR("failed to instantiate new terminal");
|
LOG_ERR("failed to instantiate new terminal");
|
||||||
|
|
|
||||||
4
slave.c
4
slave.c
|
|
@ -69,7 +69,7 @@ err:
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t
|
pid_t
|
||||||
slave_spawn(int ptmx, int argc, char *const *argv,
|
slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
|
||||||
const char *term_env, const char *conf_shell)
|
const char *term_env, const char *conf_shell)
|
||||||
{
|
{
|
||||||
int fork_pipe[2];
|
int fork_pipe[2];
|
||||||
|
|
@ -90,6 +90,8 @@ slave_spawn(int ptmx, int argc, char *const *argv,
|
||||||
/* Child */
|
/* Child */
|
||||||
close(fork_pipe[0]); /* Close read end */
|
close(fork_pipe[0]); /* Close read end */
|
||||||
|
|
||||||
|
chdir(cwd);
|
||||||
|
|
||||||
/* Restore signals */
|
/* Restore signals */
|
||||||
const struct sigaction sa = {.sa_handler = SIG_DFL};
|
const struct sigaction sa = {.sa_handler = SIG_DFL};
|
||||||
if (sigaction(SIGINT, &sa, NULL) < 0 ||
|
if (sigaction(SIGINT, &sa, NULL) < 0 ||
|
||||||
|
|
|
||||||
3
slave.h
3
slave.h
|
|
@ -4,4 +4,5 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
pid_t slave_spawn(
|
pid_t slave_spawn(
|
||||||
int ptmx, int argc, char *const *argv, const char *term_env, const char *conf_shell);
|
int ptmx, int argc, const char *cwd, char *const *argv, const char *term_env,
|
||||||
|
const char *conf_shell);
|
||||||
|
|
|
||||||
16
terminal.c
16
terminal.c
|
|
@ -465,7 +465,8 @@ initialize_fonts(struct terminal *term, const struct config *conf)
|
||||||
|
|
||||||
struct terminal *
|
struct terminal *
|
||||||
term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
|
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)
|
void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data)
|
||||||
{
|
{
|
||||||
int ptmx = -1;
|
int ptmx = -1;
|
||||||
|
|
@ -601,18 +602,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
|
||||||
.shutdown_cb = shutdown_cb,
|
.shutdown_cb = shutdown_cb,
|
||||||
.shutdown_data = shutdown_data,
|
.shutdown_data = shutdown_data,
|
||||||
.foot_exe = strdup(foot_exe),
|
.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);
|
initialize_color_cube(term);
|
||||||
if (!initialize_render_workers(term))
|
if (!initialize_render_workers(term))
|
||||||
goto err;
|
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);
|
LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height);
|
||||||
|
|
||||||
/* Start the slave/client */
|
/* 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;
|
goto err;
|
||||||
|
|
||||||
/* Initiailze the Wayland window backend */
|
/* Initiailze the Wayland window backend */
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,8 @@ struct terminal {
|
||||||
struct config;
|
struct config;
|
||||||
struct terminal *term_init(
|
struct terminal *term_init(
|
||||||
const struct config *conf, struct fdm *fdm, struct wayland *wayl,
|
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);
|
void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data);
|
||||||
|
|
||||||
bool term_shutdown(struct terminal *term);
|
bool term_shutdown(struct terminal *term);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue