Date: Wed, 13 Jun 2007 11:15:52 -0500 From: "Rick C. Petty" <rick-freebsd@kiwi-computer.com> To: Garrett Cooper <youshi10@u.washington.edu> Cc: hackers@freebsd.org Subject: Re: Using shell commands versus C equivalents Message-ID: <20070613161552.GA83292@keira.kiwi-computer.com> In-Reply-To: <46700CAE.6020902@u.washington.edu> References: <466F86C6.7010006@u.washington.edu> <20070613123213.GE98927@bunrab.catwhisker.org> <E1HySxb-000PIg-89@cs1.cs.huji.ac.il> <46700CAE.6020902@u.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jun 13, 2007 at 08:26:38AM -0700, Garrett Cooper wrote: > > vsystem("/bin/chmod +x %s", filename); > > and I replaced it with: > > chmod(filename, (mode_t) ( S_IXUSR | S_IXGRP | S_IXOTH )); Another improvement made by using stat(2)/chmod(2) over chmod(1) using system(3) variants is the protection against malicious filenames. The original code should have used fork/execv instead anyway. But yeah, saving the fork, time to load and execute the shell, and parse and perform the chmod is probably worth the effort to use the syscalls directly from C, especially if this operation happens often enough. I agree with the other poster(s) who said that if it prevents complex code, it might be worth it. Your case isn't complex enough to warrant the spawning of a shell process, especially when one of your primary goals is to reduce total runtime. -- Rick C. Petty
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070613161552.GA83292>