tmuxserver

package
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
var ErrLiveControlClients = errors.New("live Sidecar control clients still hold the tmux server")

ErrLiveControlClients reports that recovery cannot finish without affecting a control client whose parent is still alive.

Functions

func ParsePID

func ParsePID(field string) (int, bool)

ParsePID reads a #{pid} format field. The empty string, the unresolved literal "#{pid}", and non-positive values are not a pid.

func RecoverExitPending added in v1.15.0

func RecoverExitPending(ctx context.Context, observed Status) ([]int, error)

RecoverExitPending terminates only revalidated orphaned Sidecar control clients attached to the observed socket, then waits for tmux to exit by itself. It never sends a signal to the tmux server.

func SocketBinding added in v1.16.0

func SocketBinding(path string) string

SocketBinding names the socket file a server bound at path by its device, inode and modification time, with one stat and no subprocess. Unlike String it ignores ctime, which tmux changes whenever the attached-client set changes; device, inode and mtime are set when the server binds the socket and are new when a replacement server binds it again. A missing or unreadable socket is reported as such, so two such observations still compare equal and differ from any bound socket.

Types

type ControlClient added in v1.15.0

type ControlClient struct {
	PID       int    `json:"pid"`
	ParentPID int    `json:"parentPid"`
	StartedAt string `json:"startedAt"`
	Command   string `json:"command"`
	Orphaned  bool   `json:"orphaned"`
}

ControlClient is a process connected to the tmux socket whose argv is the exact control-mode attach form Sidecar starts.

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

type State added in v1.15.0

type State string

State describes whether the tmux namespace can accept commands. ExitPending is distinct from Absent: a tmux server still owns the socket, but is refusing new commands while attached clients keep its shutdown pending.

const (
	StateUnknown     State = "unknown"
	StateAbsent      State = "absent"
	StateReady       State = "ready"
	StateExitPending State = "exit_pending"
)

func (State) String added in v1.15.0

func (s State) String() string

type Status added in v1.15.0

type Status struct {
	State   State           `json:"state"`
	Socket  string          `json:"socket"`
	Detail  string          `json:"detail,omitempty"`
	Clients []ControlClient `json:"clients,omitempty"`
}

Status is one observation of the tmux namespace.

func Inspect added in v1.15.0

func Inspect(ctx context.Context) (Status, error)

Inspect distinguishes an absent server, a responsive server, and tmux's exit-pending state. All subprocesses address the resolved socket explicitly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL