Skip to content

Add share-ttl: auto-expire shares after configurable timeout#4

Merged
cgraf78 merged 4 commits intomainfrom
argus/share-ttl
Mar 27, 2026
Merged

Add share-ttl: auto-expire shares after configurable timeout#4
cgraf78 merged 4 commits intomainfrom
argus/share-ttl

Conversation

@argusbot78
Copy link
Copy Markdown
Collaborator

Summary

Shared sessions now expire automatically after a configurable timeout (share-ttl, default: 1 hour). Running ds --share on an already-shared session resets the timer. Set share-ttl = 0 to disable.

Behavior

  • On ds --share: starts a background watcher that fires ds --unshare after share-ttl seconds; prints ds: share will auto-expire in 3600s (run 'ds --share' to reset)
  • On ds --share when already sharing: cancels the old watcher, starts a new one; prints ds: already sharing session '..' (TTL reset to 3600s)
  • On ds --unshare / kill / killall: cancels watcher as part of cleanup
  • TTL = 0: no watcher spawned, no expiry

Implementation

  • New config key share-ttl / env DS_UPTERM_SHARE_TTL (default: 3600)
  • _upterm_ttl_pid_file: state file for watcher PID (.upterm.ttl.pid)
  • _upterm_start_ttl_watcher: spawns detached background process via setsid (or plain subshell fallback) — sleep TTL && ds --unshare SESSION; saves PID for later cancellation
  • _upterm_cancel_ttl_watcher: SIGTERMs the process group to kill both the shell and the sleep child
  • _share_start_success helper: consolidates the three success paths in _share_start to avoid repeating watcher-start logic
  • _share_stop: calls _upterm_cancel_ttl_watcher before cleanup
  • README: new share-ttl row in config table + "Share TTL" section
  • examples/share-upterm.conf: share-ttl=3600 added (commented out)

Notes

  • ds_bin is resolved via command -v ds before forking, with printf %q escaping for safety
  • The watcher runs outside the main shell so it survives terminal detach
  • If ds --unshare is called manually before the timer fires, _share_stop cancels the watcher cleanly

Shared sessions now expire automatically after share-ttl seconds
(default: 3600 / 1 hour). Running `ds --share` on an already-shared
session resets the timer. Set share-ttl = 0 to disable.

Implementation:
- New config key share-ttl / env DS_UPTERM_SHARE_TTL
- _upterm_start_ttl_watcher: spawns a detached background process
  (via setsid or plain subshell) that sleeps for TTL seconds then
  calls `ds --unshare`; saves watcher PID to .upterm.ttl.pid
- _upterm_cancel_ttl_watcher: kills watcher + sleep child (SIGTERM
  process group), removes pid file
- _share_start: starts watcher on successful share; resets timer
  (cancels old watcher, starts new) when re-sharing same session
- _share_stop: cancels watcher before cleanup
- README + examples/share-upterm.conf updated
@cgraf78 cgraf78 merged commit acb2c0e into main Mar 27, 2026
3 checks passed
@cgraf78 cgraf78 deleted the argus/share-ttl branch March 27, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants