aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-01 19:37:22 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-01 19:39:09 +0000
commita1efd65746cb0c464fac987e076ec3632e632445 (patch)
treeebddbca25e8d20c3d5c2d768a023a17e5df26029 /main.c
parentmain: register signal handlers for SIGINT and SIGTERM (diff)
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.
Diffstat (limited to 'main.c')
-rw-r--r--main.c16
1 files changed, 14 insertions, 2 deletions
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();