Author: mturk Date: Mon Jan 11 11:20:21 2010 New Revision: 897838 URL: http://svn.apache.org/viewvc?rev=897838&view=rev Log: Add sbuf init
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_sbuf.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/shared/sbuf.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_sbuf.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_sbuf.h?rev=897838&r1=897837&r2=897838&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_sbuf.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_sbuf.h Mon Jan 11 11:20:21 2010 @@ -87,6 +87,7 @@ acr_sbuf_t *acr_sbuf_new(acr_sbuf_t *, char *, size_t, int); #define acr_sbuf_new_auto() \ acr_sbuf_new(NULL, NULL, 0, ACR_SBUF_AUTOEXTEND) +int acr_sbuf_init(acr_sbuf_t *, char *, size_t); void acr_sbuf_clear(acr_sbuf_t *); int acr_sbuf_setpos(acr_sbuf_t *, size_t); int acr_sbuf_bcat(acr_sbuf_t *, const void *, size_t); @@ -110,6 +111,7 @@ acr_wbuf_t *acr_wbuf_new(acr_wbuf_t *, wchar_t *, size_t, int); #define acr_wbuf_new_auto() \ acr_wbuf_new(NULL, NULL, 0, ACR_SBUF_AUTOEXTEND) +int acr_wbuf_init(acr_wbuf_t *, wchar_t *, size_t); void acr_wbuf_clear(acr_wbuf_t *); int acr_wbuf_setpos(acr_wbuf_t *, size_t); int acr_wbuf_bcat(acr_wbuf_t *, const void *, size_t); 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=897838&r1=897837&r2=897838&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 11 11:20:21 2010 @@ -70,18 +70,12 @@ ep->flags = flags; if (flags & ACR_PROC_HAS_STDOUT) { - if (!acr_sbuf_new(&ep->sout, NULL, PROC_BUFFER_SIZE, - ACR_SBUF_AUTOEXTEND)) { - rc = ACR_GET_OS_ERROR(); + if ((rc = acr_sbuf_init(&ep->sout, NULL, PROC_BUFFER_SIZE))) goto cleanup; - } } if (flags & ACR_PROC_HAS_STDERR) { - if (!acr_sbuf_new(&ep->serr, NULL, PROC_BUFFER_SIZE, - ACR_SBUF_AUTOEXTEND)) { - rc = ACR_GET_OS_ERROR(); + if ((rc = acr_sbuf_init(&ep->serr, NULL, PROC_BUFFER_SIZE))) goto cleanup; - } } return ep; @@ -543,7 +537,11 @@ i_close(&pipes[PIPE_STDINP_WRS]); i_close(&pipes[PIPE_STDOUT_RDS]); i_close(&pipes[PIPE_STDERR_RDS]); + do { + /* TODO: We should consider using timeout here as well + * if set, instead infinite wait. + */ child = waitpid(pid, &exitval, WUNTRACED); } while (child == -1 && errno == EINTR); 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=897838&r1=897837&r2=897838&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 11 11:20:21 2010 @@ -59,18 +59,12 @@ ep->flags = flags; if (flags & ACR_PROC_HAS_STDOUT) { - if (!acr_sbuf_new(&ep->sout, NULL, PROC_BUFFER_SIZE, - ACR_SBUF_AUTOEXTEND)) { - rc = ACR_GET_OS_ERROR(); + if ((rc = acr_sbuf_init(&ep->sout, NULL, PROC_BUFFER_SIZE))) goto cleanup; - } } if (flags & ACR_PROC_HAS_STDERR) { - if (!acr_sbuf_new(&ep->serr, NULL, PROC_BUFFER_SIZE, - ACR_SBUF_AUTOEXTEND)) { - rc = ACR_GET_OS_ERROR(); + if ((rc = acr_sbuf_init(&ep->serr, NULL, PROC_BUFFER_SIZE))) goto cleanup; - } } return ep; Modified: commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c?rev=897838&r1=897837&r2=897838&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/sbuf.c Mon Jan 11 11:20:21 2010 @@ -154,6 +154,25 @@ return s; } +int acr_sbuf_init(acr_sbuf_t *s, char *buf, size_t length) +{ + if (s == NULL) + return ACR_EINVAL; + memset(s, 0, sizeof(acr_sbuf_t)); + s->s_size = length; + if (buf) { + s->s_buf = buf; + return 0; + } + s->s_flags = ACR_SBUF_AUTOEXTEND; + s->s_size = acr_sbuf_extendsize(s->s_size); + s->s_buf = x_malloc(s->s_size); + if (s->s_buf == NULL) + return ACR_ENOMEM; + SBUF_SETFLAG(s, ACR_SBUF_DYNAMIC); + return 0; +} + /* * Clear an sbuf and reset its position. */ @@ -561,6 +580,25 @@ return s; } +int acr_wbuf_init(acr_wbuf_t *s, wchar_t *buf, size_t length) +{ + if (s == NULL) + return ACR_EINVAL; + memset(s, 0, sizeof(acr_sbuf_t)); + s->s_size = length; + if (buf) { + s->s_buf = buf; + return 0; + } + s->s_flags = ACR_SBUF_AUTOEXTEND; + s->s_size = acr_sbuf_extendsize(s->s_size); + s->s_buf = x_malloc(s->s_size * sizeof(wchar_t)); + if (s->s_buf == NULL) + return ACR_ENOMEM; + SBUF_SETFLAG(s, ACR_SBUF_DYNAMIC); + return 0; +} + /* * Clear an sbuf and reset its position. */