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
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to