commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r899095 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_exec.h include/acr_memory.h os/win32/exec.c os/win32/main.c os/win32/pipe.c os/win32/subproc.c os/win32/wutil.c test/testsuite.c
Date Thu, 14 Jan 2010 08:07:05 GMT
Author: mturk
Date: Thu Jan 14 08:07:03 2010
New Revision: 899095

URL: http://svn.apache.org/viewvc?rev=899095&view=rev
Log:
Lot's of work to follow for the Subproc.

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_exec.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_memory.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/subproc.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
    commons/sandbox/runtime/trunk/src/main/native/test/testsuite.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=899095&r1=899094&r2=899095&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 Thu Jan 14 08:07:03 2010
@@ -87,6 +87,7 @@
 #define ACR_PROC_HAS_STDERR     0x0004
 #define ACR_PROC_USE_PATH       0x0010
 #define ACR_PROC_DETACHED       0x0100
+#define ACR_PROC_SUBPROC        0x0200
 
 /**
  * Create new executable object structure
@@ -141,6 +142,10 @@
                                  const acr_pchar_t *const *argv,
                                  acr_pchar_t *const *envp);
 
+ACR_DECLARE(int) ACR_ExecSubproc(acr_exec_t *ep, const acr_pchar_t *executable,
+                                 const acr_pchar_t *const *argv,
+                                 acr_pchar_t *const *envp);
+
 /**
  * Get executed program output stream.
  * @param exe The executable object

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_memory.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_memory.h?rev=899095&r1=899094&r2=899095&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_memory.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_memory.h Thu Jan 14 08:07:03
2010
@@ -38,7 +38,7 @@
 #define ACR_EMALLOC(T, S)       ((T *)ACR_Malloc(_E, THROW_FMARK, (S)))
 #define ACR_ECALLOC(T, S)       ((T *)ACR_Calloc(_E, THROW_FMARK, (S)))
 #define ACR_ARRAY_ALLOC(T, N)   ((T *)ACR_Aalloc(_E, THROW_FMARK, (N)))
-
+#define ACR_MEMZERO(T, M, N)    memset((M), 0, sizeof((T)) * (N))
 /**
  * This macros supress exceptions on invalid
  * pointers if it's not needed

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=899095&r1=899094&r2=899095&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 Thu Jan 14 08:07:03 2010
@@ -596,4 +596,3 @@
 
     return rc;
 }
-

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=899095&r1=899094&r2=899095&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Thu Jan 14 08:07:03 2010
@@ -37,7 +37,7 @@
 static DWORD            dll_tls_index = TLS_OUT_OF_INDEXES;
 HANDLE                  dll_heap_handle = NULL;
 HANDLE                  dll_user_token  = NULL;
-
+WCHAR                  *dll_dos_modname = NULL;
 static CRITICAL_SECTION dll_main_lock;
 static SYSTEM_INFO      osinf;
 static OSVERSIONINFOEXA osver;
@@ -105,6 +105,7 @@
             GetModuleFileNameW(instance, mod_file_name, ACR_HBUFF_LEN);
             GetLongPathNameW(mod_file_name, dll_file_name, ACR_SBUFF_LEN);
             GetShortPathNameW(dll_file_name, dos_file_name, ACR_SBUFF_LEN);
+            dll_dos_modname = dos_file_name;
             dll_heap_handle = HeapCreate(0, 0, 0);
             if (!dll_heap_handle) {
                 /* No point to continue if we are missing the process heap */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c?rev=899095&r1=899094&r2=899095&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c Thu Jan 14 08:07:03 2010
@@ -239,51 +239,56 @@
     DWORD    dwOpenMode;
     DWORD    dwPipeMode;
 
-    *rd = NULL;
-    *wr = NULL;
     name = pipe_name_from_pid(buff,
                               GetCurrentProcessId(),
                               ACR_AtomicInc32(&pipe_id));
 
-    dwOpenMode = PIPE_ACCESS_INBOUND;
-    dwPipeMode = 0;
-    if (flags == ACR_PIPE_WRITE_BLOCK ||
-        flags == ACR_PIPE_FULL_NONBLOCK)
-        dwOpenMode |= FILE_FLAG_OVERLAPPED;
-
     sa.nLength              = sizeof(SECURITY_ATTRIBUTES);
     sa.bInheritHandle       = FALSE;
     sa.lpSecurityDescriptor = NULL;
 
