MCPcopy Create free account
hub / github.com/coder/agentapi / cleanupPIDFile

Function cleanupPIDFile

cmd/server/server.go:340–359  ·  view source on GitHub ↗

cleanupPIDFile removes the PID file if it was written by this process.

(pidFile string, logger *slog.Logger)

Source from the content-addressed store, hash-verified

338
339// cleanupPIDFile removes the PID file if it was written by this process.
340func cleanupPIDFile(pidFile string, logger *slog.Logger) {
341 data, err := os.ReadFile(pidFile)
342 if err != nil {
343 if !os.IsNotExist(err) {
344 logger.Error("Failed to read PID file for cleanup", "pidFile", pidFile, "error", err)
345 }
346 return
347 }
348 pidStr := strings.TrimSpace(string(data))
349 filePID, err := strconv.Atoi(pidStr)
350 if err != nil || filePID != os.Getpid() {
351 logger.Info("PID file belongs to another process, skipping cleanup", "pidFile", pidFile, "filePID", pidStr)
352 return
353 }
354 if err := os.Remove(pidFile); err != nil && !os.IsNotExist(err) {
355 logger.Error("Failed to remove PID file", "pidFile", pidFile, "error", err)
356 } else if err == nil {
357 logger.Info("Removed PID file", "pidFile", pidFile)
358 }
359}
360
361type flagSpec struct {
362 name string

Callers 2

runServerFunction · 0.85
TestPIDFileOperationsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestPIDFileOperationsFunction · 0.68