Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 14B249E93 for ; Tue, 22 Nov 2011 09:24:00 +0000 (UTC) Received: (qmail 1276 invoked by uid 500); 22 Nov 2011 09:23:59 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 1236 invoked by uid 500); 22 Nov 2011 09:23:59 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 1228 invoked by uid 99); 22 Nov 2011 09:23:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Nov 2011 09:23:59 +0000 X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [195.4.92.94] (HELO mout4.freenet.de) (195.4.92.94) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Nov 2011 09:23:51 +0000 Received: from [195.4.92.142] (helo=mjail2.freenet.de) by mout4.freenet.de with esmtpa (ID mypop@freenet.de) (port 25) (Exim 4.76 #5) id 1RSmZe-0002pL-Dd for modules-dev@httpd.apache.org; Tue, 22 Nov 2011 10:23:30 +0100 Received: from localhost ([::1]:46442 helo=mjail2.freenet.de) by mjail2.freenet.de with esmtpa (ID mypop@freenet.de) (Exim 4.76 #1) id 1RSmZe-0008SB-9y for modules-dev@httpd.apache.org; Tue, 22 Nov 2011 10:23:30 +0100 Received: from [195.4.92.25] (port=52716 helo=15.mx.freenet.de) by mjail2.freenet.de with esmtpa (ID mypop@freenet.de) (Exim 4.76 #1) id 1RSmWs-0006T5-Uo for modules-dev@httpd.apache.org; Tue, 22 Nov 2011 10:20:38 +0100 Received: from radzewitz.freenet-ag.de ([62.104.227.65]:34670) by 15.mx.freenet.de with esmtpsa (ID mypop@freenet.de) (TLSv1:CAMELLIA256-SHA:256) (port 25) (Exim 4.76 #1) id 1RSmWs-0000d0-Q3 for modules-dev@httpd.apache.org; Tue, 22 Nov 2011 10:20:38 +0100 Subject: Re: child init/ exit and the apr_cleanup_register From: michaelr To: modules-dev@httpd.apache.org In-Reply-To: References: <1321949985.6470.3.camel@radzewitz.freenet-ag.de> Content-Type: text/plain; charset="UTF-8" Date: Tue, 22 Nov 2011 10:20:37 +0100 Message-ID: <1321953637.15268.7.camel@radzewitz.freenet-ag.de> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Content-Transfer-Encoding: 7bit Hi Sorin, thank's for your explanation. Eyerything work fine when i register the cleanup in the way you suggested. apr_pool_cleanup_register(p, NULL, child_exit, apr_pool_cleanup_null); That saved my day. Greetings Michael On Tue, 2011-11-22 at 10:02 +0100, Sorin Manolache wrote: > On Tue, Nov 22, 2011 at 09:19, michaelr wrote: > > Hello again, > > > > maybe another stupid question but i could not found any > > example in the modules dir of the httpd source. > > > > Let's say i have an child_init_function which opens a > > filehandle. This filehandle should be open until the child > > ends. > > > > In mod_example.c they register an cleanup function to call a > > function on child exit. > > > > static apr_status_t child_exit ( void *data ) > > { > > //close file handle... > > > > return OK; > > } > > > > static void child_init ( apr_pool_t *p, server_rec *s ) > > { > > //open file handle... > > > > apr_pool_cleanup_register(p, s, NULL, child_exit) ; > > } > > > > I understand the cleanup as a function which runs on pool_cleanup. > > This could happend on any time which i can't control - right? > > > > When i return an HTTP_INTERNAL_SERVER_ERROR in my handler function > > as an example the cleanup get's called also but the child is still > > alive. The filehandle is closed and on the next request i run into > > some kind of trouble. > > > The cleanup callback should not be called when you finish processing a > request. It should be called only when the child exits. > > Register the cleanup function as follows: > > apr_pool_cleanup_register(p, NULL, child_exit, apr_pool_cleanup_null); > > The third argument (child_exit) is invoked when the pool is destroyed. > The 4th (apr_pool_cleanup_null) is invoked when subpools of p are > destroyed. > > You can pass the file handle in the second argument (where I've put > NULL). Then it will show up as the data argument in child_exit. > > > S > > > > > Is there a way to define a 'real' exit function or can i force child > > shutdown in above example? What's the right way to do it correctly? > > > > Thanks a lot and greetings > > Michael > > > > > > > > > >