mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-12 07:41:42 +00:00
Optimisation & fixes
This commit is contained in:
@@ -67,6 +67,10 @@ func formatProcessList(processes []processInfo) string {
|
||||
|
||||
// getProcessNameByPID retrieves the process name for a given PID on Unix systems
|
||||
func getProcessNameByPID(pid string) string {
|
||||
if !isValidPID(pid) {
|
||||
return ""
|
||||
}
|
||||
// #nosec G204 -- pid is validated by isValidPID() to contain only digits
|
||||
cmd := exec.Command("ps", "-p", pid, "-o", "comm=")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
@@ -302,11 +306,11 @@ func FormatConflicts(conflicts []PortConflict) string {
|
||||
sb.WriteString(strings.Repeat("=", 50) + "\n\n")
|
||||
|
||||
for _, conflict := range conflicts {
|
||||
sb.WriteString(fmt.Sprintf("Port %d\n", conflict.Port))
|
||||
fmt.Fprintf(&sb, "Port %d\n", conflict.Port)
|
||||
if conflict.Resource != "" {
|
||||
sb.WriteString(fmt.Sprintf(" Needed for: %s\n", conflict.Resource))
|
||||
fmt.Fprintf(&sb, " Needed for: %s\n", conflict.Resource)
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" Currently used by: %s\n", conflict.UsedBy))
|
||||
fmt.Fprintf(&sb, " Currently used by: %s\n", conflict.UsedBy)
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forward
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -264,7 +265,7 @@ func (s *WatchdogTestSuite) TestConcurrentOperations() {
|
||||
wg.Add(1)
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
forwardID := string(rune('a' + id))
|
||||
forwardID := fmt.Sprintf("worker-%d", id)
|
||||
s.watchdog.RegisterWorker(forwardID, nil)
|
||||
for j := 0; j < 10; j++ {
|
||||
s.watchdog.Heartbeat(forwardID)
|
||||
|
||||
Reference in New Issue
Block a user