cherry-pick.softflowd-0.9.9-10-g2f195a0.check-pidfile-to-see-if-daemon-already-running.patch 848 B

123456789101112131415161718192021222324252627
  1. Subject: Check pidfile to see if daemon already running
  2. Origin: softflowd-0.9.9-10-g2f195a0 <https://github.com/irino/softflowd/commit/softflowd-0.9.9-10-g2f195a0>
  3. Upstream-Author: SysError956 <paulgodard@gmail.com>
  4. Date: Tue Apr 25 18:09:54 2017 -0400
  5. --- a/softflowd.c
  6. +++ b/softflowd.c
  7. @@ -1951,6 +1951,19 @@
  8. r = daemon(0, 0);
  9. loginit(PROGNAME, 0);
  10. + if ((pidfile = fopen(pidfile_path, "r")) != NULL) {
  11. + int pid;
  12. + fscanf(pidfile,"%d", &pid);
  13. + fclose(pidfile);
  14. +
  15. + /* Check if the pid exists */
  16. + int pidfree = (kill(pid, 0) && errno == ESRCH);
  17. + if (!pidfree) {
  18. + fprintf(stderr, "Already running under pid %d\n",
  19. + pid);
  20. + exit(1);
  21. + }
  22. + }
  23. if ((pidfile = fopen(pidfile_path, "w")) == NULL) {
  24. fprintf(stderr, "Couldn't open pidfile %s: %s\n",
  25. pidfile_path, strerror(errno));