12-17-04 12:45 AM
Hi,
I think this should be simple. I thaink I have done something similar
a long time ago but the magic is hiding from me.
I have a system log file that grows and is rotated once a month. I
need to read the whole log file once then "hang" on the bottom of the
file waiting for more input.
Eventually the file will be rotated. I want to have read every spec of
data in the now old log; close it and then open the new log and start
from the top.
I figured that setting up a select() then doing the read() would work.
However, the select is not blocking at all. My test file is zero
length in this test. I open the file, do the select and it returnes
immediately saying that the descriptor on that zero length file is
ready for reading... huh?
I then read zero bytes form the file and repeat... forever.
I assumed that the select would block on the zero length file until
something was sent to it.
I am FD_ZEROing, FD_SETing and reseting the time struct before each
select call
while (1)
{
FD_ZERO (&read_FDs);
FD_SET (file_no, &read_FDs);
select_timeout.tv_sec = 60; /* 1 minute, why not? */
select_timeout.tv_usec = 0;
if ((select_result = select ((file_no + 1), &read_FDs,
NULL, NULL, &select_timeout)) > 0)
{
if (FD_ISSET (WTMP_file_no, &read_FDs))
{
if ((read_result = read (file_no, &wtmp,
size_of_buf)) > 0)
{
...process read...
}
else if (read_result == 0)
{
/*
* read zero bytes on what should have been a
* prepared stream.
*/
}
else
{
exit (__LINE__);
}
}
else
{
/*
* select says there is pending data but the FD is not
* set. what gives?
*/
exit (__LINE__);
}
}
else if (select_result == -1)
{
exit (__LINE__);
}
}
I am opening the file read-only
file_no = open (file, O_CREAT | O_RDONLY, 0664)
Obviously I am missing something in the select() man page. What am I
missing?
Dean...K...
[ Post a follow-up to this message ]
|