masqmail

diff src/child.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children 98cda87105a7
line diff
     1.1 --- a/src/child.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/child.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -4,7 +4,7 @@
     1.4   * it under the terms of the GNU General Public License as published by
     1.5   * the Free Software Foundation; either version 2 of the License, or
     1.6   * (at your option) any later version.
     1.7 - * 
     1.8 + *
     1.9   * This program is distributed in the hope that it will be useful,
    1.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.12 @@ -29,51 +29,51 @@
    1.13  
    1.14  int volatile sigchild_seen = 0;
    1.15  
    1.16 -static
    1.17 -void sigchild_handler(int sig)
    1.18 +static void
    1.19 +sigchild_handler(int sig)
    1.20  {
    1.21 -  sigchild_seen = 1;
    1.22 -  signal(SIGHUP, sigchild_handler);
    1.23 +	sigchild_seen = 1;
    1.24 +	signal(SIGHUP, sigchild_handler);
    1.25  }
    1.26  
    1.27 -int child(const char *command)
    1.28 +int
    1.29 +child(const char *command)
    1.30  {
    1.31 -  int pipe[2];
    1.32 +	int pipe[2];
    1.33  
    1.34 -  if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe) == 0){
    1.35 -    pid_t pid;
    1.36 -      
    1.37 -    /*
    1.38 -    sigchild_seen = 0;
    1.39 -    signal(SIGCHLD, sigchild_handler);
    1.40 -    */
    1.41 +	if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe) == 0) {
    1.42 +		pid_t pid;
    1.43  
    1.44 -    pid = fork();
    1.45 -    if(pid == 0){
    1.46 -      int i, max_fd = sysconf(_SC_OPEN_MAX);
    1.47 -      /* child */
    1.48 -      dup2(pipe[0], 0);
    1.49 -      dup2(pipe[0], 1);
    1.50 -      dup2(pipe[0], 2);
    1.51 +		/*
    1.52 +		   sigchild_seen = 0;
    1.53 +		   signal(SIGCHLD, sigchild_handler);
    1.54 +		 */
    1.55  
    1.56 -      if(max_fd <= 0) max_fd = 64;
    1.57 -      for(i = 3; i < max_fd; i++)
    1.58 -	close(i);
    1.59 +		pid = fork();
    1.60 +		if (pid == 0) {
    1.61 +			int i, max_fd = sysconf(_SC_OPEN_MAX);
    1.62 +			/* child */
    1.63 +			dup2(pipe[0], 0);
    1.64 +			dup2(pipe[0], 1);
    1.65 +			dup2(pipe[0], 2);
    1.66  
    1.67 -      {
    1.68 -	char *argv [] = { "/bin/sh", "-c", (char*) command, NULL };
    1.69 -	execve (*argv, argv, NULL);
    1.70 -      }
    1.71 -      logwrite(LOG_ALERT, "execve failed: %s\n", strerror(errno));
    1.72 -      _exit(EXIT_FAILURE);
    1.73 -    }else if(pid == -1){
    1.74 -      return -1;
    1.75 -    }else{
    1.76 -      close(pipe[0]);
    1.77 -      return pipe[1];
    1.78 -    }
    1.79 -  }
    1.80 -  return -2;
    1.81 +			if (max_fd <= 0)
    1.82 +				max_fd = 64;
    1.83 +			for (i = 3; i < max_fd; i++)
    1.84 +				close(i);
    1.85 +
    1.86 +			{
    1.87 +				char *argv[] = { "/bin/sh", "-c", (char *) command, NULL };
    1.88 +				execve(*argv, argv, NULL);
    1.89 +			}
    1.90 +			logwrite(LOG_ALERT, "execve failed: %s\n", strerror(errno));
    1.91 +			_exit(EXIT_FAILURE);
    1.92 +		} else if (pid == -1) {
    1.93 +			return -1;
    1.94 +		} else {
    1.95 +			close(pipe[0]);
    1.96 +			return pipe[1];
    1.97 +		}
    1.98 +	}
    1.99 +	return -2;
   1.100  }
   1.101 -
   1.102 -