util.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2019-2023 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package plugin
  15. import (
  16. "github.com/shirou/gopsutil/v3/process"
  17. "github.com/drakkan/sftpgo/v2/internal/logger"
  18. )
  19. func killProcess(processPath string) {
  20. procs, err := process.Processes()
  21. if err != nil {
  22. return
  23. }
  24. for _, p := range procs {
  25. cmdLine, err := p.Exe()
  26. if err == nil {
  27. if cmdLine == processPath {
  28. err = p.Kill()
  29. logger.Debug(logSender, "", "killed process %v, pid %v, err %v", cmdLine, p.Pid, err)
  30. return
  31. }
  32. }
  33. }
  34. logger.Debug(logSender, "", "no match for plugin process %v", processPath)
  35. }