Commit graph

829 commits

Author SHA1 Message Date
Daniel Eklöf
79945419eb
terminal: comments and cleanup 2019-11-03 12:13:51 +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
e1b6aa87fb
Merge branch 'async-ptmx' 2019-11-03 01:26:42 +01:00
Daniel Eklöf
cba1551b03
terminal: cleanup asynchronous ptmx output handling
Break out actual writing to a separate function, and call this
function both from the synchronous and the asynchronous code paths.
2019-11-03 01:25:41 +01:00
Daniel Eklöf
b4c810cf50
Merge branch 'master' into async-ptmx 2019-11-03 01:14:48 +01:00
Daniel Eklöf
8cf981ca12
slave: turn on FD_CLOEXEC after slave has been spawned
This ensures that our ptmx FD isn't carried over to other terminals
spawned later.
2019-11-03 01:14:02 +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
f00c5fdac6
term: asynchronous writes to slave
Make ptmx non-blocking. Then, when writing data to the slave would
have blocked, use the FDM to asynchronously write the remaining data.

This is done by enabling EPOLLOUT on ptmx, and enqueueing all outgoing
data. The FDM handler will go through the enqueued data, and once all
of it has been written, we turn off EPOLLOUT again (thus switching
back to synchronous writes)
2019-11-03 01:03:52 +01:00
Daniel Eklöf
777d851282
fdm: invert check to get rid of one level of indentation 2019-11-03 00:52:24 +01:00
Daniel Eklöf
9f1525aef7
Rename: vt_to_slave() -> term_to_slave() 2019-11-03 00:52:24 +01:00
Daniel Eklöf
79c3121aa3
misc: fdm already logs failures 2019-11-03 00:52:24 +01:00
Daniel Eklöf
89997b97a0
fdm: add fdm_event_add() and fdm_event_del()
These functions allow users to modify already registered FDs, to add
or remove events they are interested in.
2019-11-03 00:52:24 +01:00
Daniel Eklöf
e09bda322a
fdm: bug: 'ret' was renamed to 'r', and replaced with another 'ret' 2019-11-03 00:51:47 +01:00
Daniel Eklöf
8ffa021de8
fdm: rename struct fd -> struct handler 2019-11-02 23:37:19 +01:00
Daniel Eklöf
9b67a6627a
fdm: fdm_destroy(): assert deferred delete list is empty 2019-11-02 23:36:02 +01:00
Daniel Eklöf
ba7f79af18
fdm: purge deferred delete list also when handler fails 2019-11-02 23:35:42 +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
32129083bd
main: pre-allocate fonts
Since fonts are cached, this adds no additional memory. However, it
makes the first terminal window in --server mode start much faster,
since the (primary) fonts have already been loaded.

Fallback fonts are still loaded on-demand.
2019-11-02 13:50:40 +01:00
Daniel Eklöf
c99c0285dc
fdm: fdm_poll(): disallow nested calls 2019-11-02 13:46:54 +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
965d8a3a8e
terminal: don't get stuck waiting for misbehaving slaves to terminate
While unusual, it *is* possible for a client *not* to terminate when
we close ptmx.

We need to handle this *somehow*. Since it is so unusual, we'll go
with a fairly easy, but synchronous method:

* Register a signal handler for SIGALRM, and setup a 2 second alarm
* Wait for slave to die
* If it didn't die, sent SIGTERM, then re-set the alarm for another 2
  seconds.
* If it still hasn't died, send SIGKILL (this time without an alarm).
2019-11-02 12:09:32 +01:00
Daniel Eklöf
563c910127
terminal: 'child_ret' variables isn't needed 2019-11-02 11:30:32 +01:00
Daniel Eklöf
f28fb6c039
timerfd: read() returns -1 with errno == EAGAIN, not 0
When there hasn't been a timeout (or in our case, there was a timeout,
but we reset the timer before we got to the read()), read() returns,
not 0, but -1 with errno == EAGAIN.
2019-11-02 01:44:01 +01:00
Daniel Eklöf
6ed97a47be
shm: purge buffers *before* we (maybe) return one from the cache 2019-11-02 01:31:48 +01:00
Daniel Eklöf
bf9aff056a
Revert "render: last_buf may point to a free:d buffer"
This reverts commit 4d3251a93b.
2019-11-02 01:28:29 +01:00
Daniel Eklöf
c6c75298f3
shm: automatic buffer purging is now delayed one cycle
This ensures we don't purge a buffer that a user is holding a
reference to.
2019-11-02 01:27:05 +01:00
Daniel Eklöf
b27cd9cedf
timerfd: use non-blocking mode, fixes dead lock
Since we cancel the timers every now and then, there's a (small)
chance that one handler cancels a timer that has triggered in the same
epoll() iteration.

When this happens, read() blocks.

Fix by making the timer FDs non-blocking, and simply returning when we
read 0 bytes.
2019-11-02 01:14:40 +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
8e5d386afc
shm: add shm_purge()
Destroys *all* buffers associated with the specified cookie.
2019-11-02 00:49:00 +01:00
Daniel Eklöf
4d3251a93b
render: last_buf may point to a free:d buffer
So, store last buf's width/height separately
2019-11-02 00:48:07 +01:00
Daniel Eklöf
5812242405
shm: purge unused buffers
When we need to create a new buffer (because the cache doesn't have
any buffers of correct size, or because they're all busy), purge
buffers with a size mismatch.
2019-11-02 00:35:02 +01:00
Daniel Eklöf
00b46455a0
shm: associate a 'cookie' with each buffer
When re-using a buffer from cache, only re-use ones with a matching
cookie.

This prevents contention between multiple terminal windows.
2019-11-02 00:33:37 +01:00
Daniel Eklöf
8df82938b0
shm: get_buffer(): remove 'copies' argument; it's not used 2019-11-02 00:23:51 +01:00
Daniel Eklöf
632b6ee0ea
shm: add debug logging of how large the allocated memory buffer is 2019-11-02 00:23:23 +01:00
Daniel Eklöf
f884f77d99
shm: fix name of memfd 2019-11-02 00:05:07 +01:00
Daniel Eklöf
17024b4431
client: bug: verify argv was sent correctly
We checked we had written 2 bytes (sizeof(len)), not <len> bytes.
2019-11-02 00:01:16 +01:00
Daniel Eklöf
570b3ac25a
client: add debug logging of argc/argv 2019-11-02 00:01:08 +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
25311fc4eb
Merge branch 'multi-window' 2019-11-01 23:49:54 +01:00
Daniel Eklöf
2544e93c0e
client: register signal handler for SIGTERM too 2019-11-01 21:13:37 +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
69d62d3cd2
slave: set TERM environment variable in slave process 2019-11-01 21:01:15 +01:00
Daniel Eklöf
d2b395bd43
PKGBUILD: need to execute footclient, to generate profiling data 2019-11-01 20:51:09 +01:00
Daniel Eklöf
77ea7fc61c
client: add long options for --verbose and --help 2019-11-01 20:50:00 +01:00
Daniel Eklöf
8b4ef78f7a
wayland: wayl_win_destroy(): looks like we need another roundtrip 2019-11-01 20:45:57 +01:00
Daniel Eklöf
43462b24f3
font: cache loaded fonts globally
Each font instance has a ref-counter. Whenever we want to instantiate
a font that has already been loaded, we instead return the
already-loaded instance, and bump the ref counter.

When the last font instance is destroyed, it is also removed from the
cache.
2019-11-01 20:40:42 +01:00
Daniel Eklöf
3032ac33da
completions: zsh: add --server and --term to completions 2019-11-01 20:40:10 +01:00