Skip to content

Commit 1d08382

Browse files
arthurbarrGitHub Enterprise
authored andcommitted
Use pgrep and check for error when verifying single process (#1043)
Some CPU emulators seem to have a hard time with the ps command, and the failure can cause runmqserver to crash
1 parent fa14f1f commit 1d08382

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cmd/runmqserver/process.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© Copyright IBM Corporation 2018
2+
© Copyright IBM Corporation 2018, 2025
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -42,10 +42,14 @@ func verifySingleProcess() error {
4242

4343
// Verifies that there is only one instance running of the given program name.
4444
func verifyOnlyOne(programName string) (int, error) {
45-
// #nosec G104
46-
out, _, _ := command.Run("ps", "-e", "--format", "cmd")
47-
//if this goes wrong then assume we are the only one
48-
numOfProg := strings.Count(out, programName)
45+
out, _, err := command.Run("pgrep", programName)
46+
if err != nil {
47+
log.Debugf("Failed to confirm single process: %v", err)
48+
// Don't fail the container in this case, which can occur when
49+
// using a CPU emulator
50+
return 1, nil
51+
}
52+
numOfProg := strings.Count(out, "\n")
4953
if numOfProg != 1 {
5054
return numOfProg, fmt.Errorf("Expected there to be only 1 instance of %s but found %d", programName, numOfProg)
5155
}

0 commit comments

Comments
 (0)