lkml.org 
[lkml]   [2006]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: Quick close of all the open files.
Date
Valdis.Kletnieks@vt.edu writes:

> On Wed, 07 Jun 2006 03:15:43 +0530, vamsi krishna said:
>> Hello,
>>
>> I found that the following code is closing all the open files by the
>> program, do you think its a bug in kernel code?
>>
>> ------------
>> fp = tmpfile();
>> fp->_chain = stderr;
>> fpclose(fp);
>> fp = NULL;
>
> strace that, and see how many times close() gets called. If it gets
> called once, it's a kernel bug. If it gets called once for each open
> file, it's a userspace bug.

Actually, it's not a bug at all.

> For bonus points, how did you verify that all the open files were closed?
>
> (Hint - what does that fp->_chain = stderr *really* do? ;)

As it touches the innards of the FILE type, it invokes undefined
behavior. Nothing that follows can be considered a bug.

--
Måns Rullgård
mru@inprovide.com

-
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: 2006-06-07 00:06    [from the cache]
©2003-2011 Jasper Spaans