From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 13 15:27:13 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 94BEF16A400 for ; Wed, 13 Jun 2007 15:27:13 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout3.cac.washington.edu (mxout3.cac.washington.edu [140.142.32.166]) by mx1.freebsd.org (Postfix) with ESMTP id 72AB213C48A for ; Wed, 13 Jun 2007 15:27:13 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.32.141] (may be forged)) by mxout3.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.05) with ESMTP id l5DFQc17012476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Jun 2007 08:26:38 -0700 X-Auth-Received: from [192.168.10.45] (c-24-10-12-194.hsd1.ca.comcast.net [24.10.12.194]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l5DFQbqg016282 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 13 Jun 2007 08:26:38 -0700 Message-ID: <46700CAE.6020902@u.washington.edu> Date: Wed, 13 Jun 2007 08:26:38 -0700 From: Garrett Cooper User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: Danny Braniss References: <466F86C6.7010006@u.washington.edu> <20070613123213.GE98927@bunrab.catwhisker.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.3.1.294258, Antispam-Engine: 2.5.1.298604, Antispam-Data: 2007.6.13.80333 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' Cc: hackers@freebsd.org, David Wolfskill Subject: Re: Using shell commands versus C equivalents X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2007 15:27:13 -0000 Danny Braniss wrote: >> --Rgf3q3z9SdmXC6oT >> Content-Type: text/plain; charset=us-ascii >> Content-Disposition: inline >> Content-Transfer-Encoding: quoted-printable >> >> On Tue, Jun 12, 2007 at 10:55:18PM -0700, Garrett Cooper wrote: >> >>> Another simple question (I hope): >>> Is there any reason why shell commands should be used in place of a=20 >>> C command (in this case chmod via vsystem instead of the chmod(2)=20 >>> function)? It seems like the fork / exec would be more expensive with=20 >>> the shell command, but any area where code could be optimized is more=20 >>> than welcome I would think. >>> >> There often are reasons to prefer using shell commands to C. >> >> There typically exist many tradeoffs involved in evaluating one over the >> other, and "machine efficiency" is not always the highest goal. (For >> example, it may be better to reduce complexity in favor of having a >> simpler structure that is easier for people to understand and maintain >> with confidence that the changes they make have the desired results. >> This is, of course, not to try to claim that shell scripts are >> inherently easier to understand than C code; that would be a silly >> stance to take.) >> >> I commend to your attention Geoff Collyer and Henry Spencer's "C News" >> (a successor to Rick Adams' "B News") implementation, a great deal of >> which was written as shell scripts (ca. 1988 or so). >> >> (Yes, I realize that that was almost 20 years ago, and that it >> didn't involve FreeBSD per se. Ignoring the lessons of history is >> rather short-sighted and foolish: despite using shell scripts for >> so much of the "code," the machine I was then running went from >> being extremely busy all the time to having a couple of bursts of >> activity per day for about an hour each time -- with more news >> flowing with C News vs. B News.) >> >> > > read the question again, though it is not absolutely clear/correct, the question > was: > chmod(path, mode) > vs > system("chmod ...") > > and not wheather to write a program or a shell script. > > danny > > > Sorry -- actually I meant that (along similar lines), there was a program with the following lines: vsystem("/bin/chmod +x %s", filename); and I replaced it with: chmod(filename, (mode_t) ( S_IXUSR | S_IXGRP | S_IXOTH )); Probably won't yield much gain overall, but every drop counts and there are quite a few iterations performed in the pkg_* programs, in particular dealing with X.org. Next step, eliminating the linked list structure in favor or red-black trees, maybe. -Garrett