Documentation
¶
Overview ¶
Package tmuxserver identifies one tmux server process bound to a socket.
A socket path (tmuxenv.Namespace) outlives the servers that bind it. Every liveness signal Sidecar has is a statement about one server process, so callers need an identity that changes when that process is replaced. This package is state-free: no tea.Cmd, no plugin state.
Index ¶
Constants ¶
const ListSessionsFormat = "#{session_name}\t#{pid}"
ListSessionsFormat is the list-sessions -F value that yields the session name and the server pid in one invocation. #{pid} is server-scoped and was verified to expand in list-sessions on an isolated socket (td-e27291). Do not use #{session_id}: those restart from $0 on a new server.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Incarnation ¶
type Incarnation struct {
// contains filtered or unexported fields
}
Incarnation is an opaque comparable identity of one tmux server process.
Three states are distinguishable and that is the point of the type:
- Present: a specific server, identified by socket (inode, ctime) and/or the tmux server #{pid}.
- Absent: tmux answered "no server running" — a fact about the server, not about any shell.
- Unknown: we could not ask. The zero value is Unknown.
Equal is the same-server predicate. == is field-wise and is the wrong question: Socket()/FromFileInfo leave pid 0 ("not observed yet"), while discovery Combine fills #{pid}, and those two observations are one server. Any transition that Equal reports as false invalidates prior liveness. If a tmux version reuses the socket inode, the stat source degrades to Unknown rather than claiming the same incarnation: inode without ctime is not a safe identity.
func Absent ¶
func Absent() Incarnation
Absent is tmux answering that no server is running on this socket.
func Combine ¶
func Combine(socket Incarnation, pid int) Incarnation
Combine merges a socket-stat observation with a #{pid} parsed from the same list-sessions invocation. Absent wins: a pid is meaningless if tmux already said the server is gone. Otherwise a pid fills in a Present or promotes Unknown to Present.
func FromFileInfo ¶
func FromFileInfo(info os.FileInfo) Incarnation
FromFileInfo is the table-testable form of the socket-stat source.
func FromPath ¶
func FromPath(path string) Incarnation
FromPath stats path and returns Present(inode, ctime, 0) when both are available. Any failure is Unknown.
func Present ¶
func Present(inode uint64, ctime int64, pid int) Incarnation
Present builds a Present incarnation from the identity sources we have.
inode without a ctime cannot distinguish a reused inode from the same socket, so it is dropped. If nothing remains (no ctime-qualified inode and no pid), the result is Unknown, not a fake Present.
func Socket ¶
func Socket() Incarnation
Socket observes tmuxenv.SocketPath with one stat and no subprocess. Missing or unreadable sockets, and inodes we cannot qualify with ctime, are Unknown — Absent is reserved for tmux's own "no server running".
func Unknown ¶
func Unknown() Incarnation
Unknown is the safe default: we could not observe a server.
func (Incarnation) Equal ¶
func (a Incarnation) Equal(b Incarnation) bool
Equal reports whether a and b identify the same server.
pid 0 means "not observed yet". When inode+ctime match, a missing pid on either side does not distinguish two servers. When both pids are set and differ, the same socket file is bound to a different process — that is a new incarnation. Pid-only Present values (inode 0) compare on pid alone.
func (Incarnation) IsAbsent ¶
func (i Incarnation) IsAbsent() bool
IsAbsent reports that tmux answered "no server running".
func (Incarnation) IsPresent ¶
func (i Incarnation) IsPresent() bool
IsPresent reports a concrete server identity.
func (Incarnation) IsUnknown ¶
func (i Incarnation) IsUnknown() bool
IsUnknown reports the zero value and any observation that produced no id.
func (Incarnation) ServerID ¶ added in v1.11.0
func (i Incarnation) ServerID() string
ServerID is the durable, persistable identity of a tmux server: "pid=N".
It exists because String() must not be written to disk. String() embeds the socket's inode and ctime, and tmux rewrites the socket's metadata whenever the set of attached clients changes — so a record keyed on it would appear to name a different server the moment a user attached a client, which is exactly the false "the server was replaced" verdict a cold restore must not act on. The pid is stable for the server's whole lifetime and is new after a restart, which is the only distinction a persisted marker needs to make.
An unknown or absent server has no id, and the empty string says so rather than inventing "pid=0" — a caller comparing markers must be able to tell "a different server" from "no observation".
func (Incarnation) String ¶
func (i Incarnation) String() string