Return-Path: Delivered-To: apmail-httpd-dev-archive@www.apache.org Received: (qmail 64881 invoked from network); 11 Dec 2007 13:37:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Dec 2007 13:37:55 -0000 Received: (qmail 79188 invoked by uid 500); 11 Dec 2007 13:37:37 -0000 Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 79124 invoked by uid 500); 11 Dec 2007 13:37:37 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 79113 invoked by uid 99); 11 Dec 2007 13:37:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Dec 2007 05:37:37 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of michael@metaparadigm.com designates 203.117.131.43 as permitted sender) Received: from [203.117.131.43] (HELO metamail-vm.metaparadigm.com) (203.117.131.43) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Dec 2007 13:37:39 +0000 Received: from [192.168.133.111] (cm15.gamma103.maxonline.com.sg [202.156.103.15]) (authenticated bits=0) by metamail-vm.metaparadigm.com (8.13.8/8.13.8/Debian-3) with ESMTP id lBBDbF8i027101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 11 Dec 2007 21:37:16 +0800 Message-ID: <475E9286.1080504@metaparadigm.com> Date: Tue, 11 Dec 2007 21:37:10 +0800 From: Michael Clark Organization: Metaparadigm Pte Ltd User-Agent: Mozilla-Thunderbird 2.0.0.6 (X11/20071009) MIME-Version: 1.0 To: dev@httpd.apache.org Subject: apr_os_dir_put doesn't create working apr_dir_t Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV 0.90.1/5090/Tue Dec 11 18:08:19 2007 on metamail-vm X-Virus-Status: Clean X-Virus-Checked: Checked by ClamAV on apache.org apr_os_dir_put doesn't create a working apr_dir_t i.e. apr_dir_read will not work on the created apr_dir_t This is not the case with apr_os_file_put which does in fact create a working apr_file_t Is this a bug or a feature? There doesn't seem to be any users of apr_os_dir_put in the httpd tree. Here is an example from my privilege separated wrapper functions for apr file io: The apr_file_open wrapper is quite simple as the apr_os_file_put works as expected: static apr_status_t privsep_file_open(privsep_token_t *token, apr_file_t **new, const char *fname, apr_int32_t flag, apr_fileperms_t perm, apr_pool_t *pool) { privsep_message_t msg; apr_os_file_t fd; if(!privsep_inited || !token) return apr_file_open(new, fname, flag, perm, pool); memset(&msg, 0, sizeof(msg)); msg.command = privsep_command_file_open; msg.flags = flag; msg.perms = perm; fd = privsep_send_request(&msg, token, fname); if (msg.retval != APR_SUCCESS) return msg.retval; return apr_os_file_put(new, &fd, flag, pool); } But I have to resort to ugly hacks in my apr_dir_open implementation: static apr_status_t privsep_dir_open(privsep_token_t *token, apr_dir_t **new, const char *dirname, apr_pool_t *pool) { privsep_message_t msg; apr_os_file_t fd; DIR *dir; if(!privsep_inited || !token) return apr_dir_open(new, dirname, pool); memset(&msg, 0, sizeof(msg)); msg.command = privsep_command_dir_open; fd = privsep_send_request(&msg, token, dirname); if (msg.retval != APR_SUCCESS) return msg.retval; /* apr_os_dir_put does not create a fullly allocated apr_dir_t so we need to open a directory to create one then replace the fd in the associated apr_os_dir */ if(apr_dir_open(new, "/", pool) != APR_SUCCESS) { close(fd); return APR_EGENERAL; } /* Ok, now the nasty bit: Here we assume that an integer file descriptor is the first element of the opaque DIR structure pointed at by dir This is the case on Linux, FreeBSD, Mac OS X and Solaris */ apr_os_dir_get(&dir, *new); close(*(int *)dir); *(int *)dir = fd; (*new)->dirname = apr_pstrdup(pool, dirname); return apr_os_dir_put(new, dir, pool); }