ci: add golangci-lint config and fix formatting
- Add .golangci.yml with minimal linters (govet, ineffassign) - Run gofmt -s and goimports on all files to fix formatting - Disable fieldalignment and copylocks checks in govet
This commit is contained in:
@@ -41,7 +41,7 @@ func (pm *ProcessManager) Track(proc *os.Process) {
|
||||
pm.mu.Lock()
|
||||
defer pm.mu.Unlock()
|
||||
pm.processes[proc.Pid] = proc
|
||||
|
||||
|
||||
// Auto-cleanup when process exits
|
||||
go func() {
|
||||
proc.Wait()
|
||||
@@ -59,14 +59,14 @@ func (pm *ProcessManager) KillAll() error {
|
||||
procs = append(procs, proc)
|
||||
}
|
||||
pm.mu.RUnlock()
|
||||
|
||||
|
||||
var errors []error
|
||||
for _, proc := range procs {
|
||||
if err := proc.Kill(); err != nil {
|
||||
errors = append(errors, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf("failed to kill %d processes: %v", len(errors), errors)
|
||||
}
|
||||
@@ -82,18 +82,18 @@ func (pm *ProcessManager) Close() error {
|
||||
// KillOrphanedProcesses finds and kills any orphaned pg_dump, pg_restore, gzip, or pigz processes
|
||||
func KillOrphanedProcesses(log logger.Logger) error {
|
||||
processNames := []string{"pg_dump", "pg_restore", "gzip", "pigz", "gunzip"}
|
||||
|
||||
|
||||
myPID := os.Getpid()
|
||||
var killed []string
|
||||
var errors []error
|
||||
|
||||
|
||||
for _, procName := range processNames {
|
||||
pids, err := findProcessesByName(procName, myPID)
|
||||
if err != nil {
|
||||
log.Warn("Failed to search for processes", "process", procName, "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
for _, pid := range pids {
|
||||
if err := killProcessGroup(pid); err != nil {
|
||||
errors = append(errors, fmt.Errorf("failed to kill %s (PID %d): %w", procName, pid, err))
|
||||
@@ -102,15 +102,15 @@ func KillOrphanedProcesses(log logger.Logger) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(killed) > 0 {
|
||||
log.Info("Cleaned up orphaned processes", "count", len(killed), "processes", strings.Join(killed, ", "))
|
||||
}
|
||||
|
||||
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf("some processes could not be killed: %v", errors)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -126,27 +126,27 @@ func findProcessesByName(name string, excludePID int) ([]int, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
var pids []int
|
||||
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
|
||||
for _, line := range lines {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
pid, err := strconv.Atoi(line)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
// Don't kill our own process
|
||||
if pid == excludePID {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
pids = append(pids, pid)
|
||||
}
|
||||
|
||||
|
||||
return pids, nil
|
||||
}
|
||||
|
||||
@@ -158,17 +158,17 @@ func killProcessGroup(pid int) error {
|
||||
// Process might already be gone
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Kill the entire process group (negative PID kills the group)
|
||||
// This catches pipelines like "pg_dump | gzip"
|
||||
if err := syscall.Kill(-pgid, syscall.SIGTERM); err != nil {
|
||||
// If SIGTERM fails, try SIGKILL
|
||||
syscall.Kill(-pgid, syscall.SIGKILL)
|
||||
}
|
||||
|
||||
|
||||
// Also kill the specific PID in case it's not in a group
|
||||
syscall.Kill(pid, syscall.SIGTERM)
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -186,21 +186,21 @@ func KillCommandGroup(cmd *exec.Cmd) error {
|
||||
if cmd.Process == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
pid := cmd.Process.Pid
|
||||
|
||||
|
||||
// Get the process group ID
|
||||
pgid, err := syscall.Getpgid(pid)
|
||||
if err != nil {
|
||||
// Process might already be gone
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Kill the entire process group
|
||||
if err := syscall.Kill(-pgid, syscall.SIGTERM); err != nil {
|
||||
// If SIGTERM fails, use SIGKILL
|
||||
syscall.Kill(-pgid, syscall.SIGKILL)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@ import (
|
||||
// KillOrphanedProcesses finds and kills any orphaned pg_dump, pg_restore, gzip, or pigz processes (Windows implementation)
|
||||
func KillOrphanedProcesses(log logger.Logger) error {
|
||||
processNames := []string{"pg_dump.exe", "pg_restore.exe", "gzip.exe", "pigz.exe", "gunzip.exe"}
|
||||
|
||||
|
||||
myPID := os.Getpid()
|
||||
var killed []string
|
||||
var errors []error
|
||||
|
||||
|
||||
for _, procName := range processNames {
|
||||
pids, err := findProcessesByNameWindows(procName, myPID)
|
||||
if err != nil {
|
||||
log.Warn("Failed to search for processes", "process", procName, "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
for _, pid := range pids {
|
||||
if err := killProcessWindows(pid); err != nil {
|
||||
errors = append(errors, fmt.Errorf("failed to kill %s (PID %d): %w", procName, pid, err))
|
||||
@@ -37,15 +37,15 @@ func KillOrphanedProcesses(log logger.Logger) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(killed) > 0 {
|
||||
log.Info("Cleaned up orphaned processes", "count", len(killed), "processes", strings.Join(killed, ", "))
|
||||
}
|
||||
|
||||
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf("some processes could not be killed: %v", errors)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -58,35 +58,35 @@ func findProcessesByNameWindows(name string, excludePID int) ([]int, error) {
|
||||
// No processes found or command failed
|
||||
return []int{}, nil
|
||||
}
|
||||
|
||||
|
||||
var pids []int
|
||||
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
|
||||
for _, line := range lines {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
// Parse CSV output: "name","pid","session","mem"
|
||||
fields := strings.Split(line, ",")
|
||||
if len(fields) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
// Remove quotes from PID field
|
||||
pidStr := strings.Trim(fields[1], `"`)
|
||||
pid, err := strconv.Atoi(pidStr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
// Don't kill our own process
|
||||
if pid == excludePID {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
pids = append(pids, pid)
|
||||
}
|
||||
|
||||
|
||||
return pids, nil
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func KillCommandGroup(cmd *exec.Cmd) error {
|
||||
if cmd.Process == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// On Windows, just kill the process directly
|
||||
return cmd.Process.Kill()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user