From owner-freebsd-questions@FreeBSD.ORG Wed Apr 30 17:49:51 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F211B270 for ; Wed, 30 Apr 2014 17:49:51 +0000 (UTC) Received: from mail-out.apple.com (mail-out.apple.com [17.151.62.50]) (using TLSv1 with cipher DES-CBC3-SHA (168/168 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D34981FEC for ; Wed, 30 Apr 2014 17:49:51 +0000 (UTC) MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Received: from mail-out.apple.com by local.mail-out.apple.com (Oracle Communications Messaging Server 7.0.5.30.0 64bit (built Oct 22 2013)) id <0N4U00C00UIW3900@local.mail-out.apple.com> for freebsd-questions@freebsd.org; Wed, 30 Apr 2014 10:49:45 -0700 (PDT) Received: from relay6.apple.com ([17.128.113.90]) by local.mail-out.apple.com (Oracle Communications Messaging Server 7.0.5.30.0 64bit (built Oct 22 2013)) with ESMTP id <0N4U00FADUUHH150@local.mail-out.apple.com>; Wed, 30 Apr 2014 10:49:45 -0700 (PDT) X-AuditID: 1180715a-f79cb6d00000168c-de-536137b9ce7d Received: from [17.149.230.127] (Unknown_Domain [17.149.230.127]) (using TLS with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by relay6.apple.com (Apple SCV relay) with SMTP id 0B.39.05772.9B731635; Wed, 30 Apr 2014 10:49:45 -0700 (PDT) Subject: Re: system(3) && open file descriptors From: Charles Swiger In-reply-to: <20140430044151.GA1668@La-Habana> Date: Wed, 30 Apr 2014 10:49:44 -0700 Content-transfer-encoding: quoted-printable Message-id: References: <20140429184307.GA1114@tiny-r255948> <71BBF914-AA3A-4701-8395-0A5C49474948@mac.com> <20140430044151.GA1668@La-Habana> To: Matthias Apitz X-Mailer: Apple Mail (2.1510) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrALMWRmVeSWpSXmKPExsUiOPVZve5O88Rgg3NzVCxeft3EYnH/8jUW ByaPGZ/ms3gsPTCHOYApissmJTUnsyy1SN8ugSvj2t4jzAX3uSse/bNqYJzJ2cXIySEhYCJx +m8DE4QtJnHh3nq2LkYuDiGBfiaJhY/Ps4AkmAV0JHZuvQOU4ODgFdCT2P5LDiQsLKAv8WVV C1iYTUBNYsJEHpAwJ1DF5tUPWUFsFgFViSsPjrJDTFGU2NG2BmqitsSyha+ZQWxeASuJX3P3 MkKsbWSU+DflPSNIQgSo+fP251C3yUqcPvecZQIj/ywkF81CuGgWkrELGJlXMQoUpeYkVprp JRYU5KTqJefnbmIEhVtDYdQOxoblVocYBTgYlXh4J7AlBguxJpYVV+YeYpTgYFYS4T36LyFY iDclsbIqtSg/vqg0J7X4EKM0B4uSOO/pyNhgIYH0xJLU7NTUgtQimCwTB6dUA2PR//0Cy1cu qvC9fr2Dpyj5jY7Ds/TjDDfS+/fkzT26c/rpO6dSl76W66r/r5jhnnB4n8f0vt6P9pbfuOZs 6NnZqPIt2Dv+6dsoQ9YvC/ObpoQbXlOWkD2s8Gt1h9OdmwnXP/98mx7Bsue9tFN1sfCFuXrf Cx7v/L+Td9mMjQsyD+U0xf4M+hWoxFKckWioxVxUnAgAKFKsszMCAAA= Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Apr 2014 17:49:52 -0000 On Apr 29, 2014, at 9:41 PM, Matthias Apitz wrote: > El d=EDa Tuesday, April 29, 2014 a las 02:41:22PM -0700, Charles = Swiger escribi=F3: >> Hi-- >>=20 >> On Apr 29, 2014, at 11:43 AM, Matthias Apitz = wrote: >>> It seems that the proc started by the C library call system(3), as >>> /bin/sh -c string >>> owns the same set of open file descriptors as its calling proc. Is = this >>> somewhere documented as a feature? 'man system" does not say = anything >>> about, while 'man fork' does. >>=20 >> At least my version of system(3) says that it invokes fork(2) and = checks >> the exit status of the shell via waitpid(2). That plus listing = fork(2) >> in SEE ALSO section seems to be enough of a pointer to the detailed >> behavior.... >=20 > Hi, > Ofc it must use fork(2), but it *could* as well close all fd before > execv(2). IMHO it should do this for all fd > 2, at least the man page > should mention the fact that it does not. Ah, I see your point. Yes, I suspect that folks who intend to pass FDs to children would be = more disciplined about using FD_CLOEXEC and/or doing their own FD cleanup = while calling fork/exec directly. Folks who call system() probably aren't expecting their FDs to be = passed, but I'm not sure it would be safe to change the current behavior by closing FDs for them when it did not do so before. So improving the manpage strikes me as a fine idea.... Regards, --=20 -Chuck