Language/C&C++
[Linux][C/C++] 'select' function - glibc bug??
yhcting
2010. 11. 19. 18:04
Following test is done with "Ubuntu EGLIBC 2.12.1-0ubuntu9"
Based on my simple test, 'select' function is poor to validate file descriptor.
In my test, select doesn't return error (-1) even for file descriptor 99999. Some times process is crashed - segment fault.
So, file descriptor should be validated before calling 'select'.
(I think I need to look into more about this. These are based on just test. So I'm not 100% sure about this.)
There is lot's of way. Here is well-known way.
is_valid_fd(int fd) { fcntl(fd, F_GETFL) != -1 || errno != EBADF; }
Summay. Be careful using 'select'!