lkml.org 
[lkml]   [2004]   [Mar]   [3]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateWed, 3 Mar 2004 09:46:54 +0100 (MET)
FromArmin Schindler <>
Subject[PATCH 2.4] sys_select() return error on bad file
Hi,

the following patch now returns -EBADF in sys_select()/do_select()
if all specified file-descriptors are bad (e.g. were closed by another
thread).

Without this patch, the for-loop in do_select() won't stop if there are no
valid files any more. It stops only if a specified timeout occured or a
signal arrived.

If there are no objections on this patch, I would also create a patch for
kernel 2.6 and the poll() code. I didn't have a closer look at this yet.

Armin

--- linux/fs/select.c_orig	2004-03-02 19:06:44.000000000 +0100
+++ linux/fs/select.c	2004-03-03 09:25:24.000000000 +0100
@@ -183,6 +183,8 @@
 		wait = NULL;
 	retval = 0;
 	for (;;) {
+		int file_err = 1;
+
 		set_current_state(TASK_INTERRUPTIBLE);
 		for (i = 0 ; i < n; i++) {
 			unsigned long bit = BIT(i);
@@ -199,6 +201,7 @@
 						  i /*  The fd*/,
 						  __timeout,
 						  NULL);
+				file_err = 0;
 				mask = DEFAULT_POLLMASK;
 				if (file->f_op && file->f_op->poll)
 					mask = file->f_op->poll(file, wait);
@@ -227,6 +230,10 @@
 			retval = table.error;
 			break;
 		}
+		if (file_err) {
+			retval = -EBADF;
+			break;
+		}
 		__timeout = schedule_timeout(__timeout);
 	}
 	current->state = TASK_RUNNING;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:01    [from the cache]
©2003-2008