[PATCH][1/4] poll()/select() timeout behavior
From: Bill Rugolsky Jr.
Date:  Fri Feb 20 2004 - 16:07:38 EST
This patch extends the useful range of the poll() timeout parameter
from a mere 2147s (LONG_MAX/(1000*HZ)) to 2147483s (LONG_MAX/1000).
Please apply.
	Bill Rugolsky
--- linux/fs/select.c	2004-02-03 22:43:06.000000000 -0500
+++ linux/fs/select.c	2004-02-19 14:29:03.827275000 -0500
@@ -469,11 +469,17 @@
 		return -EINVAL;
 
 	if (timeout) {
-		/* Careful about overflow in the intermediate values */
-		if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
-			timeout = (unsigned long)(timeout*HZ+999)/1000+1;
-		else /* Negative or overflow */
+                if (timeout < 0) {
 			timeout = MAX_SCHEDULE_TIMEOUT;
+		} else { 
+			/* Careful about overflow in the intermediate values */
+			long seconds = timeout/1000;
+			timeout = ((timeout - 1000*seconds)*HZ + 999)/1000 + 1;
+			if (seconds <= (MAX_SCHEDULE_TIMEOUT-2) / HZ - 1)
+				timeout += seconds*HZ;
+			else
+				timeout = MAX_SCHEDULE_TIMEOUT;
+		}
 	}
 
 	poll_initwait(&table);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/