aboutsummaryrefslogtreecommitdiff
path: root/server.c (unfollow)
Commit message (Collapse)AuthorLines
2026-09-10server: fix use-after-free during shutdownCismonX-4/+2
When terminal shutdown is in progress, calling client_destroy() results in subsequent fdm_shutdown() (registered by term_shutdown()) always called with a dangling 'struct terminal' pointer. This may happen when footclient and the client application exit simultaneously in a short window. See #2432 for more information. Fixed by not calling client_destroy() when terminal shutdown is in progress. The client will eventually be destroyed in term_shutdown_handler() (invoked from shutdown_maybe_done()), so there's no resource leak.
2025-12-20config: add [colors-dark] and [colors-light], replacing [colors] and [colors2]Daniel Eklöf-10/+10
The main reason for having two color sections is to be able to switch between dark and light. Thus, it's better if the section names reflect this, rather than the more generic 'colors' and 'colors2' (which was the dark one and which was the light one, now again?) When the second color section was added, we kept the original name, colors, to make sure we didn't break existing configurations, and third-party themes. However, in the long run, it's probably better to be specific in the section naming, to avoid confusion. So, add 'colors-dark', and 'colors-light'. Keep 'colors' and 'colors2' as aliases for now, but mark them as deprecated. They WILL be removed in a future release. Also rename the option values for initial-color-theme, from 1/2, to dark/light. Keep the old ones for now, marked as deprecated. Update all bundled themes to use the new names. In the light-only themes (i.e. themes that define a single, light, theme), use colors-light, and set initial-color-theme=light. Possible improvements: disable color switching if only one color section has been explicitly configured (todo: figure out how to handle the default color theme values...)
2025-08-01server: fix compilation error: return value ignoredDaniel Eklöf-1/+1
2025-08-01server/client: add support for sending SIGUSR to footclientDaniel Eklöf-4/+55
This patch adds the IPC infrastructure necessary to propagate SIGUSR1/SIGUSR2 from a footclient process to the server process. By targeting a particular footclient instance, only that particular instance changes theme. This is different from when targeting the server process, where all instances change theme. Closes #2156
2025-07-30server: sigusr1/2: update conf object with the "new" themeDaniel Eklöf-2/+22
When sending SIGUSR1/SIGUSR2 to a server process, all currently running client instances change their theme. But before this patch, all future instances used the original theme. With this patch, the server owned config object is updated with the selected theme, thus making new instances use the same theme as well.
2025-02-16server: fix --server=<fd> on OSes returning SO_ACCEPTCONN > 1Guillaume Outters-1/+6
Closes #1956
2025-02-05server: don't instantiate a client without a monitorsewn-0/+6
2024-08-02Remove a number of unused includesDaniel Eklöf-1/+0
2024-03-14Add support for opening an existing PTYAlyssa Ross-1/+1
Virtual machine monitor programs (e.g. QEMU, Cloud Hypervisor) expose guest consoles as PTYs. With this patch, foot can access these guest consoles. Usually, the program used for accessing these PTYs is screen, but screen is barely developed, doesn't support resizing, and has a bunch of other unrelated stuff going on. It would be nice to have a terminal emulator that properly supported opening an existing PTY. The VMM controls the master end of the PTY, so to the other end (in this case foot), it just behaves like any application running in a directly-opened PTY, and all that's needed is to change foot's code to support opening an existing PTY rather than creating one. Co-authored-by: tanto <tanto@ccc.ac>
2024-01-25Replace unchecked allocations with calls to xmalloc.h functionsCraig Barnes-1/+1
2024-01-11slave: don't skip setting environment variables when using a custom environmentDaniel Eklöf-1/+2
When launching footclient with -E,--client-environment the environment variables that should be set by foot, wasn't. Those variables are: * TERM * COLORTERM * PWD * SHELL and all variables defined by the user in the [environment] section in foot.ini. In the same way, we did not *unset* TERM_PROGRAM and TERM_PROGRAM_VERSION. This patch fixes it by "cloning" the custom environment, making it mutable, and then adding/removing the variables above from it. Instead of calling setenv()/unsetenv() directly, we add the wrapper functions add_to_env() and del_from_env(). When *not* using a custom environment, they simply call setenv()/unsetenv(). When we *are* using a custom environment, add_to_env() first loops all existing variables, looking for a match. If a match is found, it's updated with the new value. If it's not found, a new entry is added. del_from_env() loops all entries, and removes it when a match is found. If no match is found, nothing is done. The mutable environment is allocated on the heap, but never free:d. We don't need to free it, since it's only allocated after forking, in the child process. Closes #1568
2022-04-12config: config_free(): pass conf struct by pointer, not by-valueDaniel Eklöf-1/+1
2022-04-12client: add -E,--client-environmentDaniel Eklöf-2/+19
When this option is used, the child process in the new terminal instance will inherit its environment from the footclient process, instead of the foot server’s. Implemented by sending (yet another) dynamic string list as part of the client -> server setup packet. When the new option is *not* used, the setup packet is now 2 bytes larger than before. On the server side, the slave process now uses execvpe() instead of execvp(). There’s plumbing to propagate a new ‘envp’ argument from term_init() all the way down to slave_exec(). If ‘envp’ is NULL, we use ‘environ’ instead (thus matching the old behavior of execvp()). Closes #1004
2022-02-26Make foot able to receive a socket from its parentMax Gautier-26/+91
If the argument to --server is parsed as a number, consider it to be a file descriptor, and use that as a socket. This is necessary to be able to use socket activation with the server mode of foot.
2021-11-01foot/client: implement xdga client activationRonan Pigott-1/+12
This is an application of the xdg activation protocol that will allow compositors to associate new foot toplevels with the command that launched them. footclient receives an activation token from the launcher which the compositor can use to track application startup. It passes the token to the foot server, which then activates the new window with the token to complete the startup sequence.
2021-09-05server: no need to clone the config to handle -N,--no-waitDaniel Eklöf-6/+2
2021-08-31server: verify primary font is monospacedDaniel Eklöf-0/+6
... unless we’re re-using the main conf as-is, in which case we will already have done this (and the conf’s user-notification list will already contain a warning).
2021-07-31term: consolidate shutdown related state into an anonymous structDaniel Eklöf-2/+4
2021-07-11server: the terminal now purges SHM pixmaps on its ownDaniel Eklöf-7/+0
2021-06-23server: make sure ‘overrides’ have been initialized in all error pathsDaniel Eklöf-1/+1
2021-06-23server: avoid “member access within misaligned address” ASAN warningDaniel Eklöf-7/+6
2021-06-23client: send overrides for everything that is publicly visible in the confDaniel Eklöf-63/+17
Send a generic “overrides” list to the server, containing options in text, on the format “section.key=value”. This reduces the size of the base client/server protocol packet, as well as opens up for a generic -o,--override command line option (not yet implemented).
2021-06-23server: use config_clone() + config_override_apply()Daniel Eklöf-22/+50
When the connecting client overrides config options, clone the server’s configuration, and then convert the overridden options to config overrides, and apply them using config_override_apply(). When destroying the client, free the cloned config using the regular config_free().
2021-06-17server: don’t clone the config unless we’re going to modify itDaniel Eklöf-28/+50
2021-05-04main/client: change exit codeDaniel Eklöf-2/+2
* foot exits with -26/230 * footclient exits with -36/220 This is to give each application a range of exit codes. Currently unused, but we may want to change this in the future.
2021-05-04foot/footclient: use a custom exit code when foot/footclient fail to runDaniel Eklöf-2/+2
Normally, foot and footclient uses the exit code from the client application (i.e. the shell). However, foot (or footclient) itself may fail to run; if run outside of a Wayland session, or no fonts are installed, or the client application/shell cannot be found (“foot lsdjfldsjf”) etc. Up until now, there has been no way to differentiate these kind of failures from the client application exiting with code 1. This patch changes foot’s failure exit code to -27/229, and footclient’s to -28/228. Note that footclient will exit with foot’s -27/229 if footclient ran successfully, but the foot server failed to instantiate a new window. Closes #466.
2021-03-13fix code style issues and memory leakFelipe Trzaskowski-13/+8
2021-03-13add option to detach the client process from the terminal instanceFelipe Trzaskowski-41/+101
2021-02-12server: send exit-code -1 when we fail to instantiate a new terminalDaniel Eklöf-0/+1
2021-01-23client/server: switch to POSIX header for sockaddr_unJan Beich-1/+1
client.c:13:10: fatal error: 'linux/un.h' file not found #include <linux/un.h> ^~~~~~~~~~~~ client.c:195:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ client.c:195:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:11:10: fatal error: 'linux/un.h' file not found #include <linux/un.h> ^~~~~~~~~~~~ server.c:307:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr; ^ server.c:307:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr; ^ server.c:347:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:347:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:394:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:394:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^
2021-01-21client/server: switch to POSIX header for sockaddr_unJan Beich-1/+1
client.c:13:10: fatal error: 'linux/un.h' file not found #include <linux/un.h> ^~~~~~~~~~~~ client.c:195:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ client.c:195:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:11:10: fatal error: 'linux/un.h' file not found #include <linux/un.h> ^~~~~~~~~~~~ server.c:307:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr; ^ server.c:307:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr; ^ server.c:347:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:347:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:394:24: error: variable has incomplete type 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^ server.c:394:12: note: forward declaration of 'struct sockaddr_un' struct sockaddr_un addr = {.sun_family = AF_UNIX}; ^
2021-01-16debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes-4/+4
2020-11-30config: replace union in config struct with simple width/height membersCraig Barnes-12/+2
2020-11-22client: add "--window-size-pixels" and "--window-size-chars" optionsCraig Barnes-0/+16
2020-11-21server: avoid doing unaligned struct accessesDaniel Eklöf-28/+31
2020-11-21server: verify strings are NULL terminatedDaniel Eklöf-5/+14
2020-11-21client/server: simplify setup packet handlingDaniel Eklöf-92/+27
Instead of writing (and logging errors for) every parameter, one at a time, send all fixed size data in a single struct, followed by all the variable length data.
2020-10-10selection: use appropriate check for PRIMARY pasteSergey Nazaryev-341/+159
Assume it could be a copy-paste typo. We should check PRIMARY, not CLIPBOARD. Without this fix, we can't use PRIMARY until we copy anything to CLIPBOARD.
2020-08-08Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes-6/+12
2020-05-26client/server: implement '--hold' in footclientDaniel Eklöf-0/+4
2020-05-21term: don't double fork new terminal windowsDaniel Eklöf-2/+5
Instead, register their PIDs with the new reaper module and let it handle them.
2020-04-18server: don't do misaligned loadsDaniel Eklöf-11/+23
2020-04-12Fix clang warningsDaniel Eklöf-5/+5
All are printf() formatter related. Even if a variable is e.g. a 'short', when used in an expression like '<variable> - 1' it is promoted to an 'int'. Closes #16
2020-04-01conf: add 'title' conf option and --title command line optionDaniel Eklöf-0/+16
2020-04-01conf: add app-id config option and --app-id command line optionDaniel Eklöf-0/+16
2020-03-27client: add --maximized and --fullscreenDaniel Eklöf-2/+23
We now create a copy of the config for each client, and updates it with the values passed from the client. Since we're not actually cloning it (and e.g. strdup() all strings etc) we can't call conf_destroy() to free it, but need to free just the strings we've replaced.
2020-03-18server: purge *all* buffers when a terminal shuts downDaniel Eklöf-2/+7
Previously we only purged the main grid buffers. Now we also purge the search buffers and the CSD buffers.
2020-02-20slave: prefix argv[0] with a '-' when spawning a login-shellDaniel Eklöf-1/+4
2020-01-10Revert "server: use edge-triggered FDM handler for the client connections"Daniel Eklöf-13/+13
This reverts commit 9141b8a6573f973f97aa1615a8cc0c488cfd77e7.
2020-01-10server: use edge-triggered FDM handler for the client connectionsDaniel Eklöf-13/+13
2020-01-10server: be more resilient against bad behaving clientsDaniel Eklöf-3/+16
Make both the server listening socket and the connecting client sockets non-blocking. Then, when reading the initial length of the setup packet, handle read errors from partial reads separately. Assume the client writes all four bytes of the 'length' field at once, and bail out if we are unable to read those 4 bytes. Limit the maximum setup packet size to 128K. This is to prevent clients from pretending the setup packet is insanely large, causing us to fail to malloc.
2019-12-21server: verify CWD string length matches the indicated lengthDaniel Eklöf-0/+6
2019-12-21server: move forward the indicated number of TERM bytesDaniel Eklöf-1/+1
2019-12-21server: bug: move forward 2 bytes, not whatever the client sentDaniel Eklöf-1/+1
2019-12-21term: term_init: add 'cwd' argumentDaniel Eklöf-1/+1
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.
2019-12-21client/server: client sends its CWD to serverDaniel Eklöf-1/+8
2019-12-21term: term_spawn_new: always spawn foot/footclient from PATHDaniel Eklöf-1/+1
2019-12-21term: term_spawn_new(): new function, spawns a new foot/footclient processDaniel Eklöf-1/+1
Bind ctrl+shift+return to it
2019-12-14server: use socket-path from configDaniel Eklöf-19/+2
2019-12-13server: log socket packetDaniel Eklöf-1/+3
2019-12-01Add missing includesDaniel Eklöf-0/+1
2019-11-17tllist: is now an external "library", so use <> includesDaniel Eklöf-1/+2
2019-11-05server: disable debug outputDaniel Eklöf-1/+1
2019-11-05server/client: harden reading of initialization data, and make asyncDaniel Eklöf-31/+90
* Client terminal initialization data is now received asynchronously. To facilitate this, a couple of minor changes to the protocol was made: - The client now starts with sending a 4-byte unsigned integer with the *total* size of the initialization data (*not* including the size field itself. - Strings (TERM variable + argv) are now sent NULL-terminated * The server allocates a single buffer, and fills it asynchronously. When full (as indicated by the initial 'total size' integer), we parse it (taking care not to read outside boundaries etc, and verifies the lengths (of the TERM variable and argv array) indicated by the client matches the actual lengths of the strings received. * The server now ignores 'unexpected' data received from the client, after the terminal has been instantiated.
2019-11-05server: workaround evil clientsDaniel Eklöf-0/+6
If the clients attempt to send more data after we've instantiated the terminal, just consume the data but ignore it.
2019-11-05server: don't cache argc/argv in client contextDaniel Eklöf-17/+18
2019-11-03Remove unneeded includeDaniel Eklöf-1/+0
2019-11-03server: set CLOEXEC | NONBLOCK directly in socket() callDaniel Eklöf-17/+2
2019-11-03server: FD_CLOEXEC is a file descriptor flag, not a file status flagDaniel Eklöf-1/+1
2019-11-02misc: fdm already logs failuresDaniel Eklöf-4/+1
2019-11-02server: server_destroy(): unlink UNIX socketDaniel Eklöf-0/+2
2019-11-02server: use a non-blocking socket when trying to connectDaniel Eklöf-4/+23
When checking of a 'foot --server' instance is already running, we try to connect to the UNIX socket we're planning on listening on. In most cases, this will fail hard and fast. But under certain circumstances, we can get stuck in connect() waiting for a connection timeout. Since it should be possible to establish a connection immediately *if* there's someone actually listening on the socket, rely on the fact that connect() will fail with a EINPROGRESS if a connection can *not* be established immediately (and thus no one is listening on it).
2019-11-02server: don't get stuck in read() if TERM length is 0Daniel Eklöf-2/+4
2019-11-02server: don't get stuck in read() if length of argv argument is 0Daniel Eklöf-0/+3
2019-11-01server: purge shm buffers when terminal is destroyedDaniel Eklöf-0/+6
2019-11-01server: add debug logging of client argc/argvDaniel Eklöf-0/+4
2019-11-01client/server: add -t,--term to footclientDaniel Eklöf-1/+15
2019-11-01term_init(): initialize slave TERM from term_init() argumentDaniel Eklöf-2/+2
2019-11-01server: implement a --server modeDaniel Eklöf-0/+310
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.