Skip to content

Commit 53a5ab2

Browse files
author
David Grieser
committed
Revert back ai slop.
1 parent 424a20a commit 53a5ab2

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

pkg/proc/basejob.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (job *baseJob) SignalAll(sig syscall.Signal) {
3131
}
3232
}
3333

34-
if job.Cmd == nil || job.Cmd.Process == nil {
34+
if job.cmd == nil || job.cmd.Process == nil {
3535
errFunc(
3636
fmt.Errorf("job is not running"),
3737
)
@@ -43,10 +43,10 @@ func (job *baseJob) SignalAll(sig syscall.Signal) {
4343
}
4444

4545
func (job *baseJob) signalAll(sig syscall.Signal) error {
46-
if job.Cmd.Process.Pid <= 0 { // Ensure PID is positive before negating
46+
if job.cmd.Process.Pid <= 0 { // Ensure PID is positive before negating
4747
return syscall.Errno(syscall.ESRCH) // No such process or invalid PID
4848
}
49-
return syscall.Kill(-job.Cmd.Process.Pid, sig)
49+
return syscall.Kill(-job.cmd.Process.Pid, sig)
5050
}
5151

5252
func (job *baseJob) Signal(sig os.Signal) {
@@ -56,7 +56,7 @@ func (job *baseJob) Signal(sig os.Signal) {
5656
}
5757
}
5858

59-
if job.Cmd == nil || job.Cmd.Process == nil {
59+
if job.cmd == nil || job.cmd.Process == nil {
6060
errFunc(
6161
fmt.Errorf("job is not running"),
6262
)
@@ -70,7 +70,7 @@ func (job *baseJob) Signal(sig os.Signal) {
7070
}
7171

7272
func (job *baseJob) signal(sig os.Signal) error {
73-
process, err := os.FindProcess(job.Cmd.Process.Pid)
73+
process, err := os.FindProcess(job.cmd.Process.Pid)
7474
if err != nil {
7575
return err
7676
}
@@ -167,23 +167,23 @@ func (job *baseJob) startOnce(ctx context.Context, process chan<- *os.Process) e
167167
}
168168

169169
// Only set job.Cmd if cmd.Start() was successful
170-
job.Cmd = cmd
170+
job.cmd = cmd
171171

172172
if process != nil {
173-
process <- job.Cmd.Process
173+
process <- job.cmd.Process
174174
}
175175

176176
errChan := make(chan error, 1)
177177
defer close(errChan)
178178

179179
go func() {
180-
errChan <- job.Cmd.Wait()
180+
errChan <- job.cmd.Wait()
181181
}()
182182

183183
select {
184184
// job errChan or failed
185185
case err := <-errChan:
186-
if job.Cmd != nil && job.Cmd.Process != nil { // Check if process actually started
186+
if job.cmd != nil && job.cmd.Process != nil { // Check if process actually started
187187
if termErr := job.signalAll(syscall.SIGTERM); termErr != nil {
188188
if e, ok := termErr.(syscall.Errno); ok && e == syscall.ESRCH {
189189
// ESRCH (Error No Such Process) is fine, means process group already gone
@@ -209,7 +209,7 @@ func (job *baseJob) startOnce(ctx context.Context, process chan<- *os.Process) e
209209
}
210210
return err
211211
case <-ctx.Done():
212-
if job.Cmd != nil && job.Cmd.Process != nil { // Check if process actually started
212+
if job.cmd != nil && job.cmd.Process != nil { // Check if process actually started
213213
// ctx canceled, try to terminate job
214214
_ = job.signalAll(syscall.SIGTERM)
215215
l.WithField("job.name", job.Config.Name).Info("sent SIGTERM to job's process group on ctx.Done")

pkg/proc/job_common.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (job *CommonJob) Watch() {
177177
}
178178

179179
func (job *CommonJob) IsRunning() bool {
180-
if job.Cmd == nil || job.Cmd.Process == nil || job.Cmd.Process.Pid <= 0 {
180+
if job.cmd == nil || job.cmd.Process == nil || job.cmd.Process.Pid <= 0 {
181181
return false
182182
}
183183
err := job.signal(syscall.Signal(0))
@@ -187,7 +187,7 @@ func (job *CommonJob) IsRunning() bool {
187187
func (job *CommonJob) Restart() {
188188
job.restart = true
189189
// Ensure Cmd and Process are not nil before trying to signal
190-
if job.Cmd != nil && job.Cmd.Process != nil {
190+
if job.cmd != nil && job.cmd.Process != nil {
191191
job.SignalAll(syscall.SIGTERM)
192192
}
193193
if job.interrupt != nil { // Check if interrupt function is set
@@ -198,7 +198,7 @@ func (job *CommonJob) Restart() {
198198
func (job *CommonJob) Stop() {
199199
job.stop = true
200200
// Ensure Cmd and Process are not nil before trying to signal
201-
if job.Cmd != nil && job.Cmd.Process != nil {
201+
if job.cmd != nil && job.cmd.Process != nil {
202202
job.SignalAll(syscall.SIGTERM)
203203
}
204204
if job.interrupt != nil { // Check if interrupt function is set
@@ -210,8 +210,8 @@ func (job *CommonJob) Status() *CommonJobStatus {
210210
running := job.IsRunning()
211211
var pid int
212212
// Ensure Cmd and Process are not nil before trying to access Pid
213-
if running && job.Cmd != nil && job.Cmd.Process != nil {
214-
pid = job.Cmd.Process.Pid
213+
if running && job.cmd != nil && job.cmd.Process != nil {
214+
pid = job.cmd.Process.Pid
215215
}
216216
return &CommonJobStatus{
217217
Pid: pid,

pkg/proc/job_lazy.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ func (job *LazyJob) startProcessReaper(ctx context.Context) {
126126
}
127127

128128
// Ensure Cmd and Cmd.Process are not nil before accessing PID
129-
if job.Cmd == nil || job.Cmd.Process == nil {
129+
if job.cmd == nil || job.cmd.Process == nil {
130130
l.Warn("job.process is not nil, but job.Cmd or job.Cmd.Process is nil; skipping reap cycle")
131131
job.lazyStartLock.Unlock()
132132
continue
133133
}
134-
pidToReap := job.Cmd.Process.Pid
134+
pidToReap := job.cmd.Process.Pid
135135
l.Infof("sending SIGTERM to idle process PID %d", pidToReap)
136136
if err := job.signal(syscall.SIGTERM); err != nil {
137137
l.WithError(err).Warnf("failed to send SIGTERM to PID %d", pidToReap)
@@ -148,7 +148,7 @@ func (job *LazyJob) startProcessReaper(ctx context.Context) {
148148
case <-graceTimer.C:
149149
job.lazyStartLock.Lock()
150150
// Check if the process we sent SIGTERM to is still running
151-
if job.process != nil && job.Cmd != nil && job.Cmd.Process != nil && job.Cmd.Process.Pid == pidToReap {
151+
if job.process != nil && job.cmd != nil && job.cmd.Process != nil && job.cmd.Process.Pid == pidToReap {
152152
l.Warnf("process PID %d did not exit after SIGTERM and grace period; sending SIGKILL", pidToReap)
153153
if err := job.signalAll(syscall.SIGKILL); err != nil {
154154
l.WithError(err).Errorf("failed to send SIGKILL to PID %d", pidToReap)
@@ -157,8 +157,8 @@ func (job *LazyJob) startProcessReaper(ctx context.Context) {
157157
// Process is not nil, but it's not the one we targeted.
158158
// This could happen if the job was quickly restarted.
159159
currentPid := -1
160-
if job.Cmd != nil && job.Cmd.Process != nil {
161-
currentPid = job.Cmd.Process.Pid
160+
if job.cmd != nil && job.cmd.Process != nil {
161+
currentPid = job.cmd.Process.Pid
162162
}
163163
l.Warnf("original process PID %d seems to have exited or changed; current PID is %d. Skipping SIGKILL.", pidToReap, currentPid)
164164
} else {

pkg/proc/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type baseJob struct {
7676
stdErrWg sync.WaitGroup
7777
stdOutWg sync.WaitGroup
7878

79-
Cmd *exec.Cmd // Exported for testability and internal use
79+
cmd *exec.Cmd
8080
restart bool
8181
stop bool
8282
stdout *os.File
@@ -132,7 +132,7 @@ type Job interface {
132132
func newBaseJob(jobConfig *config.BaseJobConfig) (*baseJob, error) {
133133
job := &baseJob{
134134
Config: jobConfig,
135-
Cmd: nil, // Use exported field name
135+
cmd: nil,
136136
restart: false,
137137
stop: false,
138138
stdout: os.Stdout,

0 commit comments

Comments
 (0)