Commit graph

34 commits

Author SHA1 Message Date
Daniel Eklöf
f7572d4ab1
server: purge *all* buffers when a terminal shuts down
Previously we only purged the main grid buffers. Now we also purge the
search buffers and the CSD buffers.
2020-03-18 16:53:12 +01:00
Daniel Eklöf
b5efe984bb
slave: prefix argv[0] with a '-' when spawning a login-shell 2020-02-20 18:36:09 +01:00
Daniel Eklöf
ed8d7f4bae
Revert "server: use edge-triggered FDM handler for the client connections"
This reverts commit 9141b8a657.
2020-01-10 19:49:26 +01:00
Daniel Eklöf
9141b8a657
server: use edge-triggered FDM handler for the client connections 2020-01-10 19:30:03 +01:00
Daniel Eklöf
629a625422
server: be more resilient against bad behaving clients
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.
2020-01-10 19:27:17 +01:00
Daniel Eklöf
c91ef4c512
server: verify CWD string length matches the indicated length 2019-12-21 20:05:14 +01:00
Daniel Eklöf
cd382a467c
server: move forward the indicated number of TERM bytes 2019-12-21 20:05:00 +01:00
Daniel Eklöf
2a58fc27b7
server: bug: move forward 2 bytes, not whatever the client sent 2019-12-21 20:04:40 +01:00
Daniel Eklöf
39146fac5c
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.
2019-12-21 19:57:28 +01:00
Daniel Eklöf
277735db65
client/server: client sends its CWD to server 2019-12-21 19:56:37 +01:00
Daniel Eklöf
a484a65fef
term: term_spawn_new: always spawn foot/footclient from PATH 2019-12-21 15:29:42 +01:00
Daniel Eklöf
57de9feaa5
term: term_spawn_new(): new function, spawns a new foot/footclient process
Bind ctrl+shift+return to it
2019-12-21 15:27:17 +01:00
Daniel Eklöf
89ea61cf0c
server: use socket-path from config 2019-12-14 12:59:38 +01:00
Daniel Eklöf
6ef65058cf
server: log socket packet 2019-12-13 22:28:48 +01:00
Daniel Eklöf
b5780e735e
Add missing includes 2019-12-01 19:22:45 +01:00
Daniel Eklöf
29cccadd1d
tllist: is now an external "library", so use <> includes 2019-11-17 19:19:55 +01:00
Daniel Eklöf
54f750c494
server: disable debug output 2019-11-05 14:36:58 +01:00
Daniel Eklöf
9abc5ca971
server/client: harden reading of initialization data, and make async
* 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-05 10:08:30 +01:00
Daniel Eklöf
5b3fe4492c
server: workaround evil clients
If the clients attempt to send more data after we've instantiated the
terminal, just consume the data but ignore it.
2019-11-05 09:31:47 +01:00
Daniel Eklöf
5f77f0e999
server: don't cache argc/argv in client context 2019-11-05 09:31:14 +01:00
Daniel Eklöf
a8cb6c531e
Remove unneeded include 2019-11-03 13:07:19 +01:00
Daniel Eklöf
a326427caf
server: set CLOEXEC | NONBLOCK directly in socket() call 2019-11-03 01:48:40 +01:00
Daniel Eklöf
b4c810cf50
Merge branch 'master' into async-ptmx 2019-11-03 01:14:48 +01:00
Daniel Eklöf
8d9ad96b52
server: FD_CLOEXEC is a file descriptor flag, not a file status flag 2019-11-03 01:11:02 +01:00
Daniel Eklöf
79c3121aa3
misc: fdm already logs failures 2019-11-03 00:52:24 +01:00
Daniel Eklöf
1543c71f78
server: server_destroy(): unlink UNIX socket 2019-11-02 23:32:13 +01:00
Daniel Eklöf
ad26914631
server: use a non-blocking socket when trying to connect
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-02 23:25:14 +01:00
Daniel Eklöf
338747dc5a
server: don't get stuck in read() if TERM length is 0 2019-11-02 12:17:30 +01:00
Daniel Eklöf
a1ba4cb010
server: don't get stuck in read() if length of argv argument is 0 2019-11-02 12:16:50 +01:00
Daniel Eklöf
035ace33b6
server: purge shm buffers when terminal is destroyed 2019-11-02 00:49:25 +01:00
Daniel Eklöf
19c099236b
server: add debug logging of client argc/argv 2019-11-02 00:00:31 +01:00
Daniel Eklöf
438d6eaff0
client/server: add -t,--term to footclient 2019-11-01 21:10:47 +01:00
Daniel Eklöf
0bd2ddd8ad
term_init(): initialize slave TERM from term_init() argument 2019-11-01 21:03:08 +01:00
Daniel Eklöf
a1efd65746
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.
2019-11-01 20:39:09 +01:00