mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-14 08:21:27 -04:00
Merge branch 'server-socket-path'
This commit is contained in:
commit
9862d2c3a9
9 changed files with 76 additions and 43 deletions
52
client.c
52
client.c
|
|
@ -29,27 +29,32 @@ static void
|
||||||
print_usage(const char *prog_name)
|
print_usage(const char *prog_name)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [OPTIONS]...\n", prog_name);
|
printf("Usage: %s [OPTIONS]...\n", prog_name);
|
||||||
|
printf("Usage: %s [OPTIONS]... -- command\n", prog_name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
||||||
|
" -s,--server-socket=PATH path to the server UNIX domain socket (default=XDG_RUNTIME_DIR/foot.sock)\n"
|
||||||
" -v,--version show the version number and quit\n");
|
" -v,--version show the version number and quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *const *argv)
|
main(int argc, char *const *argv)
|
||||||
{
|
{
|
||||||
|
log_init(LOG_FACILITY_USER);
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
|
|
||||||
const char *const prog_name = argv[0];
|
const char *const prog_name = argv[0];
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{"term", required_argument, 0, 't'},
|
{"term", required_argument, 0, 't'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"server-socket", required_argument, 0, 's'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{NULL, no_argument, 0, 0},
|
{"help", no_argument, 0, 'h'},
|
||||||
|
{NULL, no_argument, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *term = "";
|
const char *term = "";
|
||||||
|
const char *server_socket_path = NULL;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int c = getopt_long(argc, argv, ":t:hv", longopts, NULL);
|
int c = getopt_long(argc, argv, ":t:hv", longopts, NULL);
|
||||||
|
|
@ -59,6 +64,9 @@ main(int argc, char *const *argv)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 't':
|
case 't':
|
||||||
term = optarg;
|
term = optarg;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
server_socket_path = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
|
|
@ -88,23 +96,34 @@ main(int argc, char *const *argv)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool connected = false;
|
|
||||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||||
|
|
||||||
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
|
if (server_socket_path != NULL) {
|
||||||
if (xdg_runtime != NULL) {
|
strncpy(addr.sun_path, server_socket_path, sizeof(addr.sun_path));
|
||||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot.sock", xdg_runtime);
|
|
||||||
|
|
||||||
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0)
|
|
||||||
connected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!connected) {
|
|
||||||
strncpy(addr.sun_path, "/tmp/foot.sock", sizeof(addr.sun_path) - 1);
|
|
||||||
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
LOG_ERRNO("failed to connect (is 'foot --server' running?)");
|
LOG_ERR("%s: failed to connect (is 'foot --server' running?)", server_socket_path);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
bool connected = false;
|
||||||
|
|
||||||
|
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
|
||||||
|
if (xdg_runtime != NULL) {
|
||||||
|
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot.sock", xdg_runtime);
|
||||||
|
|
||||||
|
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0)
|
||||||
|
connected = true;
|
||||||
|
else
|
||||||
|
LOG_WARN("%s/foot.sock: failed to connect, will now try /tmp/foot.sock", xdg_runtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connected) {
|
||||||
|
strncpy(addr.sun_path, "/tmp/foot.sock", sizeof(addr.sun_path) - 1);
|
||||||
|
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
|
LOG_ERRNO("failed to connect (is 'foot --server' running?)");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint16_t term_len = strlen(term) + 1;
|
const uint16_t term_len = strlen(term) + 1;
|
||||||
|
|
@ -172,5 +191,6 @@ main(int argc, char *const *argv)
|
||||||
err:
|
err:
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
log_deinit();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
_arguments \
|
_arguments \
|
||||||
-s \
|
-s \
|
||||||
'(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \
|
'(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \
|
||||||
'(-t,--term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
|
'(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
|
||||||
'(-g --geometry)'{-g,--geometry}'[window WIDTHxHEIGHT, in pixels (84x24 cells)]' \
|
'(-g --geometry)'{-g,--geometry}'[window WIDTHxHEIGHT, in pixels (84x24 cells)]' \
|
||||||
'(-s --server)'{-s,--server}'[run as server; open terminals by running footclient]' \
|
'(-s --server)'{-s,--server}'[run as server; open terminals by running footclient]:server:_files' \
|
||||||
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
||||||
'(-h --help)'{-h,--help}'[show help message and quit]'
|
'(-h --help)'{-h,--help}'[show help message and quit]'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
_arguments \
|
_arguments \
|
||||||
-s \
|
-s \
|
||||||
'(-t,--term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
|
'(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
|
||||||
|
'(-s --server-socket)'{-s,--server-socket}'[override the default path to the foot server socket (XDG_RUNTIME_DIR/foot.sock)]' \
|
||||||
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
||||||
'(-h --help)'{-h,--help}'[show help message and quit]'
|
'(-h --help)'{-h,--help}'[show help message and quit]'
|
||||||
|
|
||||||
|
|
|
||||||
14
config.c
14
config.c
|
|
@ -450,6 +450,18 @@ err:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_server_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;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
config_load(struct config *conf)
|
config_load(struct config *conf)
|
||||||
{
|
{
|
||||||
|
|
@ -498,6 +510,7 @@ config_load(struct config *conf)
|
||||||
},
|
},
|
||||||
|
|
||||||
.render_worker_count = sysconf(_SC_NPROCESSORS_ONLN),
|
.render_worker_count = sysconf(_SC_NPROCESSORS_ONLN),
|
||||||
|
.server_socket_path = get_server_socket_path(),
|
||||||
};
|
};
|
||||||
|
|
||||||
char *path = get_config_path();
|
char *path = get_config_path();
|
||||||
|
|
@ -531,4 +544,5 @@ config_free(struct config conf)
|
||||||
free(conf.term);
|
free(conf.term);
|
||||||
free(conf.shell);
|
free(conf.shell);
|
||||||
tll_free_and_free(conf.fonts, free);
|
tll_free_and_free(conf.fonts, free);
|
||||||
|
free(conf.server_socket_path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
config.h
2
config.h
|
|
@ -34,6 +34,8 @@ struct config {
|
||||||
} cursor;
|
} cursor;
|
||||||
|
|
||||||
size_t render_worker_count;
|
size_t render_worker_count;
|
||||||
|
|
||||||
|
char *server_socket_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool config_load(struct config *conf);
|
bool config_load(struct config *conf);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ execute (instead of the shell).
|
||||||
*-t*,*--term*=_TERM_
|
*-t*,*--term*=_TERM_
|
||||||
Value to set the environment variable _TERM_ to. Default: _foot_.
|
Value to set the environment variable _TERM_ to. Default: _foot_.
|
||||||
|
|
||||||
*-s*,*--server*
|
*-s*,*--server*[=_PATH_]
|
||||||
Run as a server. In this mode, a single foot instance hosts
|
Run as a server. In this mode, a single foot instance hosts
|
||||||
multiple terminals (windows). Use *footclient*(1) to launch new
|
multiple terminals (windows). Use *footclient*(1) to launch new
|
||||||
terminals.
|
terminals.
|
||||||
|
|
@ -55,6 +55,10 @@ execute (instead of the shell).
|
||||||
Also be aware that should one terminal crash, it will take all the
|
Also be aware that should one terminal crash, it will take all the
|
||||||
others with it.
|
others with it.
|
||||||
|
|
||||||
|
You may optionally override the default socket path,
|
||||||
|
_XDG\_RUNTIME\_DIR/foot.sock_. If you do so, you will need to use
|
||||||
|
the *--server-socket* option in *footclient*(1).
|
||||||
|
|
||||||
*-v*,*--version*
|
*-v*,*--version*
|
||||||
Show the version number and quit
|
Show the version number and quit
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ execute (instead of the shell).
|
||||||
*-t*,*--term*=_TERM_
|
*-t*,*--term*=_TERM_
|
||||||
Value to set the environment variable _TERM_ to. Default: _foot_.
|
Value to set the environment variable _TERM_ to. Default: _foot_.
|
||||||
|
|
||||||
|
*-s*,*--server-socket*=_PATH_
|
||||||
|
Connect to _PATH_ instead of _XDG\_RUNTIME\_DIR/foot.sock_.
|
||||||
|
|
||||||
*-v*,*--version*
|
*-v*,*--version*
|
||||||
Show the version number and quit
|
Show the version number and quit
|
||||||
|
|
||||||
|
|
|
||||||
12
main.c
12
main.c
|
|
@ -38,12 +38,14 @@ static void
|
||||||
print_usage(const char *prog_name)
|
print_usage(const char *prog_name)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [OPTIONS]...\n", prog_name);
|
printf("Usage: %s [OPTIONS]...\n", prog_name);
|
||||||
|
printf("Usage: %s [OPTIONS]... -- command\n", prog_name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -f,--font=FONT comma separated list of fonts in fontconfig format (monospace)\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"
|
" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
||||||
" -g,--geometry=WIDTHxHEIGHT set initial width and height\n"
|
" -g,--geometry=WIDTHxHEIGHT set initial width and height\n"
|
||||||
" -s,--server run as a server (use 'footclient' to start terminals)\n"
|
" -s,--server[=PATH] run as a server (use 'footclient' to start terminals).\n"
|
||||||
|
" Without PATH, XDG_RUNTIME_DIR/foot.sock will be used.\n"
|
||||||
" -v,--version show the version number and quit\n");
|
" -v,--version show the version number and quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +81,7 @@ main(int argc, char *const *argv)
|
||||||
{"term", required_argument, 0, 't'},
|
{"term", required_argument, 0, 't'},
|
||||||
{"font", required_argument, 0, 'f'},
|
{"font", required_argument, 0, 'f'},
|
||||||
{"geometry", required_argument, 0, 'g'},
|
{"geometry", required_argument, 0, 'g'},
|
||||||
{"server", no_argument, 0, 's'},
|
{"server", optional_argument, 0, 's'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{NULL, no_argument, 0, 0},
|
{NULL, no_argument, 0, 0},
|
||||||
|
|
@ -88,7 +90,7 @@ main(int argc, char *const *argv)
|
||||||
bool as_server = false;
|
bool as_server = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int c = getopt_long(argc, argv, ":t:f:g:vh", longopts, NULL);
|
int c = getopt_long(argc, argv, ":t:f:g:s::vh", longopts, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -135,6 +137,10 @@ main(int argc, char *const *argv)
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
as_server = true;
|
as_server = true;
|
||||||
|
if (optarg != NULL) {
|
||||||
|
free(conf.server_socket_path);
|
||||||
|
conf.server_socket_path = strdup(optarg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
|
|
|
||||||
21
server.c
21
server.c
|
|
@ -27,7 +27,7 @@ struct server {
|
||||||
struct wayland *wayl;
|
struct wayland *wayl;
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
char *sock_path;
|
const char *sock_path;
|
||||||
|
|
||||||
tll(struct client *) clients;
|
tll(struct client *) clients;
|
||||||
};
|
};
|
||||||
|
|
@ -273,18 +273,6 @@ fdm_server(struct fdm *fdm, int fd, int events, void *data)
|
||||||
return true;
|
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};
|
enum connect_status {CONNECT_ERR, CONNECT_FAIL, CONNECT_SUCCESS};
|
||||||
|
|
||||||
static enum connect_status
|
static enum connect_status
|
||||||
|
|
@ -328,10 +316,7 @@ server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct server *server = NULL;
|
struct server *server = NULL;
|
||||||
char *sock_path = NULL;
|
const char *sock_path = conf->server_socket_path;
|
||||||
|
|
||||||
if ((sock_path = get_socket_path()) == NULL)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
switch (try_connect(sock_path)) {
|
switch (try_connect(sock_path)) {
|
||||||
case CONNECT_FAIL:
|
case CONNECT_FAIL:
|
||||||
|
|
@ -381,7 +366,6 @@ server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl)
|
||||||
|
|
||||||
err:
|
err:
|
||||||
free(server);
|
free(server);
|
||||||
free(sock_path);
|
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -406,6 +390,5 @@ server_destroy(struct server *server)
|
||||||
fdm_del(server->fdm, server->fd);
|
fdm_del(server->fdm, server->fd);
|
||||||
if (server->sock_path != NULL)
|
if (server->sock_path != NULL)
|
||||||
unlink(server->sock_path);
|
unlink(server->sock_path);
|
||||||
free(server->sock_path);
|
|
||||||
free(server);
|
free(server);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue