History log of /openbsd-current/usr.bin/tmux/server.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.206 14-May-2024 nicm

Add missing time.h to tty.c (from Ismail Donmez), also remove some stray
spaces.


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.205 15-Sep-2023 nicm

Change UTF-8 combining to inspect the previous character at the cursor
position rather than keeping the last character from the input stream,
this is how most terminals work and fixes problems with displaying these
characters in vim. GitHub issue 3600.


# 1.204 01-Sep-2023 nicm

Rewrite combined character handling to be more consistent and to support
newer Unicode combined characters (which we have to "know" are combined
since they are not width zero). GitHub issue 3600.


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.203 30-Jun-2022 nicm

Add support for OSC 8 hyperlinks (a VTE extension now supported by other
terminals such as iTerm2). Originally written by me then extended and
completed by first Will Noble and later Jeff Chiang. GitHub issues 911,
2621, 2890, 3240.


# 1.202 21-Jun-2022 nicm

Store time lines are scrolled into history and display in copy mode.


# 1.201 30-May-2022 nicm

Add an ACL list for users connecting to the tmux socket. Users may be
forbidden from attaching, forced to attach read-only, or allowed to
attach read-write. A new command, server-access, configures the list.
tmux gets the user using getpeereid(3) of the client socket. Users must
still configure file system permissions manually. From Dallas Lyons and
others.


Revision tags: OPENBSD_7_1_BASE
# 1.200 28-Mar-2022 nicm

Report error if creating socket fails with -D.


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.205 15-Sep-2023 nicm

Change UTF-8 combining to inspect the previous character at the cursor
position rather than keeping the last character from the input stream,
this is how most terminals work and fixes problems with displaying these
characters in vim. GitHub issue 3600.


# 1.204 01-Sep-2023 nicm

Rewrite combined character handling to be more consistent and to support
newer Unicode combined characters (which we have to "know" are combined
since they are not width zero). GitHub issue 3600.


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.203 30-Jun-2022 nicm

Add support for OSC 8 hyperlinks (a VTE extension now supported by other
terminals such as iTerm2). Originally written by me then extended and
completed by first Will Noble and later Jeff Chiang. GitHub issues 911,
2621, 2890, 3240.


# 1.202 21-Jun-2022 nicm

Store time lines are scrolled into history and display in copy mode.


# 1.201 30-May-2022 nicm

Add an ACL list for users connecting to the tmux socket. Users may be
forbidden from attaching, forced to attach read-only, or allowed to
attach read-write. A new command, server-access, configures the list.
tmux gets the user using getpeereid(3) of the client socket. Users must
still configure file system permissions manually. From Dallas Lyons and
others.


Revision tags: OPENBSD_7_1_BASE
# 1.200 28-Mar-2022 nicm

Report error if creating socket fails with -D.


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.204 01-Sep-2023 nicm

Rewrite combined character handling to be more consistent and to support
newer Unicode combined characters (which we have to "know" are combined
since they are not width zero). GitHub issue 3600.


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.203 30-Jun-2022 nicm

Add support for OSC 8 hyperlinks (a VTE extension now supported by other
terminals such as iTerm2). Originally written by me then extended and
completed by first Will Noble and later Jeff Chiang. GitHub issues 911,
2621, 2890, 3240.


# 1.202 21-Jun-2022 nicm

Store time lines are scrolled into history and display in copy mode.


# 1.201 30-May-2022 nicm

Add an ACL list for users connecting to the tmux socket. Users may be
forbidden from attaching, forced to attach read-only, or allowed to
attach read-write. A new command, server-access, configures the list.
tmux gets the user using getpeereid(3) of the client socket. Users must
still configure file system permissions manually. From Dallas Lyons and
others.


Revision tags: OPENBSD_7_1_BASE
# 1.200 28-Mar-2022 nicm

Report error if creating socket fails with -D.


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.203 30-Jun-2022 nicm

Add support for OSC 8 hyperlinks (a VTE extension now supported by other
terminals such as iTerm2). Originally written by me then extended and
completed by first Will Noble and later Jeff Chiang. GitHub issues 911,
2621, 2890, 3240.


# 1.202 21-Jun-2022 nicm

Store time lines are scrolled into history and display in copy mode.


# 1.201 30-May-2022 nicm

Add an ACL list for users connecting to the tmux socket. Users may be
forbidden from attaching, forced to attach read-only, or allowed to
attach read-write. A new command, server-access, configures the list.
tmux gets the user using getpeereid(3) of the client socket. Users must
still configure file system permissions manually. From Dallas Lyons and
others.


Revision tags: OPENBSD_7_1_BASE
# 1.200 28-Mar-2022 nicm

Report error if creating socket fails with -D.


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.202 21-Jun-2022 nicm

Store time lines are scrolled into history and display in copy mode.


# 1.201 30-May-2022 nicm

Add an ACL list for users connecting to the tmux socket. Users may be
forbidden from attaching, forced to attach read-only, or allowed to
attach read-write. A new command, server-access, configures the list.
tmux gets the user using getpeereid(3) of the client socket. Users must
still configure file system permissions manually. From Dallas Lyons and
others.


Revision tags: OPENBSD_7_1_BASE
# 1.200 28-Mar-2022 nicm

Report error if creating socket fails with -D.


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.201 30-May-2022 nicm

Add an ACL list for users connecting to the tmux socket. Users may be
forbidden from attaching, forced to attach read-only, or allowed to
attach read-write. A new command, server-access, configures the list.
tmux gets the user using getpeereid(3) of the client socket. Users must
still configure file system permissions manually. From Dallas Lyons and
others.


Revision tags: OPENBSD_7_1_BASE
# 1.200 28-Mar-2022 nicm

Report error if creating socket fails with -D.


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.200 28-Mar-2022 nicm

Report error if creating socket fails with -D.


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.199 25-Mar-2022 nicm

Fix exit message if creating socket fails.


Revision tags: OPENBSD_7_0_BASE
# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.198 10-Jun-2021 nicm

Fix warnings, from Jan Tache in GitHub issue 2692.


Revision tags: OPENBSD_6_9_BASE
# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.197 11-Mar-2021 nicm

Tidy old jobs every hour instead of every 30 seconds.


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.196 11-Feb-2021 nicm

Add a couple of helper functions, and flush imsgs on exit.


Revision tags: OPENBSD_6_8_BASE
# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.195 16-Sep-2020 nicm

Fix some warnings, GitHub issue 2382.


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.194 18-Jun-2020 nicm

Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.193 01-Jun-2020 nicm

Instead of sending all data to control mode clients as fast as possible,
add a limit of how much data will be sent to the client and try to use
it for panes with some degree of fairness. GitHub issue 2217, with
George Nachman.


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.192 16-May-2020 nicm

xterm-keys has been on by default for five years and all other modern
terminals use these key sequences by default. Merge the code into the
main tty and input tree processing (converting the latter to use a tree
rather than a table at the same time) and make the option a no-op.


# 1.191 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.190 16-May-2020 nicm

Change message log to be per server rather than per client and include
every command that is run.


# 1.189 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


Revision tags: OPENBSD_6_7_BASE
# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.188 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


Revision tags: OPENBSD_6_6_BASE
# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.187 20-Jun-2019 nicm

Expand command formats in %if and move the config file loading later (to
when the first client has identified) so all the client formats are
available, fixes problems reported by Thomas Sattler.


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.186 07-Jun-2019 nicm

Do not load the config file if the server is exiting because it failed
to start, otherwise commands like lsk which start the server again can
end up looping infinitely. Also make the first client exit
correctly. Problem reported by Wael M Nasreddine.


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.185 20-May-2019 nicm

Replace the various identical error callbacks with a single one in cmd-queue.c.


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.184 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.183 23-Aug-2018 nicm

Move job struct into job.c.


# 1.182 18-Aug-2018 nicm

SESSION_UNATTACHED flag is no longer necessary now we have an attached
count instead.


# 1.181 02-Aug-2018 nicm

session_groups can be static also.


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


Revision tags: OPENBSD_6_3_BASE
# 1.180 08-Mar-2018 nicm

Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a
job flags member and a flag to indicate other jobs). GitHub issue 1245.


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.179 22-Feb-2018 nicm

Add exit-empty option to exit server if no sessions (defaults to on).


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.178 19-Dec-2017 nicm

Report better error from server when socket create fails, GitHub issue
1201.


# 1.177 12-Oct-2017 nicm

Show exit status and time in the remain-on-exit pane text, mostly from
Timo Boettcher in GitHub issue 1103.


Revision tags: OPENBSD_6_2_BASE
# 1.176 14-Jul-2017 nicm

Because ignore SIGCHLD early, letting signal_del restore it doesn't work
correctly, so set it explicitly back to default (and the others for good
measure).


# 1.175 12-Jul-2017 nicm

Block signals between forking and clearing signal handlers (or calling
event_reinit) - if the child gets a signal and fires the libevent signal
handler during this period it could write a signal into the parent's
signal pipe. GitHub issue 1001 from Aaron van Geffen.


# 1.174 12-Jul-2017 nicm

Move signal code into proc.c.


# 1.173 09-Jul-2017 nicm

Some extra logging to show why tmux might exit.


# 1.172 03-Jul-2017 nicm

Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.


# 1.171 04-Jun-2017 nicm

Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than
-v and -vvvv, and clarify the man page entry for -v.


# 1.170 22-Apr-2017 nicm

Memory leaks, from David CARLIER.


# 1.169 21-Apr-2017 nicm

Make the cmd_find_* functions more obvious when looking for a client,
rather than having it inside other functions. Should be no change to the
way targets are resolved just yet.


# 1.168 21-Apr-2017 nicm

History needs to be loaded after config parsing is done - now that
commands are queued, that's in cfg_done not after start_cfg finishes.


# 1.167 20-Apr-2017 nicm

If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.

Requested by someone about 10 years ago...


Revision tags: OPENBSD_6_1_BASE
# 1.166 09-Feb-2017 nicm

Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.


# 1.165 24-Jan-2017 nicm

Fixed keys for choose mode, and remove the last mode keys bits.


# 1.164 12-Nov-2016 nicm

Do not execute commands for a client until it has identified, fixes
problem reported by Frank Terbeck.


# 1.163 16-Oct-2016 nicm

Notifys can go via the command queue instead of using their own queue.


# 1.162 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.161 15-Oct-2016 nicm

Drain notifys once at the end of the server loop instead of doing it
from the end of every command queue (which could be nested).


# 1.160 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.159 07-Jul-2016 semarie

tmux: only consider ACCESSPERMS for setting mode on socket_path.

it explicitly removes any S_ISUID|S_ISGID|S_ISTXT bits, instead of letting
pledge(2) silenciously remove them.

ok nicm@ beck@ deraadt@


# 1.158 30-Mar-2016 nicm

Bump the listen() backlog up, some people have scripts that run up a lot
of clients quickly.


Revision tags: OPENBSD_5_9_BASE
# 1.157 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.156 16-Dec-2015 nicm

Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.


# 1.155 15-Dec-2015 nicm

Make the marked pane a cmd_find_state.


# 1.154 24-Nov-2015 nicm

Do lock failures slightly better, return a special value so we don't
unlink the wrong thing.


# 1.153 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.152 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.151 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.150 18-Nov-2015 nicm

Use __unused rather than rolling our own.


# 1.149 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.148 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.147 12-Nov-2015 nicm

Tidy utf8.c a little: build table on first use, and make utf8_width take
a u_int rather than splitting and then combining again in utf8_split.


# 1.146 31-Oct-2015 nicm

The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.


# 1.145 27-Oct-2015 nicm

Move struct options into options.c.


# 1.144 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.143 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.142 22-Oct-2015 nicm

This should not be changed.


# 1.141 22-Oct-2015 nicm

Rename shutdown to exit.


# 1.140 11-Oct-2015 guenther

Userspace doesn't need to use SUN_LEN(): connect() and bind() must accept
sizeof(struct sockaddr_un), so do the simple, portable thing

ok beck@ deraadt@


# 1.139 01-Sep-2015 nicm

Move initial conf load into cfg.c.


# 1.138 30-Aug-2015 nicm

Event base does not need to be global.


# 1.137 29-Aug-2015 nicm

We already loop over the windows in server_client_loop, so don't do it
again in server_loop just to check names.


# 1.136 29-Aug-2015 nicm

Move alerts onto events rather than checking every loop.


# 1.135 28-Aug-2015 nicm

Remove unused prototypes.


# 1.134 28-Aug-2015 nicm

Per-session timers for locking, and remove the global one-second timer.


# 1.133 28-Aug-2015 nicm

Remove the lock-server option which is a bit redundant, it isn't that
different without it.


# 1.132 28-Aug-2015 nicm

Give clock mode its own timer.


# 1.131 28-Aug-2015 nicm

Run status update on a per-client timer at status-interval.


# 1.130 28-Aug-2015 nicm

Move format job cleanup onto its own timer.


Revision tags: OPENBSD_5_8_BASE
# 1.129 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.128 05-Jun-2015 nicm

Similarly, for sessions use a callback to free rather than checking
every loop.


# 1.127 05-Jun-2015 nicm

Instead of putting dead clients on a list and checking it every loop,
use event_once to queue a callback to deal with them. Also dead clients
with references would never actually be freed because the wrap-up
functions (the callback for stdin, or status_prompt_clear) would never
be called. So call them in server_client_lost.


# 1.126 04-Jun-2015 nicm

Add support for a single "marked pane". There is one marked pane in the
server at a time; it may be toggled or cleared with select-pane -m and
-M (the border is highlighted). A new target '~' or '{marked}' specifies
the marked pane to commands and it is the default target for the
swap-pane and join-pane -s flag (this makes them much simpler to use -
mark the source pane and then change to the target pane to run swapp or
joinp).


# 1.125 01-Jun-2015 nicm

Clear signal handlers before event_reinit as apparently it can otherwise
cause libevent to go strange.


# 1.124 31-May-2015 deraadt

does not need syslog.h


# 1.123 27-May-2015 nicm

Move the jobs output cache into the formats code so that #() work more
generally (for example, again working in set-titles-string).


# 1.122 24-Apr-2015 nicm

Convert clients list into a TAILQ.


# 1.121 22-Apr-2015 nicm

Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.


# 1.120 22-Apr-2015 nicm

window_index is only used in one place (window_destroy) so inline it there.


# 1.119 21-Apr-2015 nicm

Do not die on USR1 if any of the socket parent directories are
missing. Reported by Robin Powell.


Revision tags: OPENBSD_5_7_BASE
# 1.118 09-Dec-2014 nicm

Add pane_dead_status for exit status of dead panes.


# 1.117 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


# 1.116 01-Sep-2014 nicm

Wake up any clients waiting with the wait-for command when the server
exits.


Revision tags: OPENBSD_5_6_BASE
# 1.115 21-Jul-2014 nicm

lockf is entirely useless and it was a mistake to change to it, go back
to using flock which actually works sensibly. Also always retry the lock
to fix a potential race, and add some extra logging.


# 1.114 14-May-2014 nicm

Now that cmdlists are reference counted, there is no need for two-step
deletion via the dead_key_bindings tree. From Keith Amling.


# 1.113 24-Apr-2014 nicm

There is no longer a need for a paste_stack struct or for global_buffers
to be global. Move to paste.c.


# 1.112 17-Apr-2014 nicm

Some more long lines.


Revision tags: OPENBSD_5_5_BASE
# 1.111 20-Oct-2013 nicm

Do not run any command line command from the client which starts the
server until after the configuration file completes. This prevents it
racing against run-shell or if-shell in .tmux.conf that run in the
background.


Revision tags: OPENBSD_5_4_BASE
# 1.110 24-Apr-2013 nicm

Rename global configuration define.


# 1.109 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


# 1.108 22-Mar-2013 nicm

No more lint means no more ARGSUSED.


Revision tags: OPENBSD_5_3_BASE
# 1.107 06-Dec-2012 nicm

Fix argument order in a log statement.


# 1.106 19-Nov-2012 nicm

Use a utility function for common code to show errors in config file,
from Thomas Adam.


Revision tags: OPENBSD_5_2_BASE
# 1.105 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.104 11-Apr-2012 nicm

Stop accepting new clients for 1 second on EMFILE/ENFILE. Based on
ongoing fixes to other daemons by Theo.


# 1.103 09-Mar-2012 nicm

Use a lock file and flock() to serialize server start, avoids problems
when running a bunch of tmux from cron at the same time. Based on a diff
from Tim Ruehsen.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.102 27-Mar-2011 nicm

Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.


Revision tags: OPENBSD_4_9_BASE
# 1.101 26-Jan-2011 nicm

Use LIST_* not SLIST_*.


# 1.100 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.99 01-Jan-2011 nicm

Don't reset the activity timer for unattached sessions every second,
this screws up the choice of most-recently-used. Instead, break the time
update into a little function and do it when the session is attached.

Pointed out by joshe@.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 21-Dec-2010 nicm

Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).

Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.


# 1.96 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.95 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.94 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.93 26-Sep-2010 nicm

Modify the permissions on the socket when adding or removing +x to show
attached sessions, rather than replacing them.


# 1.92 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.91 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.90 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.89 21-Jun-2010 nicm

Give tmux sockets (but not the containing folder) group
permissions. This allows hardlinks to the sockets to be used more
easily.


# 1.88 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.87 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.86 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.85 06-Apr-2010 nicm

Merge copy mode and output mode, dropping the latter. Idea and code from
Micah Cowan.


# 1.84 22-Mar-2010 nicm

Nuke unused variable.


Revision tags: OPENBSD_4_7_BASE
# 1.83 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.82 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.81 30-Jan-2010 nicm

Ignore SIGHUP as well.


# 1.80 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.79 02-Dec-2009 nicm

Close the pane if the process died due to a signal, not just if it exited
normally.


# 1.78 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.77 13-Nov-2009 nicm

Destroy panes immediately rather than checking them all every loop.


# 1.76 11-Nov-2009 nicm

Free the pane bufferevent when the fd is closed (the signal could come before
the error callback).


# 1.75 11-Nov-2009 nicm

Only need to chmod +x or -x the socket when a client is created, lost or
attached, rather than every event loop.


# 1.74 05-Nov-2009 nicm

EVLOOP_ONCE takes care of the wakeup, so no need to call event_loopexit(NULL).


# 1.73 05-Nov-2009 nicm

Now all timers are events, there is no longer any need to wake up every 50 ms -
only wake up when an event happens.


# 1.72 04-Nov-2009 nicm

Move status timer check into the global once-per-second timer, this could maybe
be done better but one every second is better than once every 50 ms.


# 1.71 04-Nov-2009 nicm

Don't reenlist the client imsg event every loop, instead have a small function
to it and call it after the event triggers or after a imsg is added.


# 1.70 04-Nov-2009 nicm

Tell the client to exit on configuration file error.


# 1.69 04-Nov-2009 nicm

Convert the window pane (pty master side) fd over to use a bufferevent.

The evbuffer API is very similar to the existing tmux buffer API so this was
remarkably painless. Not many possible ways to do it, I suppose.


# 1.68 04-Nov-2009 nicm

Call event_init() before loading the config file, since potentially it could
set up events.


# 1.67 04-Nov-2009 nicm

Switch jobs over to use a bufferevent.


# 1.66 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.65 03-Nov-2009 nicm

Change session and client activity and creation time members to have more
meaningful names.

Also, remove the code to try and update the session activity time for the
command client when a command message is received as is pointless because it
des not have a session.


# 1.64 02-Nov-2009 nicm

Reorder slightly to tidy code.


# 1.63 27-Oct-2009 nicm

Move the poll registration functions into the server-*.c files.


# 1.62 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.61 26-Oct-2009 nicm

Clear signal flags /before/ taking action and continue afterwards to reduce
chance of dropping signals. Pointed out by deraadt@.


# 1.60 22-Oct-2009 nicm

Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than
iterating over each set after poll(), allow a callback to be specified when the
fd is added and just walk once over the returned pollfds calling each callback
where needed.

More to come, getting this in so it is tested.


# 1.59 13-Oct-2009 nicm

When a session is unattached, reset its activity timer to prevent it locking
instantly when reattached.


# 1.58 12-Oct-2009 nicm

Similarly add a tty_cursor_pane function to tidy up most of the calls.


# 1.57 12-Oct-2009 nicm

_absolute is redundant, just use tty_region.


# 1.56 12-Oct-2009 nicm

Cleanup: use two functions for region setting, one for absolute and one inside
pane.


# 1.55 11-Oct-2009 nicm

Add a pipe-pane command to allow a pane to be piped to a shell command, for
example:

pipe-pane 'cat >~/out'

No arguments stops outputing and closes the pipe; the -o flag toggles a pipe
and on and off (useful for key bindings).

Suggested by espie@.


# 1.54 11-Oct-2009 nicm

Switch run-shell over to queue the command in the background like #().


# 1.53 11-Oct-2009 nicm

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.


# 1.52 11-Oct-2009 nicm

Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.

As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.


# 1.51 11-Oct-2009 nicm

Braek some bits out of server_fill_client() that aren't really related to
polling into their own function.


# 1.50 10-Oct-2009 nicm

Put all jobs on a global all_jobs list and use that in server.c instead of
running through all the clients.


# 1.49 10-Oct-2009 nicm

Rather than running status-left, status-right and window title #() with popen
immediately every redraw, queue them up and run them in the background,
starting each once every status-interval. The actual status line uses the
output from the last run.

This brings several advantages:

- tmux itself may be called from inside #() without causing the server to hang;
- likewise, sleep or similar doesn't cause the server to block;
- commands aren't run excessively often when redrawing;
- commands shared by status-left and status-right, or used multiple times, will
only be run once.

run-shell and if-shell still use system()/popen() but will be changed over to
use this too later.


# 1.48 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.47 10-Oct-2009 nicm

Add "grouped sessions" which have independent name, options, current window and
so on but where the linked windows are synchronized (ie creating, killing
windows and so on are mirrored between the sessions). A grouped session may be
created by passing -t to new-session.

Had this around for a while, tested by a couple of people.


# 1.46 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.45 10-Oct-2009 nicm

Instead of passing a struct pollfd ** around through various functions, build
them into a tree and then convert into a flat poll array before and after poll.

This adds a little code but should reduce annoying problems with ordering when
adding new things that also need to be polled.


# 1.44 05-Oct-2009 nicm

If no target client is specified to commands which accept one, try to guess the
current client, in a similar manner to how sessions already work: if the
current session can be established and has only one client, use that; otherwise
use the most recently created client.


# 1.43 24-Sep-2009 nicm

Don't allow locked or suspended clients to limit the size of active clients.


# 1.42 23-Sep-2009 nicm

On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they
exit properly.


# 1.41 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.40 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.39 20-Sep-2009 nicm

Regularise some fatal messages.


# 1.38 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.37 15-Sep-2009 nicm

The default terminal size should be 80x24, not 80x25.


# 1.36 14-Sep-2009 nicm

Nuke unused server_client_index function, pointed out by martynas@.


# 1.35 12-Sep-2009 nicm

Doh, trim variables unused now.


# 1.34 12-Sep-2009 nicm

Tidy some common code for destroying sessions into a new function.


# 1.33 10-Sep-2009 nicm

Permit options such as status-bg to be configured using the entire 256 colour
palette by setting "colour0" to "colour255".


# 1.32 07-Sep-2009 nicm

While the display-panes indicator is on screen, make the number keys select the
pane with that index.


