Index: main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.cpp	(revision 22174)
+++ main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.cpp	(revision 22177)
@@ -41,15 +41,4 @@
 #include "os_process_unix.h"
 
-#define READ_PIPE_INDEX 0
-#define WRITE_PIPE_INDEX 1
-
-#define FD_STDIN 0
-#define FD_STDOUT 1
-#define FD_STDERR 2
-
-osprocessunix::osprocessunix(char* cmdline)
-  : osprocess(cmdline)
-{}
-
 osprocessunix::osprocessunix(char* cmdline, OSProcessPipeMode mode)
   : child_stdout_read_(-1), child_stdin_write_(-1),
@@ -81,16 +70,17 @@
 
   
-  pid_t pid = fork();
-  if (pid < 0) {
+  pid_ = fork();
+  if (pid_ < 0) {
     cerr << "osprocessunix::osprocessunix(): Failed to create child process" << endl; 
     return;
   }
 
-  if (pid == 0) {
+  if (pid_ == 0) {
     // Child process
 
     // Sort out input pipe
     //   child has no buisness accessing write end of input pipe => close
-    ::close(child_stdin_write_);   
+    ::close(child_stdin_write_); 
+    child_stdin_write_=-1;
 
     if ((mode == uniWrite) || (mode == biReadWrite)) {
@@ -99,6 +89,6 @@
     }
     else {
-      // noPipe or (parent is doing) uniRead (which means we're not interested
-      // in the child reading any input from the parent)
+      // Parent is doing uniRead, which means we're not interested
+      // in the child reading any input from the parent
       // => child input remains coming from stdin
       ::close(child_stdin_read);
@@ -108,4 +98,6 @@
     //   child has no buisness accessing read end of output pipe => close
     ::close(child_stdout_read_);
+    child_stdout_read_=-1;
+
     if ((mode == uniRead) || (mode == biReadWrite)) {
       //   wire up child's stdout write so it is send down the pipe to the parent
@@ -113,26 +105,15 @@
     }
     else {
-      // noPipe or (parent is doing) uniWrite (which means we're not interested
-      // in any output produced by the child process)
+      // Parent is doing uniWrite, which means we're not interested
+      // in any output produced by the child process
       // => child output remains going to stdout
       ::close(child_stdout_write);
     }
 
-    /*
-    // execve ...
-    int rv = CreateProcess(NULL,    // no application name
-			   cmdline, 
-			   NULL, 
-			   NULL,    // no process or thread security attribues 
-			   TRUE,    // Inherit handles
-			   0,       // Creation flag
-			   NULL,    // No environment block
-			   ".",     // current working directory
-			   &si, 
-			   &pi_);    // process info filled out as a result
-    if (!rv) {
-      fprintf(stderr,"os_process_windows(): Error creating process");
-    }
-    */
+    
+    // execvp?
+    cerr << "Away to execve: " << cmdline << endl;
+
+    execve(cmdline, NULL, NULL);
 
     
@@ -154,7 +135,9 @@
       case uniRead:
 	::close(child_stdin_write_);
+	child_stdin_write_ = -1;
 	break;
       case uniWrite:
 	::close(child_stdout_read_);
+	child_stdout_read_ = -1;
 	break;
       case biReadWrite:
@@ -162,8 +145,4 @@
 	// the pipes are set up just the way we want them
 	break;
-      case noPipe:
-	::close(child_stdin_write_);
-	::close(child_stdout_read_);
-	break;
     }
   }
@@ -171,13 +150,9 @@
 
 osprocessunix::~osprocessunix()
-{}
-
-/*  
-bool osprocessunix::eop()
-{}
-
-bool osprocessunix::eop(OSProcessPipeMode)
-{}
-*/
+{
+  // close any file handles that are still open
+  close();
+}
+
 
 int osprocessunix::write(char* buffer, const int buffer_len)
@@ -206,13 +181,38 @@
 
   
-bool osprocessunix::close()
-{
-  return true;
-}
-
-bool osprocessunix::close(OSProcessPipeMode mode)
-{
-  return true;
-}
+bool osprocessunix::close_write_pipe(OSProcessWarnStatus warn_status)
+{
+  int write_close_rv = 0;
+
+  if (child_stdin_write_ != -1) {
+    write_close_rv = ::close(child_stdin_write_);
+    child_stdin_write_ = -1;
+  }
+  else if (warn_status = withWarning) {
+    cerr << "osprocessunix::close_write_pipe(): Warning - Tried to close already closed pipe" << endl;
+  }
+
+  return (write_close_rv==0);
+}
+
+
+bool osprocessunix::close_read_pipe(OSProcessWarnStatus warn_status)
+{
+  int read_close_rv = 0;
+
+
+  if (child_stdout_read_ != -1) {
+    read_close_rv = ::close(child_stdout_read_);
+    child_stdout_read_ = -1;
+  }
+  else if (warn_status == withWarning) {
+    cerr << "osprocessunix::close_read_pipe(): Warning - Tried to close already closed pipe" << endl;
+  }
+
+  return (read_close_rv==0);
+}
+
+
+
 
 
