System calls

System calls

Post by Ken Luthe » Tue, 12 Feb 2002 06:40:22



Hello,

Is it considered bad programming to use system calls in your "c" code???

thanks,

 
 
 

System calls

Post by Michael Lee Yoh » Wed, 13 Feb 2002 06:43:57


Quote:> Is it considered bad programming to use system calls in your "c" code???

You mean calls to the system() function?  It's a matter of opinion, but
personally I find the system() call dirty in most cases.  If you're just
trying to retrieve a return value from a program it's a perfect little
function.

Otherwise, calls to exec() [and its family of functions] is probably
better, if not cleaner.  *shrug*

--


Software Developer, Engineering Services
Red Hat, Inc.

http://people.redhat.com/myohe/

QUIPd 1.02: (199 of 711)
-> (Moving on up, eh?) Linux accounted for 27 percent of new
-> worldwide operating-system licenses in 2000, and Microsoft
-> captured 41 percent of new licenses.
-> - IDC

 
 
 

System calls

Post by Spark » Sun, 17 Feb 2002 14:26:04


Hmmmm,

Never thought of exec(), et al.

I'll see if that will accomplish the same thing,

thanks,
Ken
.
.
....Ken

 
 
 

System calls

Post by hira » Sun, 17 Feb 2002 20:01:12



> Hmmmm,

> Never thought of exec(), et al.

> I'll see if that will accomplish the same thing,

> thanks,
> Ken
> .
> .
> ....Ken

most of the time it's better to NOT use system calls as they're
slower.  Only time most would ever use them is when buffered i/o is
not wanted (for networking, etc).  BTW, michael: what do mean that
exec() will do the same this as a system call??  In what context?  I'm
lost... :)
 
 
 

System calls

Post by Floyd Davidso » Mon, 18 Feb 2002 00:04:08




>> Hmmmm,

>> Never thought of exec(), et al.

>> I'll see if that will accomplish the same thing,

>> thanks,
>> Ken
>> .
>> .
>> ....Ken

>most of the time it's better to NOT use system calls as they're
>slower.  Only time most would ever use them is when buffered i/o is
>not wanted (for networking, etc).

Using things like system("clear") is great.  How slow it is
makes no difference, and it requires 20 lines of code to do it
correctly otherwise.  Other examples would be calling grep if
the output is necessarily going to a file, or using popen() on
grep if the output is not to a file.

The critical differences are that speed is not important, the
size of the code to reproduce the functionality is significant,
and security is not impaired.

Quote:>  BTW, michael: what do mean that
>exec() will do the same this as a system call??  In what context?  I'm
>lost... :)

In the context of security issues, a fork() and an exec() are
exactly what system() does, except system() is a generic example
which may not provide sufficient protection.  In that case
directly doing the same fork() and exec() calls, with more
appropriate support, accomplishes the same effect as a call to
system().

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>

 
 
 

System calls

Post by John Hasle » Mon, 18 Feb 2002 01:46:39


Quote:Floyd Davidson writes:
> In the context of security issues, a fork() and an exec() are exactly
> what system() does,...

However, what system(string) does a fork() and exec() on is 'sh -c string'.
--
John Hasler

Dancing Horse Hill
Elmwood, WI
 
 
 

System calls

Post by Floyd Davidso » Mon, 18 Feb 2002 02:55:55



>Floyd Davidson writes:
>> In the context of security issues, a fork() and an exec() are exactly
>> what system() does,...

>However, what system(string) does a fork() and exec() on is 'sh -c string'.

And that is exactly part of the security risk in using system().

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>