Author: mturk Date: Fri Jan 15 15:46:24 2010 New Revision: 899672 URL: http://svn.apache.org/viewvc?rev=899672&view=rev Log: Add null pipe api
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c?rev=899672&r1=899671&r2=899672&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c Fri Jan 15 15:46:24 2010 @@ -293,6 +293,37 @@ return rc; } +static int create_nulpipe(JNIEnv *_E, acr_file_t **fd, int flags) +{ + int rc = 0; + int pd; + int mode = flags == ACR_PIPE_READ_BLOCK ? O_RDONLY : O_WRONLY; + + pd = nullpipe(mode, NULL); + if (pd == -1) + return ACR_GET_OS_ERROR(); + /* We have two handles created. + * Create wrapper objects and events + */ + *fd = ACR_TCALLOC(acr_file_t, 1); + if (!*fd) { + rc = ACR_ENOMEM; + goto finally; + } + (*fd)->fd = hp; + (*fd)->name = ACR_strdup(_dev_null); + (*fd)->flags = flags; + (*fd)->type = ACR_FT_PIPE; + (*fd)->blocking = BLK_ON; + (*fd)->timeout = -1; + + return 0; + +finally: + CloseHandle(hp); + return rc; +} + static int do_popen(JNIEnv *_E, acr_file_t *fp, int flags, jobject *fdo) { @@ -331,11 +362,11 @@ ACR_THROW_IO_IF_ERR(rc); return NULL; } - rc = do_popen(_E, pd[0], flags & ACR_PIPE_RD, &fd[0]); + rc = do_popen(_E, pd[0], &fd[0]); if (rc) { goto finally; } - rc = do_popen(_E, pd[1], flags & ACR_PIPE_WR, &fd[1]); + rc = do_popen(_E, pd[1], &fd[1]); if (rc) { ACR_DescriptorCleanup(_E, fd[0]); goto finally; @@ -347,6 +378,31 @@ return NULL; } +ACR_IO_EXPORT_DECLARE(jobject, Pipe, null0)(ACR_JNISTDARGS, + jint flags) +{ + int rc = 0; + jobject fd; + acr_file_t *pd = NULL; + + if ((rc = create_nulpipe(_E, &pd, flags))) { + ACR_THROW_IO_IF_ERR(rc); + return NULL; + } + rc = do_popen(_E, pd, &fd); + if (rc) { + goto finally; + } + if (flags & ACR_PIPE_READ_BLOCK) + return ACR_NewPipeObject(_E, flags, fd, NULL, pd->name); + else + return ACR_NewPipeObject(_E, flags, NULL, fd, pd->name); + +finally: + ACR_THROW_IO_IF_ERR(rc); + return NULL; +} + ACR_IO_EXPORT_DECLARE(jboolean, Pipe, blocking0)(ACR_JNISTDARGS, jint pipe) { 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=899672&r1=899671&r2=899672&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 Fri Jan 15 15:46:24 2010 @@ -328,7 +328,7 @@ L"SeCreateSymbolicLinkPrivilege", L"SeDebugPrivilege", L"SeTakeOwnershipPrivilege", - L"SeTcbPrivilege", + L"SeTcbPrivilege", /* Requires 'Act as part of the operating system' user right */ NULL }; 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=899672&r1=899671&r2=899672&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 Fri Jan 15 15:46:24 2010 @@ -346,19 +346,48 @@ return 0; finally: - if (IS_VALID_HANDLE(hr)) - CloseHandle(hr); - if (IS_VALID_HANDLE(hw)) - CloseHandle(hw); + SAFE_CLOSE_HANDLE(hr); + SAFE_CLOSE_HANDLE(hw); if (*rd) { - if ((*rd)->overlap.hEvent) - CloseHandle((*rd)->overlap.hEvent); + SAFE_CLOSE_HANDLE((*rd)->overlap.hEvent); x_free(*rd); } x_free(name); return rc; } +static int create_nulpipe(JNIEnv *_E, acr_file_t **fd, int flags) +{ + int rc = 0; + HANDLE hp = NULL; + wchar_t *name = NULL; + int mode = flags == ACR_PIPE_READ_BLOCK ? GENERIC_READ : GENERIC_WRITE; + + hp = nullpipe(mode, NULL); + if (IS_INVALID_HANDLE(hp)) + return ACR_GET_OS_ERROR(); + /* We have two handles created. + * Create wrapper objects and events + */ + *fd = ACR_TCALLOC(acr_file_t, 1); + if (!*fd) { + rc = ACR_ENOMEM; + goto finally; + } + (*fd)->fd = hp; + (*fd)->name = ACR_wcsdup(L"NUL"); + (*fd)->flags = flags; + (*fd)->type = ACR_FT_PIPE; + (*fd)->blocking = BLK_ON; + (*fd)->timeout = -1; + + return 0; + +finally: + CloseHandle(hp); + return rc; +} + static int file_cleanup(void *file, int type, unsigned int flags) { int rc = ACR_EBADF; @@ -437,8 +466,7 @@ return rc; } -static int do_popen(JNIEnv *_E, acr_file_t *fp, int flags, - jobject *fdo) +static int do_popen(JNIEnv *_E, acr_file_t *fp, jobject *fdo) { int rc = 0; int fo; @@ -491,11 +519,11 @@ ACR_THROW_IO_IF_ERR(rc); return NULL; } - rc = do_popen(_E, pd[0], flags & ACR_PIPE_RD, &fd[0]); + rc = do_popen(_E, pd[0], &fd[0]); if (rc) { goto finally; } - rc = do_popen(_E, pd[1], flags & ACR_PIPE_WR, &fd[1]); + rc = do_popen(_E, pd[1], &fd[1]); if (rc) { ACR_DescriptorCleanup(_E, fd[0]); goto finally; @@ -507,6 +535,31 @@ return NULL; } +ACR_IO_EXPORT_DECLARE(jobject, Pipe, null0)(ACR_JNISTDARGS, + jint flags) +{ + int rc = 0; + jobject fd; + acr_file_t *pd = NULL; + + if ((rc = create_nulpipe(_E, &pd, flags))) { + ACR_THROW_IO_IF_ERR(rc); + return NULL; + } + rc = do_popen(_E, pd, &fd); + if (rc) { + goto finally; + } + if (flags & ACR_PIPE_READ_BLOCK) + return ACR_NewPipeObject(_E, flags, fd, NULL, pd->name); + else + return ACR_NewPipeObject(_E, flags, NULL, fd, pd->name); + +finally: + ACR_THROW_IO_IF_ERR(rc); + return NULL; +} + ACR_IO_EXPORT_DECLARE(jboolean, Pipe, blocking0)(ACR_JNISTDARGS, jint pipe) {