configure_network: mysystem: use vfork

This commit is contained in:
satbaby
2012-06-18 16:58:51 +02:00
parent 7d8d995046
commit aff97b7c18

View File

@@ -217,24 +217,26 @@ void CNetworkConfig::commitConfig(void)
int mysystem(char * cmd, char * arg1, char * arg2) int mysystem(char * cmd, char * arg1, char * arg2)
{ {
int pid, i; int i;
switch (pid = fork()) pid_t pid;
{ int maxfd = getdtablesize();// sysconf(_SC_OPEN_MAX);
case -1: /* can't fork */ switch (pid = vfork())
perror("fork"); {
return -1; case -1: /* can't fork */
perror("vfork");
return -1;
case 0: /* child process */ case 0: /* child process */
for(i = 3; i < 256; i++) for(i = 3; i < maxfd; i++)
close(i); close(i);
if(execlp(cmd, cmd, arg1, arg2, NULL)) if(execlp(cmd, cmd, arg1, arg2, NULL))
{ {
perror("exec"); perror("exec");
} }
exit(0); exit(0);
default: /* parent returns to calling process */ default: /* parent returns to calling process */
break; break;
} }
waitpid(pid, 0, 0); waitpid(pid, 0, 0);
return 0; return 0;
} }