Skip to content

Commit d24d7d3

Browse files
authored
Parent ID: Exception for nodejs. Can use TAU_PPID Env Variable (#53)
1 parent 8cbd68b commit d24d7d3

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

singletons/session/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func Delete() error {
10-
processDir, found := nearestProcessDirectory(os.Getppid())
10+
processDir, found := nearestProcessDirectory(parentId())
1111
if !found || len(processDir) == 0 {
1212
return singletonsI18n.SessionNotFound()
1313
}

singletons/session/discovery.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,38 @@ import (
44
"fmt"
55
"os"
66
"path"
7+
"strconv"
78

89
"github.com/mitchellh/go-ps"
910
)
1011

11-
func parentId(pid int) (int, error) {
12-
process, err := ps.FindProcess(pid)
12+
func parentId() int {
13+
var ppid int
14+
15+
envppid := os.Getenv("TAU_PPID")
16+
if envppid != "" {
17+
ppid, _ = strconv.Atoi(envppid)
18+
} else {
19+
ppid = os.Getppid()
20+
}
21+
22+
process, err := ps.FindProcess(ppid)
1323
if err != nil {
14-
return 0, err
24+
return ppid
1525
}
1626

1727
// This is for `go run .`
18-
if process.Executable() == "go" {
19-
return process.PPid(), nil
28+
if process.Executable() == "go" || process.Executable() == "node" {
29+
return process.PPid()
2030
}
2131

22-
return process.Pid(), nil
32+
return process.Pid()
2333
}
2434

2535
func discoverOrCreateConfigFileLoc() (string, error) {
26-
grandPid, err := parentId(os.Getppid())
27-
if err != nil {
28-
return "", err
29-
}
36+
grandPid := parentId()
3037

38+
var err error
3139
processDir, found := nearestProcessDirectory(grandPid)
3240
if !found {
3341
processDir, err = createProcessDirectory(grandPid)

0 commit comments

Comments
 (0)