[5.2] 0a4222f Only use the kill(pid, 0) test to detect dead process if it has indicated the process was present at one point.

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Fri Sep 15 11:17:14 UTC 2017


commit 0a4222f72d3f0c66003a98a79442c69f199cb68e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Sep 8 12:17:15 2017 +0000

    Only use the kill(pid,0) test to detect dead process if it has
    indicated the process was present at one point.

diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index ccb0dfb..e7cc519 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -120,6 +120,8 @@ struct vsm {
 
 	int			attached;
 	double			patience;
+
+	int			couldkill;
 };
 
 /*--------------------------------------------------------------------*/
@@ -347,9 +349,11 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb)
 		closefd(&vs->fd);
 	}
 
-
-	if (vs->fd >= 0)
-		return (retval|VSM_MGT_RUNNING);
+	if (vs->fd >= 0) {
+		if (!vd->couldkill || !kill(vs->id1, 0))
+			retval |= VSM_MGT_RUNNING;
+		return (retval);
+	}
 
 	retval |= VSM_MGT_CHANGED;
 	vs->fd = openat(vs->dfd, "_.index", O_RDONLY);
@@ -377,7 +381,13 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb)
 	 * XXX: be kill(pid,0)'ed for more rapid abandonment detection.
 	 */
 	i = sscanf(VSB_data(vsb), "# %ju %ju\n%n", &id1, &id2, &ac);
-	if (i != 2 || (kill(id1, 0) && errno == ESRCH)) {
+	if (i != 2) {
+		retval |= VSM_MGT_RESTARTED | VSM_MGT_CHANGED;
+		return (retval);
+	}
+	if (!kill(id1, 0)) {
+		vd->couldkill = 1;
+	} else if (vd->couldkill && errno == ESRCH) {
 		retval |= VSM_MGT_RESTARTED | VSM_MGT_CHANGED;
 		return (retval);
 	}


More information about the varnish-commit mailing list