|
From: Alberto G. I. <ag...@ag...> - 2003-02-10 10:35:53
|
On Sun, Feb 09, 2003 at 08:01:12PM -0500, Aaron Sethman wrote:
>
> Here is a simple little replacement for system() that does close file
> descriptors. The main issue with it is though, it ends up picking an
> arbitrary number of fds to close. I picked closing 0 to 99.
>
> Aaron
>
>
> int s_system(const char *string)
> {
> pid_t pid;
> int x;
> pid = fork()
>
> if(pid == -1)
> {
> return -1;
> }
>
> if(pid > 0)
> {
> int status;
> wait(&status);
> return(status);
> }
>
> for(x = 0; x < 100; x++)
> {
> close(x);
> }
> execlp("/bin/sh", "-c", string);
>
> }
>
Hi,
Again, I'm no C hacker, but I think this should be better:
for(x = 3; x < 100; x++)
Since the first 3 fds (stdin, stdout and stderr) should be kept open.
Regards,
Alberto
--
Alberto Gonzalez Iniesta | They that give up essential liberty
agi@(agi.as|debian.org) | to obtain a little temporary safety
Encrypted mail preferred | deserve neither liberty nor safety.
Key fingerprint = 9782 04E7 2B75 405C F5E9 0C81 C514 AF8E 4BA4 01C3
|