lkml.org 
[lkml]   [1999]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectselect() clobbering the timeout
I recently came across something strange on one Linux server: select()
calls that time out suddenly started clobbering the timeout value with
garbage.

This is a UP P-II running kernel 2.0.35, with an uptime of 254 days.
It's also a production server, and it's otherwise running fine. The
weird behavior only started 5 days ago, and we only noticed it because
it made zsh appear to hang.

Now it's predictable: a test program shows that select() clobbers the
timeout value everytime the timeout expires, but not when it returns
early (because of input or a singal). I've single-stepped through the
disassembly of select() in libc, and it appears clearly that the
clobbering must happen in the kernel itself. I can't reproduce it on
any other kernel, but then again, that 2.0.35 took 8 months to start
doing it.

I'm posting this not to ask for a fix, but just in case someone gets
inspired to look at it, or can quickly say "that got fixed in 2.0.36" or
whatever ...

Here's some test code:

#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>

void catchasignal() { }

int main(int argc, char **argv) {
struct timeval tv;
fd_set s;

signal(SIGINT, catchasignal);
tv.tv_sec = atoi(argv[1]);
tv.tv_usec = atoi(argv[2]);
FD_ZERO(&s);
FD_SET(0, &s);
printf("tv_sec = %ld, tv_usec = %ld\n", (long)tv.tv_sec, (long)tv.tv_usec);
select(1, &s, NULL, NULL, &tv);
printf("tv_sec = %ld, tv_usec = %ld\n", (long)tv.tv_sec, (long)tv.tv_usec);
return 0;
}

and its output on the misbehaving kernel:

$ ./mintest 0 1000
tv_sec = 0, tv_usec = 1000
tv_sec = 20936492, tv_usec = 650000
$ ./mintest 1 0
tv_sec = 1, tv_usec = 0
tv_sec = 20936484, tv_usec = 550000
$ ./mintest 2 0
tv_sec = 2, tv_usec = 0
^C
tv_sec = 1, tv_usec = 570000

--
Roger Espel Llima, espel@llaic.u-clermont1.fr
http://www.eleves.ens.fr:8080/home/espel/index.html

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.415 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site