changeset 391:0ca270ca11fa

Refactoring and code layouting.
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 17:53:04 +0100
parents 68ae9182059c
children c5fd796ea06e
files src/child.c
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/child.c	Sat Feb 18 13:50:02 2012 +0100
+++ b/src/child.c	Sat Feb 18 17:53:04 2012 +0100
@@ -39,9 +39,11 @@
 		pid_t pid;
 
 		pid = fork();
-		if (pid == 0) {
+		if (pid == -1) {
+			return -1;
+		} else if (pid == 0) {
+			/* child */
 			int i, max_fd = sysconf(_SC_OPEN_MAX);
-			/* child */
 			dup2(pipe[0], 0);
 			dup2(pipe[0], 1);
 			dup2(pipe[0], 2);
@@ -52,14 +54,15 @@
 				close(i);
 
 			{
-				char *argv[] = { "/bin/sh", "-c", (char *) command, NULL };
+				char *argv[] = { "/bin/sh", "-c",
+						(char *) command, NULL };
 				execve(*argv, argv, NULL);
 			}
-			logwrite(LOG_ALERT, "execve failed: %s\n", strerror(errno));
+			logwrite(LOG_ALERT, "execve failed: %s\n",
+					strerror(errno));
 			_exit(1);
-		} else if (pid == -1) {
-			return -1;
 		} else {
+			/* parent */
 			close(pipe[0]);
 			return pipe[1];
 		}