masqmail

diff src/child.c @ 391:0ca270ca11fa

Refactoring and code layouting.
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 17:53:04 +0100
parents b27f66555ba8
children 885e3d886199
line diff
     1.1 --- a/src/child.c	Sat Feb 18 13:50:02 2012 +0100
     1.2 +++ b/src/child.c	Sat Feb 18 17:53:04 2012 +0100
     1.3 @@ -39,9 +39,11 @@
     1.4  		pid_t pid;
     1.5  
     1.6  		pid = fork();
     1.7 -		if (pid == 0) {
     1.8 +		if (pid == -1) {
     1.9 +			return -1;
    1.10 +		} else if (pid == 0) {
    1.11 +			/* child */
    1.12  			int i, max_fd = sysconf(_SC_OPEN_MAX);
    1.13 -			/* child */
    1.14  			dup2(pipe[0], 0);
    1.15  			dup2(pipe[0], 1);
    1.16  			dup2(pipe[0], 2);
    1.17 @@ -52,14 +54,15 @@
    1.18  				close(i);
    1.19  
    1.20  			{
    1.21 -				char *argv[] = { "/bin/sh", "-c", (char *) command, NULL };
    1.22 +				char *argv[] = { "/bin/sh", "-c",
    1.23 +						(char *) command, NULL };
    1.24  				execve(*argv, argv, NULL);
    1.25  			}
    1.26 -			logwrite(LOG_ALERT, "execve failed: %s\n", strerror(errno));
    1.27 +			logwrite(LOG_ALERT, "execve failed: %s\n",
    1.28 +					strerror(errno));
    1.29  			_exit(1);
    1.30 -		} else if (pid == -1) {
    1.31 -			return -1;
    1.32  		} else {
    1.33 +			/* parent */
    1.34  			close(pipe[0]);
    1.35  			return pipe[1];
    1.36  		}