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