[MEDIUM] support setting a server weight to zero

Sometimes it is useful to be able to set a server's weight to zero.
It allows the server to receive only persistent traffic but never
normal traffic.
diff --git a/src/backend.c b/src/backend.c
index 58de35e..5cea808 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -203,7 +203,8 @@
 		int max = 0;
 		best = NULL;
 		for (cur = px->srv; cur; cur = cur->next) {
-			if (flag == (cur->state &
+			if (cur->eweight &&
+			    flag == (cur->state &
 				     (SRV_RUNNING | SRV_GOINGDOWN | SRV_BACKUP))) {
 				int v;
 
@@ -250,15 +251,24 @@
 		return;
 
 	/* We will factor the weights to reduce the table,
-	 * using Euclide's largest common divisor algorithm
+	 * using Euclide's largest common divisor algorithm.
+	 * Since we may have zero weights, we have to first
+	 * find a non-zero weight server.
 	 */
-	pgcd = p->srv->uweight;
-	for (srv = p->srv->next; srv && pgcd > 1; srv = srv->next) {
-		int w = srv->uweight;
-		while (w) {
-			int t = pgcd % w;
-			pgcd = w;
-			w = t;
+	pgcd = 1;
+	srv = p->srv;
+	while (srv && !srv->uweight)
+		srv = srv->next;
+
+	if (srv) {
+		pgcd = srv->uweight; /* note: cannot be zero */
+		while (pgcd > 1 && (srv = srv->next)) {
+			int w = srv->uweight;
+			while (w) {
+				int t = pgcd % w;
+				pgcd = w;
+				w = t;
+			}
 		}
 	}
 
@@ -283,6 +293,9 @@
 	if (act < bck)
 		act = bck;
 
+	if (!act)
+		act = 1;
+
 	p->lbprm.map.srv = (struct server **)calloc(act, sizeof(struct server *));
 	/* recounts servers and their weights */
 	p->lbprm.map.state = PR_MAP_RECALC;