execute.c
changeset 9 9acd8ae3190c
parent 8 03339adb7014
child 18 af4898956964
--- a/execute.c	Fri Mar 23 08:37:45 2007 +0100
+++ b/execute.c	Fri Mar 23 14:34:16 2007 +0100
@@ -1,18 +1,28 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <signal.h>
 
+#include "msg.h"
 #include "main.h"
 
+static void program_signal();
+
 static void run_parent()
 {
     int status;
     wait(&status);
-    printf("End of child\n");
 };
 
 static void run_child(const char *command)
 {
+    int p[2];
+    /* Closing input */
+    pipe(&p);
+    close(p[1]); /* closing the write handle */
+    close(0);
+
+    dup(p[0]); /* the pipe reading goes to stdin */
     execlp("bash", "bash", "-c", command, NULL);
 }
 
@@ -22,9 +32,13 @@
 
     pid = fork();
 
+    /* For the parent */
+    /*program_signal(); Still not needed*/
+
     switch(pid)
     {
         case 0:
+            close(server_socket);
             run_child(command);
             break;
         case -1:
@@ -36,3 +50,20 @@
             break;
     }
 }
+
+static void sigchld_handler(int val)
+{
+}
+
+static void program_signal()
+{
+  struct sigaction act;
+
+  act.sa_handler = sigchld_handler;
+  /* Reset the mask */
+  memset(&act.sa_mask,0,sizeof(act.sa_mask));
+  act.sa_flags = SA_NOCLDSTOP;
+  act.sa_restorer = NULL;
+
+  sigaction(SIGCHLD, &act, NULL);
+}