Re: Quick close of all the open files.

From: linux-os (Dick Johnson)
Date: Wed Jun 07 2006 - 07:31:49 EST



On Tue, 6 Jun 2006, vamsi krishna wrote:

> 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;
> ------------
>
> o Is there any other elegant way to close all the open files (rather
> than reading from /proc/<pid>/fd and calling close on each of the fd?)
>
> Looking forward to hear from you.
>
> Thank you,
> Vamsi.
> -

tmpfile() returns a pointer to the FILE type. FILE is an opaque
type, meaning you have no business accessing any of its contents.
In fact, there are no user accessible headers from which you
could properly determine the contents of this type. Your program
should not even know that it is a structure. In fact, it could
be a pointer to a linked list.

Anything you think you are seeing, any behavior you think exists,
is invalidated once you access any members of this structure.

If you want to close all open buffered files (streams), you use
fcloseall().

Also, the FILE type and any buffering is performed by the 'C'
runtime library. The kernel only does open/read/write/close,
the underlying primitives. If you find anything wrong with
FILE operations, you should contact the people who provided
your 'C' runtime library, not the Linux kernel group.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.4 on an i686 machine (5592.88 BogoMips).
New book: http://www.AbominableFirebug.com/
_


****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@xxxxxxxxxxxx - and destroy all copies of this information, including any attachments, without reading or disclosing them.

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