-    *rd = CreateNamedPipeW(name,
-                           dwOpenMode,
-                           dwPipeMode,
-                           1,
-                           0,
-                           65536,
-                           1,
-                           &sa);
-    if (IS_INVALID_HANDLE(*rd))
-        return ACR_GET_OS_ERROR();
-    dwOpenMode = FILE_ATTRIBUTE_NORMAL;
-    if (flags == ACR_PIPE_READ_BLOCK ||
-        flags == ACR_PIPE_FULL_NONBLOCK)
-        dwOpenMode |= FILE_FLAG_OVERLAPPED;
-    *wr = CreateFileW(name,
-                      GENERIC_WRITE,
-                      0,
-                      &sa,
-                      OPEN_EXISTING,
-                      dwOpenMode,
-                      NULL);
-    if (IS_INVALID_HANDLE(*wr)) {
-        rc = ACR_GET_OS_ERROR();
-        CloseHandle(*rd);
-        *rd = NULL;
-        return rc;
+    if (rd) {
+        dwOpenMode = PIPE_ACCESS_INBOUND;
+        dwPipeMode = 0;
+        if (flags == ACR_PIPE_WRITE_BLOCK ||
+            flags == ACR_PIPE_FULL_NONBLOCK)
+            dwOpenMode |= FILE_FLAG_OVERLAPPED;
+
+        *rd = CreateNamedPipeW(name,
+                               dwOpenMode,
+                               dwPipeMode,
+                               1,
+                               0,
+                               65536,
+                               1,
+                               &sa);
+        if (IS_INVALID_HANDLE(*rd))
+            return ACR_GET_OS_ERROR();
+    }
+    if (wr) {
+        dwOpenMode = FILE_ATTRIBUTE_NORMAL;
+        if (flags == ACR_PIPE_READ_BLOCK ||
+            flags == ACR_PIPE_FULL_NONBLOCK)
+            dwOpenMode |= FILE_FLAG_OVERLAPPED;
+        *wr = CreateFileW(name,
+                          GENERIC_WRITE,
+                          0,
+                          &sa,
+                          OPEN_EXISTING,
+                          dwOpenMode,
+                          NULL);
+        if (IS_INVALID_HANDLE(*wr)) {
+            rc = ACR_GET_OS_ERROR();
+            if (rd) {
+                SAFE_CLOSE_HANDLE(*rd);
+            }
+            return rc;
+        }
     }
-    if (pname)
+    if (pname) {
+        /* Return the unique pipe name */
         *pname = x_wcsdup(name);
+    }
     return 0;
 }
 

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=899095&r1=899094&r2=899095&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 Thu Jan 14 08:07:03 2010
@@ -107,10 +107,11 @@
     const wchar_t  *pi_name = NULL;
     const wchar_t  *po_name = NULL;
     const wchar_t  *pe_name = NULL;
-    HANDLE ppipe[3] = { NULL, NULL, NULL };
-    HANDLE pipes[6] = { NULL, NULL, NULL, NULL,  NULL, NULL };
-    HANDLE waith[6] = { NULL, NULL, NULL, NULL,  NULL, NULL };
+    HANDLE ppipe[3];
+    HANDLE pipes[6];
+    HANDLE waith[6];
     DWORD  waitn    = 0;
+    DWORD  dwChildTimeout;
     OVERLAPPED_BUFFER ob[3];
     char pstdinb[PROC_BUFFER_SIZE];
     DWORD dwCreationFlags = CREATE_UNICODE_ENVIRONMENT | CREATE_SUSPENDED;
@@ -142,7 +143,13 @@
         rc = ACR_EINVAL;
         goto cleanup;
     }
