Author: mturk
Date: Mon Jan 18 13:02:44 2010
New Revision: 900380

URL: http://svn.apache.org/viewvc?rev=900380&view=rev
Log:
Add option to redirect stderr to null and just have stdout

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_exec.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/subproc.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_exec.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_exec.h?rev=900380&r1=900379&r2=900380&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_exec.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_exec.h Mon Jan 18 
13:02:44 2010
@@ -85,6 +85,7 @@
 #define ACR_PROC_HAS_STDIN      0x0001
 #define ACR_PROC_HAS_STDOUT     0x0002
 #define ACR_PROC_HAS_STDERR     0x0004
+#define ACR_PROC_OUTPUT_COMBINE 0x000A
 #define ACR_PROC_USE_PATH       0x0010
 #define ACR_PROC_DETACHED       0x0100
 #define ACR_PROC_SUBPROC        0x0200

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c?rev=900380&r1=900379&r2=900380&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c Mon Jan 18 
13:02:44 2010
@@ -278,8 +278,13 @@
             rc = ACR_GET_OS_ERROR();
             goto child_cleanup;
         }
-        if (pipes[PIPE_STDERR_WRS] == -1)
-            rc = dup2(pipes[PIPE_STDOUT_WRS], STDERR_FILENO);
+        if (pipes[PIPE_STDERR_WRS] == -1) {
+            if (!(ep->flags & ACR_PROC_HAS_STDOUT) ||
+                ((ep->flags & ACR_PROC_OUTPUT_COMBINE) == 
ACR_PROC_OUTPUT_COMBINE))
+                rc = dup2(pipes[PIPE_STDOUT_WRS], STDERR_FILENO);
+            else
+                rc = nullpipe(O_WRONLY, STDERR_FILENO);
+        }
         else
             rc = dup2(pipes[PIPE_STDERR_WRS], STDERR_FILENO);
         if (rc == -1) {

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c?rev=900380&r1=900379&r2=900380&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c Mon Jan 18 
13:02:44 2010
@@ -160,7 +160,7 @@
     DWORD  dwTimeout = INFINITE;
     OVERLAPPED_SBUFF overlap[3];
     DWORD  dwCreationFlags = CREATE_UNICODE_ENVIRONMENT | CREATE_SUSPENDED;
-    DWORD  dwPipeFlags;
+    DWORD  dwDuplicate;
     const char *inpp = NULL;
     wchar_t    *args = NULL;
     wchar_t    *envb = NULL;
@@ -234,31 +234,39 @@
             goto cleanup;
     }
     else {
-        /* Use same pipes for stderr and stdout
-         */
-        pipes[PIPE_STDERR_WRS] = pipes[PIPE_STDOUT_WRS];
+        if (!(ep->flags & ACR_PROC_HAS_STDOUT) ||
+            ((ep->flags & ACR_PROC_OUTPUT_COMBINE) == 
ACR_PROC_OUTPUT_COMBINE)) {
+            /* Use same pipes for stderr and stdout
+             */
+            pipes[PIPE_STDERR_WRS] = pipes[PIPE_STDOUT_WRS];
+        }
+        else
+            pipes[PIPE_STDERR_WRS] = nullpipe(GENERIC_WRITE, NULL);
     }
     /* Always use STDHANDLES
      * They are either real handles or handles to NUL device
      */
     si.dwFlags |= STARTF_USESTDHANDLES;
-    dwPipeFlags = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
-    if (!DuplicateHandle(cp, pipes[PIPE_STDINP_RDS], cp, 
&pipes[PIPE_STDINP_RDS],
-                         0, TRUE, dwPipeFlags)) {
+    dwDuplicate = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
+    if (!DuplicateHandle(cp,  pipes[PIPE_STDINP_RDS],
+                         cp, &pipes[PIPE_STDINP_RDS],
+                         0, TRUE, dwDuplicate)) {
         rc = ACR_GET_OS_ERROR();
         goto cleanup;
     }
-    dwPipeFlags = DUPLICATE_SAME_ACCESS;
-    if (ep->flags & ACR_PROC_HAS_STDERR)
-        dwPipeFlags |= DUPLICATE_CLOSE_SOURCE;
-    if (!DuplicateHandle(cp, pipes[PIPE_STDOUT_WRS], cp, 
&pipes[PIPE_STDOUT_WRS],
-                         0, TRUE, dwPipeFlags)) {
+    dwDuplicate = DUPLICATE_SAME_ACCESS;
+    if (pipes[PIPE_STDERR_WRS] != pipes[PIPE_STDOUT_WRS])
+        dwDuplicate |= DUPLICATE_CLOSE_SOURCE;
+    if (!DuplicateHandle(cp,  pipes[PIPE_STDOUT_WRS],
+                         cp, &pipes[PIPE_STDOUT_WRS],
+                         0, TRUE, dwDuplicate)) {
         rc = ACR_GET_OS_ERROR();
         goto cleanup;
     }
-    dwPipeFlags = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
-    if (!DuplicateHandle(cp, pipes[PIPE_STDERR_WRS], cp, 
&pipes[PIPE_STDERR_WRS],
-                         0, TRUE, dwPipeFlags)) {
+    dwDuplicate = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
+    if (!DuplicateHandle(cp,  pipes[PIPE_STDERR_WRS],
+                         cp, &pipes[PIPE_STDERR_WRS],
+                         0, TRUE, dwDuplicate)) {
         rc = ACR_GET_OS_ERROR();
         goto cleanup;
     }
@@ -638,3 +646,4 @@
 
     return rc;
 }
+

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/subproc.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/subproc.c?rev=900380&r1=900379&r2=900380&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/subproc.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/subproc.c Mon Jan 18 
13:02:44 2010
@@ -120,7 +120,7 @@
     OVERLAPPED_SBUFF overlap[3];
     char pstdinb[ACR_SBUFF_SIZ];
     DWORD dwCreationFlags = CREATE_UNICODE_ENVIRONMENT | CREATE_SUSPENDED | 
DETACHED_PROCESS;
-    DWORD dwPipeFlags;
+    DWORD dwDuplicate;
     acr_exec_t child;
     acr_time_t endat = 0;
 
@@ -199,24 +199,32 @@
                     if (opt) {
                         wcslcpy(pi_name, pfx, sizeof(pi_name));
                         wcslcat(pi_name, opt, sizeof(pi_name));
+                        child.flags |= ACR_PROC_HAS_STDIN;
                     }
-                    child.flags |= ACR_PROC_HAS_STDIN;
                 break;
                 case L'O':
                     /* Where the child stdout should be redirected */
                     if (opt) {
                         wcslcpy(po_name, pfx, sizeof(po_name));
                         wcslcat(po_name, opt, sizeof(po_name));
+                        child.flags |= ACR_PROC_HAS_STDOUT;
+                    }
+                break;
+                case L'C':
+                    /* Where the child stdout should be redirected */
+                    if (opt) {
+                        wcslcpy(po_name, pfx, sizeof(po_name));
+                        wcslcat(po_name, opt, sizeof(po_name));
+                        child.flags |= ACR_PROC_OUTPUT_COMBINE;
                     }
-                    child.flags |= ACR_PROC_HAS_STDOUT;
                 break;
                 case L'E':
                     /* Where the child stderr should be redirected */
                     if (opt) {
                         wcslcpy(pe_name, pfx, sizeof(pe_name));
                         wcslcat(pe_name, opt, sizeof(pe_name));
+                        child.flags |= ACR_PROC_HAS_STDERR;
                     }
-                    child.flags |= ACR_PROC_HAS_STDERR;
                 break;
                 case L'D':
                     /* Detached process */
@@ -344,32 +352,37 @@
         }
     }
     else {
-        /* Use same pipes for stderr and stdout
-         */
-        pipes[PIPE_STDERR_WRS] = pipes[PIPE_STDOUT_WRS];
+        if (!(child.flags & ACR_PROC_HAS_STDOUT) ||
+            ((child.flags & ACR_PROC_OUTPUT_COMBINE) == 
ACR_PROC_OUTPUT_COMBINE)) {
+            /* Use same pipes for stderr and stdout
+             */
+            pipes[PIPE_STDERR_WRS] = pipes[PIPE_STDOUT_WRS];
+        }
+        else
+            pipes[PIPE_STDERR_WRS] = nullpipe(GENERIC_WRITE, NULL);
     }
 
     /* Always use STDHANDLES
      * They are either real handles or handles to NUL device
      */
     si.dwFlags |= STARTF_USESTDHANDLES;
-    dwPipeFlags = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
+    dwDuplicate = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
     if (!DuplicateHandle(cp, pipes[PIPE_STDINP_RDS], cp, 
&pipes[PIPE_STDINP_RDS],
-                         0, TRUE, dwPipeFlags)) {
+                         0, TRUE, dwDuplicate)) {
         rc = ACR_GET_OS_ERROR();
         goto cleanup;
     }
-    dwPipeFlags = DUPLICATE_SAME_ACCESS;
-    if (child.flags & ACR_PROC_HAS_STDERR)
-        dwPipeFlags |= DUPLICATE_CLOSE_SOURCE;
+    dwDuplicate = DUPLICATE_SAME_ACCESS;
+    if (pipes[PIPE_STDERR_WRS] != pipes[PIPE_STDOUT_WRS])
+        dwDuplicate |= DUPLICATE_CLOSE_SOURCE;
     if (!DuplicateHandle(cp, pipes[PIPE_STDOUT_WRS], cp, 
&pipes[PIPE_STDOUT_WRS],
-                         0, TRUE, dwPipeFlags)) {
+                         0, TRUE, dwDuplicate)) {
         rc = ACR_GET_OS_ERROR();
         goto cleanup;
     }
-    dwPipeFlags = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
+    dwDuplicate = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
     if (!DuplicateHandle(cp, pipes[PIPE_STDERR_WRS], cp, 
&pipes[PIPE_STDERR_WRS],
-                         0, TRUE, dwPipeFlags)) {
+                         0, TRUE, dwDuplicate)) {
         rc = ACR_GET_OS_ERROR();
         goto cleanup;
     }
@@ -1192,3 +1205,4 @@
 
     return rc;
 }
+


Reply via email to