From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id CBE29BC69 for ; Sat, 15 Sep 2007 16:11:30 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEqF60bAXQImlWdsb2JhbACBV4w7AQEBAQcKDxg X-IronPort-AV: E=Sophos;i="4.20,258,1186351200"; d="scan'208";a="817759" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 15 Sep 2007 16:12:12 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l8FEBmWf016250 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sat, 15 Sep 2007 16:11:48 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAEqF60bVhW6V/2dsb2JhbACBVw X-IronPort-AV: E=Sophos;i="4.20,258,1186351200"; d="scan'208";a="2741557" Received: from server2.thinkcrime.de ([213.133.110.149]) by mail3-smtp-sop.national.inria.fr with ESMTP; 15 Sep 2007 16:12:12 +0200 Received: from hod-sarge-2005-10.lan.m-e-leypold.de (dslb-088-072-195-133.pools.arcor-ip.net [88.72.195.133]) (Authenticated sender: hod-sarge-2005-10@server2) by server2.thinkcrime.de (Postfix) with ESMTP id 674D9900245 for ; Sat, 15 Sep 2007 16:12:01 +0200 (CEST) Received: by hod-sarge-2005-10.lan.m-e-leypold.de (Postfix, from userid 1003) id DAE0937962; Sat, 15 Sep 2007 16:16:39 +0200 (CEST) To: caml-list@inria.fr Subject: Re: [Caml-list] Closing all open file descriptors References: <006b01c7f699$275fd6d0$017ca8c0@countertenor> <200709141000.l8EA04x12648@virtutech.se> <1189806728.46eb0288d38b8@webmail.in-berlin.de> <1189847741.46eba2bd9d121@webmail.in-berlin.de> <20070915192631.2384ae5a.mle+ocaml@mega-nerd.com> <1189852990.46ebb73e7edc3@webmail.in-berlin.de> From: Markus E L Organization: N/A Date: Sat, 15 Sep 2007 16:16:39 +0200 In-Reply-To: <1189852990.46ebb73e7edc3@webmail.in-berlin.de> (Oliver Bandel's message of "Sat, 15 Sep 2007 12:43:10 +0200") Message-ID: <5fps0k9fp4.fsf@hod.lan.m-e-leypold.de> User-Agent: Some cool user agent (SCUG) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at discorde with ID 46EBE824.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; descriptors:01 markus:01 bandel:01 ocaml:01 bandel:01 descriptors:01 fcntl:01 markus:01 wrote:01 wrote:01 oliver:01 oliver:01 caml-list:01 inherit:01 inherit:01 Oliver Bandel wrote: > Zitat von Erik de Castro Lopo : > >> Oliver Bandel wrote: >> >> > If you think you need all this for your daemon, >> > I ask: why do you think you need it? If you write it, you have >> > full control over all files you open >> >> No, thats not right. I can write a program, that opens a bunch >> of file descriptors, and then exec his program and his program >> will inherit all open file descritors. > > Yes, that's correct. > But you (as the programmer) have the control (by design) > about how to handle that case. Let's assume (as an example) I'm starting a demon / background process by clicking on an icon in a desktop environment. Which file descriptors are open when the demon starts executing? Would I be expected to patch the desktop to ensure that they aren't? Or will I have to rely on a rather undocumented bit of the desktop software's behaviour (perhaps subject to change) to guarantee my demons security. This sucks on so many levels. My position is, if there is something you inherit or can create in your process there must also be a way to browse/index/enumerate what you inherited/created. So, yes, there should be a enumerate_my_open_descriptors() even in POSIX. If it it isn't it has to be reinvented in a platform specific way on every platfrom where this is possible (e.g. under Linux using /proc/self/fd), to get a better programming environment. > If you have all your open descriptors in a list, > you can close them after a fork. And if you inherit them unkknowingly, you're lost. > In C, with fcntl, there is a possibility to close files > on an exec automatically with the close-on-exec flag. This is aboout what a parent does whom one possibly doesn't control. Regards -- Markus