Skip to content

Commit cfd9b8a

Browse files
committed
hopefully rolling back the cmd debug
1 parent 31f5e12 commit cfd9b8a

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

util/exec/exec.go

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,11 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
186186

187187
// Best-effort cleanup of a stale HEAD.lock after the command finishes.
188188
defer func() {
189-
190189
if cmd.Dir == "" {
191190
return
192191
}
193192
lockPath := filepath.Join(cmd.Dir, ".git", "HEAD.lock")
194-
logCtx.WithFields(logrus.Fields{"headLockPath": lockPath}).Info("Checking HEAD.lock presense post-exec")
193+
logCtx.WithFields(logrus.Fields{"headLockPath": lockPath}).Info("Checking HEAD.lock presence post-exec")
195194
if _, err := os.Stat(lockPath); err == nil {
196195
// Log and attempt removal; ignore ENOENT races
197196
logCtx.WithFields(logrus.Fields{"headLockPath": lockPath}).Warn("HEAD.lock present post-exec, removing it")
@@ -218,22 +217,42 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
218217
"headLockExists": exists,
219218
"where": where,
220219
}
220+
221+
pgid, pgErr := syscall.Getpgid(cmd.Process.Pid)
222+
if pgErr == nil && pgid > 0 {
223+
// Portable ps: list all processes, print needed columns without headers, then filter by PGID in Go.
224+
out, _ := exec.Command(
225+
"ps",
226+
"-ax",
227+
"-o", "pid=,ppid=,pgid=,etime=,comm=,args=",
228+
).Output()
229+
if len(out) > 0 {
230+
var b strings.Builder
231+
want := strconv.Itoa(pgid)
232+
for _, line := range strings.Split(string(out), "\n") {
233+
line = strings.TrimSpace(line)
234+
if line == "" {
235+
continue
236+
}
237+
fieldsSlice := strings.Fields(line)
238+
if len(fieldsSlice) < 3 {
239+
continue
240+
}
241+
if fieldsSlice[2] == want {
242+
b.WriteString(line)
243+
b.WriteByte('\n')
244+
}
245+
}
246+
fields["gitProcsInGroup"] = strings.TrimSpace(b.String())
247+
}
248+
}
249+
221250
if exists {
222251
fields["headLockSize"] = fileInfo.Size()
223252
fields["headLockMode"] = fileInfo.Mode().String()
224253
fields["headLockModTime"] = fileInfo.ModTime()
225254
fields["headLockIsDir"] = fileInfo.IsDir()
226255

227-
pgid, pgErr := syscall.Getpgid(cmd.Process.Pid)
228-
if pgErr == nil && pgid > 0 {
229-
out, _ := exec.Command(
230-
"ps",
231-
"-o", "pid,ppid,pgid,etime,comm,args",
232-
"--no-headers",
233-
"--pgroup", strconv.Itoa(pgid),
234-
).CombinedOutput()
235-
fields["processesInGroup"] = strings.TrimSpace(string(out))
236-
}
237256
}
238257
logCtx.WithFields(fields).Info("HEAD.lock status")
239258
}

0 commit comments

Comments
 (0)