# 1.31 07-Sep-2009 nicm

Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.


# 1.30 07-Sep-2009 kili

Tiny cleanup.

ok nicm@


# 1.29 05-Sep-2009 nicm

Only redraw all clients once when the backoff timer expires rather than every
second all the time.

Reported by Simon Nicolussi.


# 1.28 04-Sep-2009 nicm

Tell the user when sleeping due to password backoff.


# 1.27 02-Sep-2009 nicm

When shutting down the server, expect clients to be polite and exit when asked
with the right message.


# 1.26 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.25 31-Aug-2009 nicm

Don't call tty_free unless the client is a terminal, otherwise tty_init hasn't
been called and it may end up doing close(0). From Kalle Olavi Niemitalo.


# 1.24 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.23 18-Aug-2009 nicm

Whoops, getting the comparison the right way round is usually recommended.


# 1.22 18-Aug-2009 nicm

options_get_number() is relatively expensive and a check for dead panes happens
a lot more often than actually finding one, so instead of getting the option
for every check, get it for every dead window found.


# 1.21 14-Aug-2009 nicm

Reset attributes as well as scroll region before poll(2) and add a big comment
explaining why.


# 1.20 11-Aug-2009 nicm

Initialise log_fd to -1, prevents spurious disconnection of the client when it
ends up as fd 0 (likely if the server is started with "tmux start").

Also add some extra debugging messages to server.c.


# 1.19 11-Aug-2009 nicm

Drop the no_stop argument to tty_close and tty_free in favour of a flag in the
tty struct.


# 1.18 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.17 10-Aug-2009 nicm

Reset the attributes after drawing all or part of the screen, and reset the
region before poll(2). This reduces (but does not eliminate) the chance of the
attributes not being normal if tmux is disconnected without warning (ssh ~.,
reboot from inside, etc).


# 1.16 07-Aug-2009 nicm

If there is an error in the configuration file, don't just exit(1) as this can
cause the client to hang. Instead, send the error message, then mark the client
as bad and start a normal shutdown so the server exits once the error is
written.

This also allows some code duplicating daemon(3) to be trimmed and logging to
begin earlier.

Prompted by Theo noticing the behaviour on error wasn't documented.


# 1.15 28-Jul-2009 nicm

Next step towards customisable mode keys: build each default table of keys into
a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).


# 1.14 24-Jul-2009 nicm

Permit commands to be bound to key presses without the prefix key first. The
new -n flag to bind-key and unbind-key sets or removes these bindings, and
list-key shows them in []s.


# 1.13 21-Jul-2009 nicm

Make some functions which return unused values void (mostly found by lint) and
tweak a redundant expression in window_pane_set_mode.


# 1.12 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.11 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.10 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.9 14-Jul-2009 nicm

Instead of faking up a status line in status_redraw, use the same code to
redraw it as to draw the entire screen, just skip all lines but the last.

This makes horizontal split redraw properly when the status line is off.


# 1.8 12-Jul-2009 nicm

Creating a key binding which replaces itself (such as "bind x bind x lsw")
frees the command list bound to the key while it is still being executed,
leading to a use after free. To prevent this, create a dead keys list and defer
freeing replaced or removed key bindings until the main loop when the key
binding will have finished executing.

Found by Johan Friis when creating a key binding to reload his configuration
file.


# 1.7 12-Jul-2009 nicm

If it exist, load a system-wide configuration file /etc/tmux.conf before any
user-specified one.


# 1.6 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.5 26-Jun-2009 nicm

After logging (if enabled) is switched to file, there is no reason to keep
stdin/stdout/stderr active, so dup them to /dev/null.


# 1.4 25-Jun-2009 nicm

Remove some dead assignments, found by sthen with clang.


# 1.3 24-Jun-2009 nicm

Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.

Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.

Initially from Tiago Cunha.


# 1.2 24-Jun-2009 nicm

Make remain-on-exit work again when there is only one pane left, which was
broken sometime during the pane/layout changes. Reported/tested by Iain Morgan,
thanks.


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti