--- deliantra/server/common/porting.C 2006/09/10 16:00:23 1.5 +++ deliantra/server/common/porting.C 2006/09/12 23:22:32 1.6 @@ -1,7 +1,7 @@ /* * static char *rcsid_porting_c = - * "$Id: porting.C,v 1.5 2006/09/10 16:00:23 root Exp $"; + * "$Id: porting.C,v 1.6 2006/09/12 23:22:32 root Exp $"; */ /* @@ -180,46 +180,41 @@ FILE *ret; if (!strcmp (type, "r")) - { - pd = STDOUT_FILENO; - } + pd = STDOUT_FILENO; else if (!strcmp (type, "w")) - { - pd = STDIN_FILENO; - } + pd = STDIN_FILENO; else - { - return NULL; - } + return NULL; + if (pipe (fd) != -1) { switch (fork ()) { - case -1: - close (fd[0]); - close (fd[1]); - break; - case 0: - close (fd[0]); - if ((fd[1] == pd) || (dup2 (fd[1], pd) == pd)) - { - if (fd[1] != pd) - { - close (fd[1]); - } - execl ("/bin/sh", "sh", "-c", command, NULL); - close (pd); - } - exit (1); - break; - default: - close (fd[1]); - if (ret = fdopen (fd[0], type)) - { - return ret; - } - close (fd[0]); - break; + case -1: + close (fd[0]); + close (fd[1]); + break; + case 0: + close (fd[0]); + if ((fd[1] == pd) || (dup2 (fd[1], pd) == pd)) + { + if (fd[1] != pd) + { + close (fd[1]); + } + execl ("/bin/sh", "sh", "-c", command, NULL); + close (pd); + } + _exit (1); + break; + default: + close (fd[1]); + if (ret = fdopen (fd[0], type)) + { + return ret; + } + close (fd[0]); + break; } } return NULL; @@ -232,8 +227,6 @@ * String related function ****************************************************************************/ - - /* * A replacement of strdup(), since it's not defined at some * unix variants.