summaryrefslogtreecommitdiff
path: root/internal/askcli/runlock_stale_linux.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-13 08:09:33 +0300
committerPaul Buetow <paul@buetow.org>2026-04-13 08:10:16 +0300
commitf2dd8d8a515c1a2a220836231ad1a671a5e9b73d (patch)
tree5b19585afb01b60d03d24a96b57bc7b986ea4cc0 /internal/askcli/runlock_stale_linux.go
parent56002ff942de1bfb0ce467ec37a692b8c4ca01e9 (diff)
ask: serialize concurrent CLI with repo lock and stale PID recovery
Add advisory lock under .git/hexai-ask.lock around Taskwarrior execution, with metadata (PID and process basename) and Linux /proc comm checks to remove orphan lock files when the recorded holder is gone or not ask. Extract internal/filelock for shared flock helpers; stats uses it too. Made-with: Cursor
Diffstat (limited to 'internal/askcli/runlock_stale_linux.go')
-rw-r--r--internal/askcli/runlock_stale_linux.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/askcli/runlock_stale_linux.go b/internal/askcli/runlock_stale_linux.go
new file mode 100644
index 0000000..183dfb2
--- /dev/null
+++ b/internal/askcli/runlock_stale_linux.go
@@ -0,0 +1,33 @@
+//go:build linux
+
+package askcli
+
+import (
+ "os"
+ "strconv"
+ "strings"
+
+ "golang.org/x/sys/unix"
+)
+
+func lockHolderIsStale(pid int, expectedComm string) bool {
+ if pid <= 0 {
+ return false
+ }
+ if err := unix.Kill(pid, 0); err != nil {
+ return true
+ }
+ data, err := os.ReadFile("/proc/" + strconv.Itoa(pid) + "/comm")
+ if err != nil {
+ return false
+ }
+ holder := strings.TrimSpace(string(data))
+ if holder == "" {
+ return false
+ }
+ want := expectedComm
+ if len(want) > 15 {
+ want = want[:15]
+ }
+ return holder != want
+}