-    memset(&child, 0, sizeof(acr_exec_t));
+
+    ACR_MEMZERO(HANDLE, ppipe, 3);
+    ACR_MEMZERO(HANDLE, pipes, 6);
+    ACR_MEMZERO(HANDLE, waith, 6);
+    ACR_MEMZERO(OVERLAPPED_BUFFER, ob, 3);
+
+    ACR_MEMZERO(acr_exec_t, &child, 1);
     child.pid = -1;
 
     for (i = 2; i < argc; i++) {
@@ -219,8 +226,7 @@
     memset(&si, 0, sizeof(si));
     si.cb = sizeof(si);
 
-    for (i = 0; i < 3; i++)
-        memset(&ob[i], 0, sizeof(OVERLAPPED_BUFFER));
+    dwChildTimeout = child.limit.timeout > 0 ? PROC_TIMEOUT_STEP : INFINITE;
 
     /* Sanity check.
      * Daemons have no stream pipes
@@ -243,6 +249,8 @@
                            NULL, ACR_PIPE_READ_BLOCK)))
             goto cleanup;
         /* Open the handle to the parent stdin
+         * TODO: We need to create the named pipe here so that
+         *       our parent can connect to us.
          */
         ppipe[0] = CreateFileW(pi_name,
                                GENERIC_READ,
@@ -267,7 +275,7 @@
         /* Open the handle to the parent stdout
          */
         ppipe[1] = CreateFileW(po_name,
-                               GENERIC_WRITE,
+                               GENERIC_WRITE | FILE_READ_ATTRIBUTES,
                                0,
                                &sa,
                                OPEN_EXISTING,
@@ -394,7 +402,6 @@
     /* Sink the console pipes and wait until the child terminates.
      */
     do {
-        DWORD dwTimeout = child.limit.timeout > 0 ? PROC_TIMEOUT_STEP : INFINITE;
         DWORD ws;
         /* Do some blocking read from the parent
          */
@@ -417,7 +424,7 @@
          * because their events are set on signaled. This usualy means that
          * the first ReadFile/WriteFile will fail with ERROR_IO_PENDING.
          */
-        ws = ACR_WaitForMultipleObjectOrSignal(waitn, waith, dwTimeout);
+        ws = ACR_WaitForMultipleObjectOrSignal(waitn, waith, dwChildTimeout);
         switch (ws) {
             case WAIT_ACRSIGNAL_0:
                 /* Signal event is set.

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c?rev=899095&r1=899094&r2=899095&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c Thu Jan 14 08:07:03 2010
@@ -41,7 +41,7 @@
     va_end(ap);
     if (file) {
         const char *fn = ACR_FilePathNameGet(file);
-        snprintf(fmt, ACR_HBUFF_LEN, "[%6d] (%-10s @%4d) %s",
+        snprintf(fmt, ACR_HBUFF_LEN, "[%-6d %-10s %4d] %s",
                       GetCurrentProcessId(), fn, line, buf);
         bp = fmt;
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=899095&r1=899094&r2=899095&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Thu Jan 14 08:07:03 2010
@@ -677,6 +677,27 @@
     return 0;
 }
 
+static int test_exec5(int argc, const char *const argv[])
+{
+    int rc;
+    acr_exec_t *exe;
+    if (argc < 1) {
+        return ACR_EINVAL;
+    }
+    exe = ACR_ExecNew(ACR_PROC_HAS_STDOUT | ACR_PROC_HAS_STDERR);
+#if defined(WIN32)
+    rc = ACR_ExecSubproc(exe, wargv[0], &wargv[1], NULL);
+#else
+    rc = ACR_ExecSubproc(exe, argv[0], &argv[1], NULL);
+#endif
+    fprintf(stdout, "[STDOUT]:\n%s", ACR_ExecStream(exe, 1));
+    fprintf(stdout, "[STDERR]:\n%s", ACR_ExecStream(exe, 2));
+    fprintf(stdout, "\n[EXITWHY]: %d\n[EXITVAL]: %d\n[EXITPID]: %d\n",
+            exe->exitwhy, exe->exitval, exe->pid);
+    ACR_ExecFree(exe);
+    return 0;
+}
+
 #if defined(WIN32)
 static int test_registry(int argc, const char *const argv[])
 {
@@ -817,6 +838,9 @@
         else if (!strcasecmp(run_test, "daemon")) {
             rv = test_exec4(argc, argv);
         }
+        else if (!strcasecmp(run_test, "subproc")) {
+            rv = test_exec5(argc, argv);
+        }
 #if defined(WIN32)
         else if (!strcasecmp(run_test, "registry")) {
             rv = test_registry(argc, argv);



Mime
View raw message