]> mj.ucw.cz Git - libucw.git/commitdiff
Daemon: Fixed more race conditions. v6.1.1
authorPavel Charvat <pchar@ucw.cz>
Fri, 10 Oct 2014 12:56:58 +0000 (12:56 +0000)
committerPavel Charvat <pchar@ucw.cz>
Fri, 10 Oct 2014 12:56:58 +0000 (12:56 +0000)
ucw/daemon-ctrl.c

index 029a39d91e8db2a2624b35962aa6db5cc215397b..6834b0c845d2164dad04814516e439b4a79842c1 100644 (file)
@@ -187,7 +187,7 @@ daemon_control(struct daemon_control_params *dc)
       if (pid)
        {
          sig = dc->signal ? : SIGTERM;
-         if (kill(pid, sig) < 0)
+         if (kill(pid, sig) < 0 && errno != ESRCH)
            {
              st = daemon_control_err(dc, "Cannot send signal %d: %m", sig);
              goto done;
@@ -205,10 +205,12 @@ daemon_control(struct daemon_control_params *dc)
       if (!pid)
        return DAEMON_STATUS_NOT_RUNNING;
       sig = dc->signal ? : SIGHUP;
-      if (kill(pid, sig) < 0)
-       st = daemon_control_err(dc, "Cannot send signal %d: %m", sig);
-      else
+      if (kill(pid, sig) >= 0)
        st = DAEMON_STATUS_OK;
+      else if (errno == ESRCH)
+       st = DAEMON_STATUS_NOT_RUNNING;
+      else
+       st = daemon_control_err(dc, "Cannot send signal %d: %m", sig);
       break;
     default:
       ASSERT(0);