Documentation
¶
Overview ¶
Package proclifecycle is a stdlib-only leaf package (no deps beyond os/ os/signal/path/filepath/strings/sync/syscall/time) holding generic host-process lifecycle plumbing: catchable-signal-triggered cleanup hooks and a stale-temp-file sweep. It has ZERO business being named after VMs — relocated out of sdk/vmshared (FLOOR-SLIM mechanical batch, per an orchestrator ruling) once a consumer census showed it is used directly by charly/main.go AND by candy/plugin-enc, candy/plugin-secrets, candy/plugin-vm, candy/plugin-oci, and sdk/deploykit/localpkg.go — a genuinely shared leaf, never a VM-kit or a charly-core-only dependency. Mirrors the sdk/schemaconcat precedent: a stdlib-only leaf outside the named mechanism kits (kit/deploykit/buildkit/loaderkit/vmshared), so charly/main.go can import it directly without violating IMPORT-PURITY (a leaf is not a mechanism kit), and every kit (vmshared included) may import it too (kits may import leaves).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InstallSignalHandler ¶
func InstallSignalHandler()
InstallSignalHandler arms the global signal handler exactly once. Subsequent calls are no-ops. On SIGTERM/SIGINT/SIGHUP it runs the registered temp cleanups AND the registered shutdown hooks (plugin-client reaping, etc.), then re-raises the signal so the process exits with the conventional 128+signum status code.
SIGKILL is not catchable (kernel-level). Leftover temps from a SIGKILL'd charly are caught by the next invocation's SweepStaleTemps; orphaned plugin servers from a SIGKILL'd charly self-terminate via the plugin SDK's parent-death watch (see plugin/sdk/parentwatch.go).
func RegisterShutdownHook ¶
func RegisterShutdownHook(fn func())
RegisterShutdownHook registers fn to run on a catchable shutdown signal (SIGTERM/SIGINT/SIGHUP), in the signal handler, before it re-raises the signal and the process exits. It is the package-boundary seam that lets package main reap resources this package's signal handler cannot reference directly — notably charly's connected out-of-process plugin clients (providerRegistry.Close): a Ctrl-C'd / `systemctl stop`ped charly kills its plugin servers instead of orphaning them (the 77h-orphan leak). Hooks run in registration order; each MUST be best-effort and bounded (the handler is synchronous). A nil fn is a no-op.
func RegisterTempCleanup ¶
func RegisterTempCleanup(path string)
RegisterTempCleanup registers path for cleanup on graceful shutdown (SIGTERM/SIGINT/SIGHUP). Existing `defer os.Remove(...)` callers keep working for normal exit; this is a SUPPLEMENTAL safety net for the ungraceful-but-catchable signal path. Empty path is a no-op.
func SweepStaleTemps ¶
func SweepStaleTemps()
SweepStaleTemps removes /tmp/<prefix>* entries that are (a) NOT held open by any running process AND (b) older than sweepSafetyFloor AND (c) owned by the current user. Best-effort: never errors, never blocks. Called once from main().
func UnregisterTempCleanup ¶
func UnregisterTempCleanup(path string)
UnregisterTempCleanup removes a path from the registry. Called by the existing defer-cleanup paths after they successfully os.Remove the file, so the registry doesn't accumulate stale entries in long- running charly processes (e.g. `charly mcp serve`).
Types ¶
This section is empty.