[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

life span of file descriptors?



Hi,

to learn a little bit about system calls I tried to hack some
kind of monitoring system. Each system call of a user should
be logged in some log file.

I added a system call to activate monitoring of a specific user.
In the correspending service routine I opened a file (mode
O_CREAT | O_APPEND) and store the file descriptor in some table.

Now, every time a system call is executed a log message is
appended to this file. To do this I hacked the 
 execute_syscall()
function.

This works now fine for the first time a system call is executed.
But after the 2nd time the stored file descriptor seems
to be invalid. A write request (with sys_write()) always returns 
the errorcode -9 (i.e. EBADF).

If I changed the execute_syscall to 
- open the file, 
- write the message, 
- and close the file
everything works fine.

But my guess is that opening and closing a file is quite expensive
and the first approach would be preferrable.

So the question is: Why can't I write more than once to the
same file descriptor in the kernel from different system calls?

Any ideas?

(I used the UML system for the implementation and I did not try
this on a "real" kernel.)

-- Torsten
begin:vcard 
n:Fink;Torsten
tel;fax:+49-30-83875109
tel;home:+49-177-7438287
tel;work:+49-30-83875113
x-mozilla-html:FALSE
url:http://www.inf.fu-berlin.de/~tnfink/
org:Freie Universität Berlin;Institut für Informatik
adr:;;Takustr.9;Berlin;;14195;Germany
version:2.1
email;internet:tnfink@inf.fu-berlin.de
x-mozilla-cpt:;-24640
fn:Torsten Fink
end:vcard