Skip to content

Commit 19aa1db

Browse files
committed
return err instead of log fatal
1 parent e57a3e5 commit 19aa1db

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

process.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"fmt"
77
"io"
8-
"log"
98
"os"
109
"os/exec"
1110
"strconv"
@@ -157,7 +156,7 @@ func (p *Process) FindProcess() error {
157156

158157
ps, err := exec.Command("ps", "-e").Output()
159158
if err != nil {
160-
log.Fatalln(err)
159+
return err
161160
}
162161

163162
scanner := bufio.NewScanner(bytes.NewReader(ps))
@@ -278,7 +277,7 @@ func FindByPid(pid int) (*Process, error) {
278277
// ps -o tty=,comm= -p $PID
279278
pidCmd, err := exec.Command("ps", "-o", "tty=,comm=", pidStr).Output()
280279
if err != nil {
281-
log.Fatalln(err)
280+
return nil, err
282281
}
283282

284283
// Split the tty and command parts from the result of the above ps command.
@@ -295,7 +294,7 @@ func FindByPid(pid int) (*Process, error) {
295294
// Get the ps command= string result.
296295
pidCommandEq, err := exec.Command("ps", "-o", "command=", pidStr).Output()
297296
if err != nil {
298-
log.Fatalln(err)
297+
return nil, err
299298
}
300299

301300
// Split the command= string after the comm= string.
@@ -309,7 +308,7 @@ func FindByPid(pid int) (*Process, error) {
309308
// lsof -p $PID
310309
lsofOutput, err := exec.Command("lsof", "-p", pidStr).Output()
311310
if err != nil {
312-
log.Fatalln(err)
311+
return nil, err
313312
}
314313

315314
scanner := bufio.NewScanner(bytes.NewReader(lsofOutput))

0 commit comments

Comments
 (0)