You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2010/01/04 09:33:44 UTC
svn commit: r895576 - in /commons/sandbox/runtime/trunk/src/main/native: ./
include/ include/arch/aix/ include/arch/darwin/ include/arch/hpux/
include/arch/linux/ include/arch/solaris/ include/arch/unix/ os/unix/
os/win32/ shared/ test/
Author: mturk
Date: Mon Jan 4 08:33:31 2010
New Revision: 895576
URL: http://svn.apache.org/viewvc?rev=895576&view=rev
Log:
Add argument processing
Added:
commons/sandbox/runtime/trunk/src/main/native/include/acr_args.h (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/args.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/configure
commons/sandbox/runtime/trunk/src/main/native/include/acr.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_exec.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_time.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/aix/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Mon Jan 4 08:33:31 2010
@@ -86,6 +86,7 @@
COMMON_OBJS=\
$(SRCDIR)/shared/buildmark.$(OBJ) \
+ $(SRCDIR)/shared/args.$(OBJ) \
$(SRCDIR)/shared/array.$(OBJ) \
$(SRCDIR)/shared/bzip2.$(OBJ) \
$(SRCDIR)/shared/callback.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon Jan 4 08:33:31 2010
@@ -72,6 +72,7 @@
COMMON_OBJS=\
$(SRCDIR)/shared/buildmark.$(OBJ) \
+ $(SRCDIR)/shared/args.$(OBJ) \
$(SRCDIR)/shared/array.$(OBJ) \
$(SRCDIR)/shared/bzip2.$(OBJ) \
$(SRCDIR)/shared/callback.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Mon Jan 4 08:33:31 2010
@@ -116,6 +116,7 @@
cxx_set=no
test=ctest$$
mach=unknown
+has_legacy_code=no
for o
do
@@ -269,6 +270,8 @@
[platform dependent]
--enable-native-threads Enables Solaris native threads support
[disabled]
+ --enable-legacy-code Enables maximum binary platform compatibility
+ [disabled]
--enable-test Enables test code compilation
[disabled]
--with-java-home=DIR Path to the Java SDK
@@ -674,6 +677,7 @@
test -d "$topdir/include/arch/$host" && varadds includes "-I$topdir/include/arch/$host"
test ".$host" != .windows && varadds includes "-I$topdir/include/arch/unix"
test ".$has_unicode" = .yes && varadds cppopts -DUNICODE -D_UNICODE
+test ".$has_legacy_code" = .yes && varadds cppopts -DENABLE_LEGACY_CODE
if [ ".$has_maintainer_mode" = .yes ]; then
varadds cppopts -DDEBUG -D_DEBUG
else
@@ -736,7 +740,7 @@
have_include()
{
printf "Checking for %-32s" "<$2.h>" 1>&2
- if [ .$host = .windows -a .$1 = .0 ]; then
+ if [ .$host = .windows -a .$1 != .w ]; then
echo "not supported" 1>&2
echo 0
else
@@ -847,9 +851,12 @@
have_function()
{
printf "Checking for %-32s" "$2" 1>&2
- if [ .$host = .windows -a .$1 = .0 ]; then
+ if [ .$host = .windows -a .$1 != .w ]; then
echo "not supported" 1>&2
rc=0
+ elif [ .$1 = .c -a .$has_legacy_code = .yes ]; then
+ echo "not supported by legacy code" 1>&2
+ rc=0
else
rc=`have_function_body $2 $3`
test ".$rc" = .0 && rc=`have_function_body __$2 $3`
@@ -983,7 +990,7 @@
test ".$sizeof_long_double" = .0 && have_long_double=0
if [ ".$host" = .windows ]; then
- have_ktmw32=`have_include 1 ktmw32`
+ have_ktmw32=`have_include w ktmw32`
have_aio=0
have_windows=1
have_uuid_uuid=0
@@ -993,9 +1000,9 @@
have_off64t=1
sizeof_off64_t=`check_sizeof off64_t 0`
test ".$sizeof_off64_t" = .0 && have_off64t=0
- have_aio=`have_include 0 aio`
+ have_aio=`have_include x aio`
have_windows=0
- have_uuid_uuid=`have_include 0 uuid/uuid`
+ have_uuid_uuid=`have_include x uuid/uuid`
if [ ".$have_uuid_uuid" = .1 ]; then
ok=`have_library uuid uuid_generate`
if [ ".$ok" = .1 ]; then
@@ -1009,7 +1016,7 @@
fi
if [ ".$host" = ".linux" ]; then
- have_selinux=`have_include 0 selinux/selinux`
+ have_selinux=`have_include x selinux/selinux`
if [ ".$have_selinux" = .1 ]; then
ok=`have_library selinux is_selinux_enabled`
if [ ".$ok" = .1 ]; then
@@ -1023,9 +1030,9 @@
fi
if [ ".$host" = ".solaris" ]; then
- have_port=`have_include 0 port`
+ have_port=`have_include x port`
if [ ".$have_port" = .1 ]; then
- have_port=`have_function 0 port_create`
+ have_port=`have_function x port_create`
fi
ok=`have_library kstat`
test ".$ok" = .1 && varadds ldflags -lkstat
@@ -1043,7 +1050,7 @@
varadds sslflags -lssl -lcrypto
fi
have_openssl=1
- have_ocsp=`have_include 1 openssl/ocsp`
+ have_ocsp=`have_include w openssl/ocsp`
varadds modules '??(SSLMODLIB)'
else
if [ ".$openssl_home" != . ]; then
@@ -1069,7 +1076,7 @@
fi
has_openssl=yes
have_openssl=1
- have_ocsp=`have_include 1 $openssl_home/openssl/ocsp`
+ have_ocsp=`have_include w $openssl_home/openssl/ocsp`
varadds modules '??(SSLMODLIB)'
else
have_ocsp=0
@@ -1084,7 +1091,7 @@
have_sqlite3=1
else
test ".$sqlite_inc" != . && varadds includes "-I$sqlite_inc"
- have_sqlite3=`have_include 0 sqlite3`
+ have_sqlite3=`have_include w sqlite3`
if [ .$have_sqlite3 = .1 ] ; then
if [ ".$host" = .windows ]; then
test ".$sqlite_lib" != . && varadds sqlflags "/libpath:\"$sqlite_lib\""
@@ -1147,59 +1154,60 @@
#define HAVE_PORT_H $have_port
#define HAVE_SQLITE3 $have_sqlite3
-#define HAVE_UNISTD_H `have_include 0 unistd`
-#define HAVE_STRING_H `have_include 1 string`
-#define HAVE_STRINGS_H `have_include 0 strings`
-#define HAVE_INTTYPES_H `have_include 0 inttypes`
-#define HAVE_STDINT_H `have_include 0 stdint`
-#define HAVE_WTYPES_H `have_include 0 wtypes`
-#define HAVE_DLFCN_H `have_include 0 dlfcn`
-#define HAVE_LINK_H `have_include 0 link`
-#define HAVE_FCNTL_H `have_include 0 fcntl`
-#define HAVE_SYS_FILE_H `have_include 0 sys/file`
-#define HAVE_SYS_TYPES_H `have_include 1 sys/types`
-#define HAVE_SYS_CDEFS_H `have_include 0 sys/cdefs`
-#define HAVE_SYS_QUEUE_H `have_include 0 sys/queue`
-#define HAVE_SYS_RESOURCE_H `have_include 0 sys/resource`
-#define HAVE_SYS_SELECT_H `have_include 0 sys/select`
-#define HAVE_SYS_SOCKET_H `have_include 0 sys/socket`
-#define HAVE_SYS_WAIT_H `have_include 0 sys/wait`
-#define HAVE_SYS_SYSLIMITS_H `have_include 0 sys/syslimits`
-#define HAVE_SYS_UIO_H `have_include 0 sys/uio`
-#define HAVE_SYS_MMAN_H `have_include 0 sys/mman`
-#define HAVE_SYS_EPOLL_H `have_include 0 sys/epoll`
-#define HAVE_SYS_EVENT_H `have_include 0 sys/event`
-#define HAVE_SYS_EVENTFD_H `have_include 0 sys/eventfd`
-#define HAVE_SYS_SIGNALFD_H `have_include 0 sys/signalfd`
-#define HAVE_SYS_INOTIFY_H `have_include 0 sys/inotify`
-#define HAVE_LIMITS_H `have_include 1 limits`
-#define HAVE_NETDB_H `have_include 0 netdb`
-#define HAVE_NETINET_IN_H `have_include 0 netinet/in`
-#define HAVE_ARPA_INET_H `have_include 0 arpa/inet`
-#define HAVE_RESOLV_H `have_include 0 resolv`
-#define HAVE_SYS_UN_H `have_include 0 sys/un`
-#define HAVE_UCONTEXT_H `have_include 0 ucontext`
-#define HAVE_STRERROR_R `have_function 0 strerror_r`
-#define HAVE_MMAP64 `have_function 0 mmap64`
-#define HAVE_POSIX_MEMALIGN `have_function 0 posix_memalign`
-#define HAVE_FDATASYNC `have_function 0 fdatasync`
-#define HAVE_ACCEPT4 `have_function 0 accept4`
-#define HAVE_CLOCK_GETTIME `have_function 0 clock_gettime`
-#define HAVE_DUP3 `have_function 0 dup3`
-#define HAVE_EPOLL_CREATE1 `have_function 0 epoll_create1`
-#define HAVE_KQUEUE `have_function 0 kqueue`
-#define HAVE_INOTIFY_INIT `have_function 0 inotify_init`
-#define HAVE_USLEEP `have_function 0 usleep`
-#define HAVE_NANOSLEEP `have_function 0 nanosleep`
-#define HAVE_LOCALTIME_R `have_function 0 localtime_r`
-#define HAVE_GMTIME_R `have_function 0 gmtime_r`
-#define HAVE_SIGSETJMP `have_function 0 sigsetjmp`
-#define HAVE_SIGACTION `have_function 0 sigaction`
-#define HAVE_EVENTFD `have_function 0 eventfd`
-#define HAVE_EVENTFD2 `have_function 0 eventfd2`
-#define HAVE_SIGNALFD `have_function 0 signalfd`
-#define HAVE_FDWALK `have_function 0 fdwalk`
-#define HAVE_PIPE2 `have_function 0 pipe2`
+#define HAVE_UNISTD_H `have_include x unistd`
+#define HAVE_STRING_H `have_include w string`
+#define HAVE_STRINGS_H `have_include x strings`
+#define HAVE_INTTYPES_H `have_include x inttypes`
+#define HAVE_STDINT_H `have_include x stdint`
+#define HAVE_WTYPES_H `have_include x wtypes`
+#define HAVE_DLFCN_H `have_include x dlfcn`
+#define HAVE_LINK_H `have_include x link`
+#define HAVE_FCNTL_H `have_include x fcntl`
+#define HAVE_SYS_FILE_H `have_include x sys/file`
+#define HAVE_SYS_TYPES_H `have_include w sys/types`
+#define HAVE_SYS_CDEFS_H `have_include x sys/cdefs`
+#define HAVE_SYS_QUEUE_H `have_include x sys/queue`
+#define HAVE_SYS_RESOURCE_H `have_include x sys/resource`
+#define HAVE_SYS_SELECT_H `have_include x sys/select`
+#define HAVE_SYS_SOCKET_H `have_include x sys/socket`
+#define HAVE_SYS_WAIT_H `have_include x sys/wait`
+#define HAVE_SYS_SYSLIMITS_H `have_include x sys/syslimits`
+#define HAVE_SYS_UIO_H `have_include x sys/uio`
+#define HAVE_SYS_MMAN_H `have_include x sys/mman`
+#define HAVE_SYS_EPOLL_H `have_include x sys/epoll`
+#define HAVE_SYS_EVENT_H `have_include x sys/event`
+#define HAVE_SYS_EVENTFD_H `have_include x sys/eventfd`
+#define HAVE_SYS_SIGNALFD_H `have_include x sys/signalfd`
+#define HAVE_SYS_INOTIFY_H `have_include x sys/inotify`
+#define HAVE_SYS_TIME_H `have_include x sys/time`
+#define HAVE_LIMITS_H `have_include w limits`
+#define HAVE_NETDB_H `have_include x netdb`
+#define HAVE_NETINET_IN_H `have_include x netinet/in`
+#define HAVE_ARPA_INET_H `have_include x arpa/inet`
+#define HAVE_RESOLV_H `have_include x resolv`
+#define HAVE_SYS_UN_H `have_include x sys/un`
+#define HAVE_UCONTEXT_H `have_include x ucontext`
+#define HAVE_STRERROR_R `have_function x strerror_r`
+#define HAVE_MMAP64 `have_function x mmap64`
+#define HAVE_POSIX_MEMALIGN `have_function x posix_memalign`
+#define HAVE_FDATASYNC `have_function x fdatasync`
+#define HAVE_CLOCK_GETTIME `have_function x clock_gettime`
+#define HAVE_KQUEUE `have_function x kqueue`
+#define HAVE_INOTIFY_INIT `have_function x inotify_init`
+#define HAVE_USLEEP `have_function x usleep`
+#define HAVE_NANOSLEEP `have_function x nanosleep`
+#define HAVE_LOCALTIME_R `have_function x localtime_r`
+#define HAVE_GMTIME_R `have_function x gmtime_r`
+#define HAVE_SIGSETJMP `have_function x sigsetjmp`
+#define HAVE_SIGACTION `have_function x sigaction`
+#define HAVE_FDWALK `have_function x fdwalk`
+#define HAVE_DUP3 `have_function c dup3`
+#define HAVE_EPOLL_CREATE1 `have_function c epoll_create1`
+#define HAVE_ACCEPT4 `have_function c accept4`
+#define HAVE_EVENTFD `have_function c eventfd`
+#define HAVE_EVENTFD2 `have_function c eventfd2`
+#define HAVE_SIGNALFD `have_function c signalfd`
+#define HAVE_PIPE2 `have_function c pipe2`
#define HAVE_SOCK_CLOEXEC `have_defined SOCK_CLOEXEC`
#define HAVE_FILE_CLOEXEC `have_defined O_CLOEXEC`
#define HAVE_OFF64_T $have_off64t
@@ -1307,3 +1315,4 @@
echo "Configured for $host$bits-$cc"
$EECHO "You can now run \033[1m$run_make\033[0m to build the library."
echo ""
+
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Mon Jan 4 08:33:31 2010
@@ -118,6 +118,9 @@
#if HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
@@ -272,6 +275,7 @@
typedef PSID acr_uid_t;
typedef PSID acr_gid_t;
typedef HANDLE acr_osd_t;
+typedef DWORD acr_pid_t;
#if HAVE_INTPTR_T
typedef intptr_t acr_intptr_t;
#else
@@ -337,6 +341,7 @@
typedef uid_t acr_uid_t;
typedef gid_t acr_gid_t;
typedef int acr_osd_t;
+typedef pid_t acr_pid_t;
#if CC_SIZEOF_LONG == 8
#define ACR_INT64_C(val) (val##L)
#define ACR_UINT64_C(val) (val##UL)
Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_args.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_args.h?rev=895576&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_args.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_args.h Mon Jan 4 08:33:31 2010
@@ -0,0 +1,67 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_ARGS_H
+#define _ACR_ARGS_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_args.h
+ * @brief
+ *
+ * ACR Prosess argument parsing functions
+ *
+ */
+
+/**
+ * This function provides a way to parse a generic argument string
+ * into a standard argv[] form of argument list. It respects the
+ * usual "whitespace" and quoteing rules. In the future this could
+ * be expanded to include support for the apr_call_exec command line
+ * string processing (including converting '+' to ' ' and doing the
+ * url processing. It does not currently support this function.
+ *
+ * @param cmdline Input argument string for conversion to argv[].
+ * @param argv Output location. This is a pointer to an array
+ * of pointers to strings (ie. &(char *argv[]).
+ * This value will be allocated from the contexts
+ * pool and filled in with copies of the tokens
+ * found during parsing of the cmdline.
+ * @return number of argumennts in argv array or -1 in case of error.
+ */
+ACR_DECLARE(int) ACR_StringToArgvA(const char *cmdline,
+ char ***argv)
+
+#if defined(WIN32)
+/**
+ * Unicode version of ACR_StringToArgvA
+ */
+ACR_DECLARE(int) ACR_StringToArgvW(const wchar_t *cmdline,
+ wchar_t ***argv)
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_ARGS_H */
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_args.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Mon Jan 4 08:33:31 2010
@@ -579,6 +579,16 @@
#define ACR_ENOTIMPL (ACR_OS_START_STATUS + 23)
/** @see ACR_STATUS_IS_EMISMATCH */
#define ACR_EMISMATCH (ACR_OS_START_STATUS + 24)
+
+/** @see ACR_STATUS_IS_CHILD_SIGNAL */
+#define ACR_CHILD_SIGNAL (ACR_OS_START_STATUS + 50)
+/** @see ACR_STATUS_IS_CHILD_SIGNAL_CORE */
+#define ACR_CHILD_SIGNAL_CORE (ACR_OS_START_STATUS + 51)
+/** @see ACR_STATUS_IS_CHILD_ERROR */
+#define ACR_CHILD_ERROR (ACR_OS_START_STATUS + 52)
+/** @see ACR_STATUS_IS_PARENT_ERROR */
+#define ACR_PARENT_ERROR (ACR_OS_START_STATUS + 53)
+
/** @} */
/**
@@ -728,6 +738,38 @@
*/
#define ACR_STATUS_IS_EBUSY(s) ((s) == ACR_EBUSY)
+/**
+ * The child exited by signal
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define ACR_STATUS_IS_CHILD_SIGNAL(s) ((s) == ACR_CHILD_SIGNAL)
+
+/**
+ * The child exited by core signal
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define ACR_STATUS_IS_CHILD_SIGNAL_CORE(s) ((s) == ACR_CHILD_SIGNAL_CORE)
+
+/**
+ * The child exited with unspecified error
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define ACR_STATUS_IS_CHILD_ERROR(s) ((s) == ACR_CHILD_ERROR)
+
+/**
+ * The child didnt executed because of parent error
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define ACR_STATUS_IS_PARENT_ERROR(s) ((s) == ACR_PARENT_ERROR)
+
/** @} */
/**
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=895576&r1=895575&r2=895576&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 4 08:33:31 2010
@@ -31,6 +31,34 @@
*
*/
+/** The ACR process type */
+typedef struct acr_exec_t {
+ /** Process id */
+ acr_pid_t pid;
+ /** Data from STDOUT */
+ acr_sbuf_t sout;
+ /** Data from STDERR */
+ acr_sbuf_t serr;
+ /** Data for STDIN */
+ struct iovec data;
+ /** Process timeout */
+ acr_time_t timeout;
+ /** Process flags */
+ int flags;
+ /** Process exit value */
+ int exitval;
+ /** Process exit reason */
+ int exitwhy;
+} acr_exec_t;
+
+#define ACR_PROC_HAS_STDIN 0x0001
+#define ACR_PROC_HAS_STDOUT 0x0002
+#define ACR_PROC_HAS_STDERR 0x0004
+
+ACR_DECLARE(acr_exec_t *) ACR_ExecNew(int flags);
+ACR_DECLARE(int) ACR_ShellExec(acr_exec_t *exe, const acr_pchar_t *cmdline);
+ACR_DECLARE(const char *) ACR_ExecStream(acr_exec_t *exe, int which);
+ACR_DECLARE(void) ACR_ExecFree(acr_exec_t *exe);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h Mon Jan 4 08:33:31 2010
@@ -39,6 +39,16 @@
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
+#if !defined(STDIN_FILENO)
+#define STDIN_FILENO 0
+#endif
+#if !defined(STDOUT_FILENO)
+#define STDOUT_FILENO 1
+#endif
+#if !defined(STDERR_FILENO)
+#define STDERR_FILENO 2
+#endif
+
/**
* Function prototypes for the portable layer
*/
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h Mon Jan 4 08:33:31 2010
@@ -43,7 +43,7 @@
/**
* Send a signal to the process.
* @param key Signal security key.
- * @param sig signal to send.
+ * @param signum signal to send.
* @param to pid of the process
*/
ACR_DECLARE(int) ACR_RaiseSignal(const acr_pchar_t *key, int signum, int to);
@@ -67,9 +67,21 @@
*/
ACR_DECLARE(acr_sigfunc_t *) ACR_Signal(int signo, acr_sigfunc_t *func);
+/**
+ * Block the signal
+ * @param signum signal to block.
+ */
+ACR_DECLARE(int) ACR_SignalBlock(int signum);
+
+/**
+ * Unblock the signal
+ * @param signum signal to unblock.
+ */
+ACR_DECLARE(int) ACR_SignalUnblock(int signum);
#ifdef __cplusplus
}
#endif
#endif /* _ACR_SIGNALS_H */
+
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Mon Jan 4 08:33:31 2010
@@ -428,28 +428,16 @@
ACR_DECLARE(wchar_t *) ACR_wcsqtab2ss(wchar_t *str);
/**
- * Convert string sparated by isspace chars to array.
- * Single quotes allow embedded spaces.
- * @param s String to use.
- * @param args Output token array.
- * @param maxargs Maximum size of the token array.
- * @return number of tokens.
- * @note If the maxargs is not large enough to hold all the tokens returned
- * value is >= to maxargs.
- */
-ACR_DECLARE(size_t) ACR_StrTokenize(char *s, char **args, size_t maxargs);
-
-/**
* Sort the array of string using case insensitive order
* @param pointer to char array to sort.
*/
-ACR_DECLARE(void) ACR_StrSortA(char ***args);
+ACR_DECLARE(void) ACR_StrArraySortA(char ***args);
/**
* Sort the array of wide string using case insensitive order
* @param pointer to the wide char array to sort.
*/
-ACR_DECLARE(void) ACR_StrSortW(wchar_t ***args);
+ACR_DECLARE(void) ACR_StrArraySortW(wchar_t ***args);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_time.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_time.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_time.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_time.h Mon Jan 4 08:33:31 2010
@@ -46,6 +46,9 @@
*/
#define ACR_USEC_PER_SEC ACR_TIME_C(1000000)
+/** @return acr_time_t as a msec */
+#define ACR_TIME_AS_MSEC(T) ((T) / 1000)
+
/**
* Convert DOS time format to ACR Time
*/
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/aix/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/aix/acr_arch_private.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/aix/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/aix/acr_arch_private.h Mon Jan 4 08:33:31 2010
@@ -78,6 +78,8 @@
* Temporary APR private flags
*/
#define DEV_RANDOM "/dev/urandom"
+#define DEF_UPATH "/bin:/usr/bin"
+#define DEF_SPATH "/sbin:/bin:/usr/sbin:/usr/bin"
#define DSO_USE_DLFCN 1
#define DIRENT_INODE d_ino
#undef DIRENT_TYPE
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h Mon Jan 4 08:33:31 2010
@@ -77,6 +77,8 @@
* Temporary APR private flags
*/
#define DEV_RANDOM "/dev/urandom"
+#define DEF_UPATH "/bin:/usr/bin"
+#define DEF_SPATH "/sbin:/bin:/usr/sbin:/usr/bin"
#define DSO_USE_DLFCN 1
#define DIRENT_INODE d_fileno
#define DIRENT_TYPE d_type
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h Mon Jan 4 08:33:31 2010
@@ -80,6 +80,8 @@
* Temporary APR private flags
*/
#define DEV_RANDOM "/dev/urandom"
+#define DEF_UPATH "/bin:/usr/bin"
+#define DEF_SPATH "/sbin:/bin:/usr/sbin:/usr/bin"
#define DSO_USE_DLFCN 1
#define DIRENT_INODE d_fileno
#undef DIRENT_TYPE
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h Mon Jan 4 08:33:31 2010
@@ -79,6 +79,8 @@
* Temporary APR private flags
*/
#define DEV_RANDOM "/dev/urandom"
+#define DEF_UPATH "/bin:/usr/bin"
+#define DEF_SPATH "/sbin:/bin:/usr/sbin:/usr/bin"
#define DSO_USE_DLFCN 1
#define DIRENT_INODE d_fileno
#define DIRENT_TYPE d_type
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h Mon Jan 4 08:33:31 2010
@@ -81,6 +81,9 @@
* Temporary APR private flags
*/
#define DEV_RANDOM "/dev/urandom"
+#define SHELL_PATH "/usr/xpg4/bin/sh"
+#define DEF_UPATH "/usr/xpg4/bin:/usr/bin:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/sfw/bin:/opt/sfw/bin"
+#define DEF_SPATH "/usr/sbin:/usr/xpg4/bin:/usr/bin:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/sfw/bin:/opt/sfw/bin"
#define DSO_USE_DLFCN 1
#define DIRENT_INODE d_ino
#undef DIRENT_TYPE
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Mon Jan 4 08:33:31 2010
@@ -62,6 +62,13 @@
#define IS_INVALID_MEMORY(h) (((h) == NULL || (h) == INVALID_MEMORY_VALUE))
#define IS_VALID_MEMORY(h) (((h) != NULL && (h) != INVALID_MEMORY_VALUE))
+#ifndef DEFAULT_PATH
+#define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
+#endif
+#ifndef SHELL_PATH
+#define SHELL_PATH "/bin/sh"
+#endif
+
#if !defined(O_NONBLOCK)
#if defined(O_NDELAY)
#define O_NONBLOCK O_NDELAY
@@ -198,6 +205,52 @@
return d;
}
+/* restartable close() */
+static ACR_INLINE int r_close(int fd)
+{
+ int rc;
+ do {
+ rc = close(fd);
+ } while (rc == -1 && errno == EINTR);
+
+ return rc;
+}
+
+/* safe close() */
+static ACR_INLINE int s_close(int fd)
+{
+ if (fd == -1) {
+ errno = EBADF;
+ return -1;
+ }
+ else
+ return r_close(fd);
+}
+
+static ACR_INLINE int i_close(int *fd)
+{
+ if (fd) {
+ int fc = *fd;
+ *fd = -1;
+ return s_close(fc);
+ }
+ else {
+ errno = EINVAL;
+ return -1;
+ }
+}
+
+/* restartable dup2() */
+static ACR_INLINE int r_dup2(int oldfd, int newfd)
+{
+ int rc;
+ do {
+ rc = dup2(oldfd, newfd);
+ } while (rc == -1 && errno == EINTR);
+
+ return rc;
+}
+
/* restartable read() */
static ACR_INLINE ssize_t r_read(int fd, void *buf, size_t count)
{
@@ -220,6 +273,40 @@
return w;
}
+static ACR_INLINE ssize_t f_write(int fd, const void *buf, size_t count)
+{
+ ssize_t t = 0;
+ ssize_t w;
+ ssize_t c = (ssize_t)count;
+ const char *p = (const char *)buf;
+ do {
+ w = r_write(fd, p, c);
+ if (w > 0) {
+ p += w;
+ c -= w;
+ t += w;
+ }
+ } while (w >= 0 && c > 0);
+ return t;
+}
+
+static ACR_INLINE ssize_t f_read(int fd, void *buf, size_t count)
+{
+ ssize_t t = 0;
+ ssize_t r;
+ ssize_t c = (ssize_t)count;
+ char *p = (char *)buf;
+ do {
+ r = r_read(fd, p, c);
+ if (r > 0) {
+ p += r;
+ c -= r;
+ t += r;
+ }
+ } while (r >= 0 && c > 0);
+ return t;
+}
+
/* restartable pread() */
static ACR_INLINE ssize_t r_pread(int fd, void *buf, size_t count,
off_t offset)
@@ -254,8 +341,7 @@
volatile char *ptr = (volatile char *)p;
while (len) {
- *ptr = 0;
- ptr++;
+ *(ptr++) = 0;
len--;
}
return p;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c Mon Jan 4 08:33:31 2010
@@ -43,6 +43,7 @@
if (dp->dp != NULL) {
if (closedir((DIR *)dp->dp))
rc = ACR_GET_OS_ERROR();
+ dp->dp = NULL;
}
else
rc = ACR_EBADF;
@@ -326,3 +327,4 @@
return rv;
}
+
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=895576&r1=895575&r2=895576&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 4 08:33:31 2010
@@ -22,8 +22,11 @@
#include "acr_memory.h"
#include "acr_signals.h"
#include "acr_string.h"
+#include "acr_sbuf.h"
#include "acr_descriptor.h"
#include "acr_file.h"
+#include "acr_pipe.h"
+#include "acr_time.h"
#include "acr_exec.h"
/**
@@ -31,7 +34,342 @@
*
*/
-#define PIPE_RDS 0
-#define PIPE_WRS 1
+extern int pipepair(int pd[2], int flags);
+extern int nullpipe(int flags, int fd);
+
+#define PIPE_STDINP_RDS 0
+#define PIPE_STDINP_WRS 1
+#define PIPE_STDOUT 2
+#define PIPE_STDOUT_RDS 2
+#define PIPE_STDOUT_WRS 3
+#define PIPE_STDERR 4
+#define PIPE_STDERR_RDS 4
+#define PIPE_STDERR_WRS 5
+#define PIPE_SIGNAL 6
+#define PIPE_SIGNAL_RDS 6
+#define PIPE_SIGNAL_WRS 7
+
+/* Internal structure for passing data
+ * across the signal pipe
+ */
+typedef struct _info_c {
+ pid_t pid; /* Pid */
+ int err; /* Error from grand child */
+ int sig; /* Signal number from child */
+ int len; /* Payload data length */
+} _info_c;
+
+ACR_DECLARE(acr_exec_t *) ACR_ExecNew(int flags)
+{
+ int rc = 0;
+ acr_exec_t *ep;
+
+ if (!(ep = s_calloc(acr_exec_t, 1)))
+ return NULL;
+ ep->pid = -1;
+ ep->timeout = -1;
+ ep->flags = flags;
+
+ if (flags & ACR_PROC_HAS_STDOUT) {
+ if (!acr_sbuf_new(&ep->sout, NULL, 512, ACR_SBUF_AUTOEXTEND)) {
+ rc = ACR_GET_OS_ERROR();
+ goto cleanup;
+ }
+ }
+ if (flags & ACR_PROC_HAS_STDERR) {
+ if (!acr_sbuf_new(&ep->serr, NULL, 512, ACR_SBUF_AUTOEXTEND)) {
+ rc = ACR_GET_OS_ERROR();
+ goto cleanup;
+ }
+ }
+ return ep;
+
+cleanup:
+ acr_sbuf_delete(&ep->sout);
+ acr_sbuf_delete(&ep->serr);
+ x_free(ep);
+
+ ACR_SET_OS_ERROR(rc);
+ return NULL;
+}
+
+ACR_DECLARE(int) ACR_ShellExec(acr_exec_t *ep, const acr_pchar_t *cmdline)
+{
+ pid_t pid;
+ ssize_t rd;
+ int i;
+ int rc = 0;
+ int exitval;
+ int pipes[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
+ _info_c info = { -1, 0, 0, 0 };
+
+ /* Create pipes */
+ if (ep->flags & ACR_PROC_HAS_STDERR) {
+ if ((rc = pipepair(&pipes[PIPE_STDOUT], ACR_PIPE_WRITE_BLOCK)))
+ goto cleanup;
+ }
+ if (ep->flags & ACR_PROC_HAS_STDERR) {
+ if ((rc = pipepair(&pipes[PIPE_STDERR], ACR_PIPE_WRITE_BLOCK)))
+ goto cleanup;
+ }
+ if ((rc = pipepair(&pipes[PIPE_SIGNAL], ACR_PIPE_FULL_BLOCK)))
+ goto cleanup;
+
+ pid = fork();
+ if (pid < 0) {
+ rc = ACR_GET_OS_ERROR();
+ goto cleanup;
+ }
+ else if (pid == 0) {
+ /* Child process */
+ const char *args[4];
+
+ args[0] = SHELL_PATH;
+ args[1] = "-c";
+ args[2] = cmdline;
+ args[3] = NULL;
+
+ /* Close child side of pipes
+ */
+ i_close(&pipes[PIPE_STDINP_WRS]);
+ i_close(&pipes[PIPE_STDOUT_RDS]);
+ i_close(&pipes[PIPE_STDERR_RDS]);
+ i_close(&pipes[PIPE_SIGNAL_RDS]);
+
+ /* Make sure the signaling pipe is closed on exec.
+ * This forces parent to wait until actual
+ * exec is performed or until the error is
+ * written to the signal pipe
+ */
+ acr_cloexec(pipes[PIPE_SIGNAL_WRS]);
+
+ close(STDOUT_FILENO);
+ if (pipes[PIPE_STDINP_RDS] == -1) {
+ /* Redirect stdin to /dev/null
+ */
+ pipes[PIPE_STDINP_RDS] = nullpipe(O_RDONLY, -1);
+ if (pipes[PIPE_STDINP_RDS] == -1) {
+ rc = ACR_GET_OS_ERROR();
+ goto child_cleanup;
+ }
+ }
+ if (dup2(pipes[PIPE_STDINP_RDS], STDIN_FILENO) == -1) {
+ rc = ACR_GET_OS_ERROR();
+ goto child_cleanup;
+ }
+
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+ if (pipes[PIPE_STDOUT_WRS] == -1) {
+ /* Redirect stdout to /dev/null
+ */
+ pipes[PIPE_STDOUT_WRS] = nullpipe(O_WRONLY, -1);
+ if (pipes[PIPE_STDOUT_WRS] == -1) {
+ rc = ACR_GET_OS_ERROR();
+ goto child_cleanup;
+ }
+ }
+ if (dup2(pipes[PIPE_STDOUT_WRS], STDOUT_FILENO) == -1) {
+ rc = ACR_GET_OS_ERROR();
+ goto child_cleanup;
+ }
+ if (pipes[PIPE_STDERR_WRS] == -1)
+ rc = dup2(pipes[PIPE_STDOUT_WRS], STDERR_FILENO);
+ else
+ rc = dup2(pipes[PIPE_STDERR_WRS], STDERR_FILENO);
+ if (rc == -1) {
+ rc = ACR_GET_OS_ERROR();
+ goto child_cleanup;
+ }
+ i_close(&pipes[PIPE_STDOUT_WRS]);
+ i_close(&pipes[PIPE_STDERR_WRS]);
+
+ execv(SHELL_PATH, (char * const *)args);
+ rc = ACR_GET_OS_ERROR();
+
+child_cleanup:
+ /* Still here?
+ */
+ info.pid = getpid();
+ info.err = rc;
+ f_write(pipes[PIPE_SIGNAL_WRS], &info, sizeof(info));
+ /* Alternative to exit() could be
+ * kill(info.pid, 9);
+ */
+ exit(0x80 + rc);
+ }
+ else {
+ /* Parent process */
+ struct pollfd ps[4];
+ int npipes = 0;
+ int running = ep->flags & (ACR_PROC_HAS_STDOUT | ACR_PROC_HAS_STDERR);
+ pid_t child = pid;
+
+ /* Close parent side of pipes
+ */
+ i_close(&pipes[PIPE_STDINP_RDS]);
+ i_close(&pipes[PIPE_STDOUT_WRS]);
+ i_close(&pipes[PIPE_STDERR_WRS]);
+ i_close(&pipes[PIPE_SIGNAL_WRS]);
+
+ /* Handshake with the child process.
+ * If the read is sucessful it means that
+ * either init or execv inside child failed.
+ */
+ rd = r_read(pipes[PIPE_SIGNAL_RDS], &info, sizeof(info));
+ i_close(&pipes[PIPE_SIGNAL_RDS]);
+ if (rd == sizeof(info)) {
+ /* We have received error status
+ * from the child
+ */
+ running = 0;
+ }
+
+ while (running) {
+ npipes = 0;
+ if (pipes[PIPE_STDOUT_RDS] != -1) {
+ ps[npipes].fd = pipes[PIPE_STDOUT_RDS];
+ ps[npipes].events = POLLIN;
+ ps[npipes].revents = 0;
+ npipes++;
+ }
+ if (pipes[PIPE_STDERR_RDS] != -1) {
+ ps[npipes].fd = pipes[PIPE_STDERR_RDS];
+ ps[npipes].events = POLLIN;
+ ps[npipes].revents = 0;
+ npipes++;
+ }
+ if (npipes) {
+ i = 0;
+ do {
+ rc = poll(ps, npipes, -1);
+ } while (rc == -1 && errno == EINTR);
+ if (rc < 1)
+ break;
+ if (pipes[PIPE_STDOUT_RDS] != -1 && ps[i].revents) {
+ if (ps[i].revents & POLLIN) {
+ char buf[512];
+
+ rd = r_read(pipes[PIPE_STDOUT_RDS], buf, sizeof(buf));
+ if (rd > 0)
+ acr_sbuf_bcat(&ep->sout, buf, rd);
+ else
+ i_close(&pipes[PIPE_STDOUT_RDS]);
+ }
+ else {
+ i_close(&pipes[PIPE_STDOUT_RDS]);
+ }
+ i++;
+ }
+ if (pipes[PIPE_STDERR_RDS] != -1 && ps[i].revents) {
+ if (ps[i].revents & POLLIN) {
+ char buf[512];
+
+ rd = r_read(pipes[PIPE_STDERR_RDS], buf, sizeof(buf));
+ if (rd > 0)
+ acr_sbuf_bcat(&ep->serr, buf, rd);
+ else
+ i_close(&pipes[PIPE_STDERR_RDS]);
+ }
+ else {
+ i_close(&pipes[PIPE_STDERR_RDS]);
+ }
+ i++;
+ }
+ }
+ else {
+ /* All pipes are closed
+ */
+ running = 0;
+ }
+ }
+ /* Finished reading child output streams
+ */
+ i_close(&pipes[PIPE_STDINP_WRS]);
+ i_close(&pipes[PIPE_STDOUT_RDS]);
+ i_close(&pipes[PIPE_STDERR_RDS]);
+ do {
+ child = waitpid(pid, &exitval, WUNTRACED);
+ } while (child == -1 && errno == EINTR);
+
+ if (info.err) {
+ /* Error reported from child
+ */
+ ep->exitwhy = ACR_CHILD_ERROR;
+ ep->exitval = info.err;
+ ep->pid = info.pid;
+
+ return ep->exitwhy;
+ }
+ switch (child) {
+ case 0:
+ /* Unexpected condition
+ */
+ ep->exitwhy = ACR_CHILD_NOTDONE;
+ ep->exitval = 0;
+ break;
+ case -1:
+ /* unexpected condition */
+ ep->exitwhy = ACR_CHILD_NOTDONE;
+ ep->exitval = ACR_GET_OS_ERROR();
+ break;
+ default:
+ ep->pid = child;
+
+ if (WIFEXITED(exitval)) {
+ ep->exitwhy = ACR_CHILD_DONE;
+ ep->exitval = WEXITSTATUS(exitval);
+ }
+ else if (WIFSIGNALED(exitval)) {
+ ep->exitwhy = ACR_CHILD_SIGNAL;
+#ifdef WCOREDUMP
+ if (WCOREDUMP(exitval))
+ ep->exitwhy = ACR_CHILD_SIGNAL_CORE;
+#endif
+ ep->exitval = WTERMSIG(exitval);
+ }
+ else {
+ /* unexpected condition */
+ ep->exitwhy = ACR_CHILD_ERROR;
+ ep->exitval = exitval;
+ }
+ break;
+ }
+ }
+
+ return ep->exitwhy;
+cleanup:
+ ep->exitwhy = ACR_PARENT_ERROR;
+ ep->exitval = rc;
+ for (i = 0; i < 8; i++)
+ s_close(pipes[i]);
+ return ep->exitwhy;
+}
+
+ACR_DECLARE(const char *) ACR_ExecStream(acr_exec_t *e, int which)
+{
+ if (e) {
+ switch (which) {
+ case STDOUT_FILENO:
+ return acr_sbuf_data(&e->sout);
+ break;
+ case STDERR_FILENO:
+ return acr_sbuf_data(&e->serr);
+ break;
+ }
+ }
+ return NULL;
+}
+
+ACR_DECLARE(void) ACR_ExecFree(acr_exec_t *e)
+{
+ if (e) {
+
+ acr_sbuf_delete(&e->sout);
+ acr_sbuf_delete(&e->serr);
+
+ x_free(e);
+ }
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Mon Jan 4 08:33:31 2010
@@ -39,7 +39,7 @@
return ACR_EBADF;
}
if (fp->fd != -1) {
- if (close(fp->fd))
+ if (i_close(&fp->fd))
rc = ACR_GET_OS_ERROR();
else
rc = ACR_SUCCESS;
@@ -50,8 +50,6 @@
}
if (flags & ACR_IOH_CLEAR)
x_free(fp);
- else
- fp->fd = -1;
return rc;
}
@@ -233,8 +231,7 @@
fp->descriptor = (*_E)->NewWeakGlobalRef(_E, *fdo);
finally:
if (rc) {
- if (fd >= 0)
- close(fd);
+ s_close(fd);
if (fp) {
x_free(fp->name);
x_free(fp);
@@ -728,3 +725,4 @@
}
return fd;
}
+
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c Mon Jan 4 08:33:31 2010
@@ -75,7 +75,7 @@
if ((flags & MMAP_OWNS_FILE) && m->fd > 0) {
/* Since we have opended the file close it.
*/
- if (close(m->fd))
+ if (r_close(m->fd))
rc = ACR_GET_OS_ERROR();
m->fd = -1;
}
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=895576&r1=895575&r2=895576&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 Mon Jan 4 08:33:31 2010
@@ -83,7 +83,7 @@
return ACR_EBADF;
}
if (fp->fd >= 0) {
- if (close(fp->fd))
+ if (r_close(fp->fd))
rc = ACR_GET_OS_ERROR();
else
rc = ACR_SUCCESS;
@@ -150,15 +150,101 @@
return rc;
}
+/* Macro to ensure that descriptor is
+ * above standard io descriptors
+ */
+#define FD_ABOVE_STDFILENO(D) \
+ do { \
+ if ((D) == -1 || (D) > 2) \
+ break; \
+ (D) = dup((D)); \
+ } while ((D) < 3)
+
+static const char *_dev_null = "/dev/null";
+
+int nullpipe(int flags, int fd)
+{
+ int nd;
+ int saved_errno = 0;
+
+ if ((nd = open(_dev_null, flags)) == -1)
+ return -1;
+ FD_ABOVE_STDFILENO(nd);
+ if (nd == -1)
+ return -1;
+ if (fd == -1)
+ return nd;
+ if ((fd = dup2(nd, fd)) == -1)
+ saved_errno = errno;
+ close(nd);
+ if (saved_errno)
+ errno = saved_errno;
+ return fd;
+}
+
+int pipepair(int pd[2], int flags)
+{
+ int rc = 0;
+
+#if HAVE_PIPE2
+ int pf = 0;
+
+ if (flags == ACR_PIPE_FULL_NONBLOCK)
+ pf |= O_NONBLOCK;
+ if (pipe2(pd, pf) == -1)
+ return ACR_GET_OS_ERROR();
+ if (flags == ACR_PIPE_WRITE_BLOCK) {
+ if ((rc = acr_nonblock(pd[0], 1)))
+ goto finally;
+ }
+ if (flags == ACR_PIPE_READ_BLOCK) {
+ if ((rc = acr_nonblock(pd[1], 1)))
+ goto finally;
+ }
+#else
+ if (pipe(pd) == -1)
+ return ACR_GET_OS_ERROR();
+ if (flags == ACR_PIPE_WRITE_BLOCK ||
+ flags == ACR_PIPE_FULL_NONBLOCK) {
+ if ((rc = acr_nonblock(pd[0], 1)))
+ goto finally;
+ }
+ if (flags == ACR_PIPE_READ_BLOCK ||
+ flags == ACR_PIPE_FULL_NONBLOCK) {
+ if ((rc = acr_nonblock(pd[1], 1)))
+ goto finally;
+ }
+#endif
+ FD_ABOVE_STDFILENO(pd[0]);
+ if (pd[0] == -1) {
+ rc = ACR_GET_OS_ERROR();
+ goto finally;
+ }
+ FD_ABOVE_STDFILENO(pd[1]);
+ if (pd[1] == -1) {
+ rc = ACR_GET_OS_ERROR();
+ goto finally;
+ }
+
+ return 0;
+
+finally:
+ s_close(pd[0]);
+ s_close(pd[1]);
+
+ return rc;
+}
+
static int create_pipepair(JNIEnv *_E, acr_file_t **rd, acr_file_t **wr,
int flags)
{
int rc = 0;
int pd[2] = { -1, -1 };
- if (pipe(pd) == -1)
- return ACR_GET_OS_ERROR();
*wr = NULL;
+ *rd = NULL;
+ if ((rc = pipepair(pd, flags)))
+ goto finally;
/* We have two handles created.
* Create wrapper objects and events
*/
@@ -173,8 +259,6 @@
(*rd)->type = ACR_FT_PIPE;
if (flags == ACR_PIPE_WRITE_BLOCK ||
flags == ACR_PIPE_FULL_NONBLOCK) {
- if ((rc = acr_nonblock(pd[0], 1)))
- goto finally;
(*rd)->blocking = BLK_OFF;
(*rd)->timeout = 0;
}
@@ -192,10 +276,8 @@
(*wr)->name = NULL;
(*wr)->flags = flags;
(*wr)->type = ACR_FT_PIPE;
- if (flags == ACR_PIPE_WRITE_BLOCK ||
+ if (flags == ACR_PIPE_READ_BLOCK ||
flags == ACR_PIPE_FULL_NONBLOCK) {
- if ((rc = acr_nonblock(pd[1], 1)))
- goto finally;
(*wr)->blocking = BLK_OFF;
(*wr)->timeout = 0;
}
@@ -206,15 +288,11 @@
return 0;
finally:
- if (*rd) {
- close((*rd)->fd);
- x_free(*rd);
- }
- if (*wr) {
- close((*wr)->fd);
- x_free(*wr);
- }
- return rc;
+ s_close(pd[0]);
+ s_close(pd[1]);
+ x_free(*rd);
+ *rd = NULL;
+ return rc;
}
static int do_popen(JNIEnv *_E, acr_file_t *fp, int flags,
@@ -336,3 +414,4 @@
}
return (jint)f->timeout;
}
+
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c Mon Jan 4 08:33:31 2010
@@ -50,7 +50,7 @@
return ACR_EBADF;
}
if (fp->fd != -1) {
- if (close(fp->fd))
+ if (i_close(&fp->fd))
rc = ACR_GET_OS_ERROR();
else
rc = ACR_SUCCESS;
@@ -59,8 +59,6 @@
fp->name = NULL;
if (flags & ACR_IOH_CLEAR)
x_free(fp);
- else
- fp->fd = -1;
return rc;
}
@@ -126,8 +124,7 @@
rc = ACR_GET_OS_ERROR();
finally:
unlink(name);
- if (fd != -1)
- close(fd);
+ s_close(fd);
ACR_THROW_IO_IF_ERR(rc);
return -1;
}
@@ -161,7 +158,7 @@
return NULL;
}
unlink(name);
- close(fd);
+ r_close(fd);
/* Now try to make a directory with the same name.
* Use 0700 since mkstemp uses 0600.
*/
@@ -188,7 +185,7 @@
f = mkstemp(tp);
if (f != -1) {
unlink(tp);
- close(f);
+ r_close(f);
return 1;
}
else
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Mon Jan 4 08:33:31 2010
@@ -22,6 +22,7 @@
#include "acr_port.h"
#include "acr_string.h"
#include "acr_file.h"
+#include "acr_time.h"
char *acr_FileReadTxt(const char *name)
{
@@ -255,3 +256,77 @@
#endif
return rc;
}
+
+#ifndef POLLRDNORM
+#define POLLRDNORM POLLIN
+#endif
+
+#ifndef POLLWRNORM
+#define POLLWRNORM POLLOUT
+#endif
+
+#ifndef POLLRDBAND
+#define POLLRDBAND POLLPRI
+#endif
+
+int arc_pollrd(int fd, acr_time_t timeout)
+{
+ int rc;
+ int msecs = 0;
+ struct pollfd pd;
+
+ pd.fd = fd;
+ pd.events = POLLIN;
+ pd.revents = 0;
+
+ if (timeout > 0)
+ msecs = (int)ACR_TIME_AS_MSEC(timeout);
+ else if (timeout < 0)
+ msecs = -1;
+
+ do {
+ rc = poll(&pd, 1, msecs);
+ } while (rc == -1 && errno == EINTR);
+
+ if (rc < 0)
+ return ACR_GET_OS_ERROR();
+ else if (rc == 0)
+ return ACR_TIMEUP;
+ else if (pd.revents & POLLNVAL)
+ return ACR_EBADF;
+ else if (pd.revents & (POLLHUP | POLLERR))
+ return ACR_EIO;
+ else
+ return 0;
+}
+
+int arc_pollwr(int fd, acr_time_t timeout)
+{
+ int rc;
+ int msecs = 0;
+ struct pollfd pd;
+
+ pd.fd = fd;
+ pd.events = POLLOUT;
+ pd.revents = 0;
+
+ if (timeout > 0)
+ msecs = (int)ACR_TIME_AS_MSEC(timeout);
+ else if (timeout < 0)
+ msecs = -1;
+ do {
+ rc = poll(&pd, 1, msecs);
+ } while (rc == -1 && errno == EINTR);
+
+ if (rc < 0)
+ return ACR_GET_OS_ERROR();
+ else if (rc == 0)
+ return ACR_TIMEUP;
+ else if (pd.revents & POLLNVAL)
+ return ACR_EBADF;
+ else if (pd.revents & (POLLHUP | POLLERR))
+ return ACR_EIO;
+ else
+ return 0;
+}
+
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=895576&r1=895575&r2=895576&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 4 08:33:31 2010
@@ -28,3 +28,5 @@
* Windows process execution functions
*
*/
+
+
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Mon Jan 4 08:33:31 2010
@@ -915,3 +915,4 @@
else
return 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=895576&r1=895575&r2=895576&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 Mon Jan 4 08:33:31 2010
@@ -57,7 +57,7 @@
static acr_atomic32_t pipe_id = 0;
-static int crate_socketpair(SOCKET *rd, SOCKET *wr, int nonblocking)
+int socketpair(SOCKET *rd, SOCKET *wr, int nonblocking)
{
FD_SET rs;
SOCKET ls;
@@ -200,18 +200,17 @@
return rv;
}
-static int create_pipepair(JNIEnv *_E, acr_file_t **rd, acr_file_t **wr,
- int flags)
+int pipepair(HANDLE *rd, HANDLE *wr, wchar_t **pname, int flags)
{
int rc = 0;
SECURITY_ATTRIBUTES sa;
- HANDLE hr = NULL;
- HANDLE hw = NULL;
wchar_t buff[64];
wchar_t *name;
DWORD dwOpenMode;
DWORD dwPipeMode;
+ *rd = NULL;
+ *wr = NULL;
name = pipe_name_from_pid(buff,
GetCurrentProcessId(),
ACR_AtomicInc32(&pipe_id));
@@ -240,18 +239,34 @@
if (flags == ACR_PIPE_READ_BLOCK ||
flags == ACR_PIPE_FULL_NONBLOCK)
dwOpenMode |= FILE_FLAG_OVERLAPPED;
- hw = CreateFileW(name,
- GENERIC_WRITE,
- 0,
- &sa,
- OPEN_EXISTING,
- dwOpenMode,
- NULL);
+ *er = CreateFileW(name,
+ GENERIC_WRITE,
+ 0,
+ &sa,
+ OPEN_EXISTING,
+ dwOpenMode,
+ NULL);
if (IS_INVALID_HANDLE(hw)) {
rc = ACR_GET_OS_ERROR();
CloseHandle(hr);
return rc;
}
+ if (pname)
+ *pname = x_wcsdup(name);
+ return 0;
+}
+
+static int create_pipepair(JNIEnv *_E, acr_file_t **rd, acr_file_t **wr,
+ int flags)
+{
+ int rc = 0;
+ SECURITY_ATTRIBUTES sa;
+ HANDLE hr = NULL;
+ HANDLE hw = NULL;
+ wchar_t *name = NULL;
+
+ if ((rc = pipepair(&hr, &hw, &name, flags)))
+ return rc;
/* We have two handles created.
* Create wrapper objects and events
*/
@@ -261,7 +276,7 @@
goto finally;
}
(*rd)->fd = hr;
- (*rd)->name = ACR_wcsdup(name);
+ (*rd)->name = name;
(*rd)->flags = flags;
(*rd)->type = ACR_FT_PIPE;
if (flags == ACR_PIPE_WRITE_BLOCK ||
@@ -299,13 +314,14 @@
finally:
if (IS_VALID_HANDLE(hr))
CloseHandle(hr);
+ if (IS_VALID_HANDLE(hw))
+ CloseHandle(hw);
if (*rd) {
- CloseHandle((*rd)->fd);
if ((*rd)->overlap.hEvent)
CloseHandle((*rd)->overlap.hEvent);
- x_free((*rd)->name);
x_free(*rd);
}
+ x_free(name);
return rc;
}
@@ -523,3 +539,5 @@
}
return (jint)f->timeout;
}
+
+
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c Mon Jan 4 08:33:31 2010
@@ -20,7 +20,10 @@
#include "acr_string.h"
#include "acr_platform.h"
#include "acr_error.h"
+#include "acr_env.h"
#include "acr_vm.h"
+#include "acr_atomics.h"
+#include "acr_port.h"
static const char unknown[] = "unknown";
extern PSID acr_everyone_sid;
@@ -32,18 +35,19 @@
acr_size_t acr_page_size;
int acr_native_codepage = ACR_CP_DEFAULT;
-
+wchar_t *acr_comspec = NULL;
typedef struct struct_align_t {
char c;
acr_int64_t l;
acr_int32_t i;
} struct_align_t;
-static int initialized = 0;
+static acr_atomic32_t initialized = 0;
ACR_DECLARE(int) ACR_PlatformInitialize(JNIEnv *_E, int ios)
{
int rc;
- if (initialized++)
+
+ if (ACR_AtomicInc32(&initialized))
return 0;
acr_page_size = (acr_size_t)acr_osinf->dwPageSize;
if (!acr_everyone_sid) {
@@ -74,6 +78,14 @@
GENERIC_ALL | FILE_ALL_ACCESS,
GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE |
FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE);
+ /* Get the path to the cmd.exe
+ */
+ acr_comspec = acr_EnvGetW(L"COMSPEC");
+ if (!acr_comspec) {
+ /* Hope the PATH is set correctly
+ */
+ acr_comspec = x_wcsdup("CMD.EXE");
+ }
return acr_ioh_init(ios);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c Mon Jan 4 08:33:31 2010
@@ -190,7 +190,7 @@
DWORD rt;
DWORD rl, dw;
INT64 qw;
- wchar_t *wn;
+ wchar_t *wn = NULL;
char tb[128];
unsigned char *bb = NULL;
char *value = NULL;
@@ -202,7 +202,7 @@
ACR_SET_OS_ERROR(ACR_EINVAL);
return NULL;
}
- if (!(wn = x_wcsdup_utf8(name))) {
+ if (name && *name && !(wn = x_wcsdup_utf8(name))) {
ACR_SET_OS_ERROR(ACR_ENOMEM);
return NULL;
}
@@ -285,13 +285,13 @@
DWORD rt, st = type;
DWORD rl, dw;
INT64 qw;
- wchar_t *wn;
+ wchar_t *wn = NULL;
wchar_t *wp, *p;
if (k && IS_INVALID_HANDLE(k->key)) {
return ACR_EINVAL;
}
- if (!(wn = x_wcsdup_utf8(name))) {
+ if (name && *name && !(wn = x_wcsdup_utf8(name))) {
return ACR_ENOMEM;
}
if ((rc = (int)RegQueryValueExW(k->key, wn, NULL,
Added: commons/sandbox/runtime/trunk/src/main/native/shared/args.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/args.c?rev=895576&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/args.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/args.c Mon Jan 4 08:33:31 2010
@@ -0,0 +1,608 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_memory.h"
+#include "acr_error.h"
+#include "acr_types.h"
+#include "acr_string.h"
+#include "acr_sbuf.h"
+#include "acr_env.h"
+
+/**
+ * Just like strpbrk but it doesn't break if the char
+ * is escaped by single quote
+ */
+static char *strpbrk_s(const char *s1, const char *s2)
+{
+ const char *scanp;
+ int c, sc, pc = *s1;
+
+ /* Some early sanity check */
+ if (!s1 || !*s1)
+ return NULL;
+ while ((c = *s1++) != 0) {
+ for (scanp = s2; (sc = *scanp++) != 0;) {
+ if (sc == c && pc != '\'')
+ return (char *)(s1 - 1);
+ }
+ /* Don't update the previous marker if it was \' already
+ * In that case we have escaped single quote.
+ */
+ if (pc == '\\' && c == '\'')
+ pc = 0;
+ else
+ pc = c;
+ }
+ return NULL;
+}
+
+static char *_strexpand(char *str)
+{
+ char *var_pos;
+ char *var_end;
+ char *var_ptr;
+ char *var_rep;
+ acr_sbuf_t sbuf;
+
+ var_ptr = str;
+
+ if (!var_ptr || !*var_ptr)
+ return str; /* Guard against zero input */
+ var_pos = strpbrk_s(var_ptr, "$");
+ if (!var_pos) {
+#if defined(WIN32)
+ char *buf;
+ DWORD siz;
+
+ siz = ExpandEnvironmentStringsA(str, NULL, 0);
+ if (siz) {
+ buf = s_malloc(char, siz);
+ if (buf == NULL)
+ return str;
+ siz = ExpandEnvironmentStringsA(str, buf, siz);
+ if (!siz) {
+ x_free(buf);
+ return str;
+ }
+ x_free(str);
+ return buf;
+ }
+#endif
+ /* Nothing to replace.
+ */
+ return str;
+ }
+ acr_sbuf_new(&sbuf, NULL, strlen(str), ACR_SBUF_AUTOEXTEND);
+ /* Loop for each unescaped $ */
+ while (var_pos) {
+ int wch = 0;
+ var_end = NULL;
+ var_rep = NULL;
+ if (*(var_pos + 1) == '(') {
+ var_end = strpbrk(var_pos + 1, " })");
+ wch = ')';
+ }
+ else if (*(var_pos + 1) == '{') {
+ var_end = strpbrk(var_pos + 1, " })");
+ wch = '}';
+ }
+ if (var_end && *var_end == wch) {
+ *var_pos++ = '\0';
+ *var_pos++ = '\0';
+ *var_end++ = '\0';
+ /* Add the string before $ */
+ acr_sbuf_cat(&sbuf, var_ptr);
+ /* var_pos holds the variable name */
+ var_rep = ACR_EnvGet(var_pos);
+ if (var_rep) {
+ acr_sbuf_cat(&sbuf, var_rep);
+ x_free(var_rep);
+ }
+ else {
+ acr_sbuf_putc(&sbuf, '$');
+ if (wch == '}')
+ acr_sbuf_putc(&sbuf, '{');
+ else
+ acr_sbuf_putc(&sbuf, '(');
+ acr_sbuf_cat(&sbuf, var_pos);
+ acr_sbuf_putc(&sbuf, wch);
+ }
+ var_ptr = var_end;
+ var_pos = strpbrk_s(var_ptr, "$");
+ }
+ else {
+ *var_pos++ = '\0';
+ acr_sbuf_cat(&sbuf, var_ptr);
+ acr_sbuf_putc(&sbuf, '$');
+ var_ptr = var_pos;
+ var_pos = strpbrk_s(var_ptr, "$");
+ }
+ }
+ /* Add what's left from the original string */
+ acr_sbuf_cat(&sbuf, var_ptr);
+ acr_sbuf_finish(&sbuf);
+ x_free(str);
+
+ str = acr_sbuf_data(&sbuf);
+ return str;
+}
+
+/*
+ * This function provides a way to parse a generic argument string
+ * into a standard argv[] form of argument list. It respects the
+ * usual "whitespace" and quoteing rules. In the future this could
+ * be expanded to include support for the apr_call_exec command line
+ * string processing (including converting '+' to ' ' and doing the
+ * url processing. It does not currently support this function.
+ *
+ * cmdline: Input argument string for conversion to argv[].
+ * argv: Output location. This is a pointer to an array
+ * of pointers to strings (ie. &(char *argv[]).
+ * This value will be allocated from the contexts
+ * pool and filled in with copies of the tokens
+ * found during parsing of the cmdline.
+ */
+ACR_DECLARE(int) ACR_StringToArgvA(const char *cmdline,
+ char ***argv)
+{
+ const char *cp;
+ const char *ct;
+ char *cleaned, *dirty;
+ char *args;
+ char *argp;
+ char *exps;
+ int escaped;
+ int isquoted, numargs = 0, argnum;
+ size_t offset;
+#define SKIP_WHITESPACEA(C) \
+ for ( ; *C == ' ' || *C == '\t'; ) { \
+ C++; \
+ };
+
+#define CHECK_QUOTATIONA(C, Q) \
+ Q = 0; \
+ if (*C == '"') { \
+ Q = 1; \
+ C++; \
+ } \
+ else if (*C == '\'') { \
+ Q = 2; \
+ C++; \
+ }
+
+/* DETERMINE_NEXTSTRING:
+ * At exit, cp will point to one of the following: NULL, SPACE, TAB or QUOTE.
+ * NULL implies the argument string has been fully traversed.
+ */
+#define DETERMINE_NEXTSTRINGA(C, Q) \
+ for ( ; *C != '\0'; C++) { \
+ if ((*C == '\\' && (*(C+1) == ' ' || *(C+1) == '\t' || \
+ *(C+1) == '"' || *(C+1) == '\''))) { \
+ C++; \
+ continue; \
+ } \
+ if ((!Q && (*C == ' ' || *C == '\t')) \
+ || (Q == 1 && *C == '"') \
+ || (Q == 2 && *C == '\'')) { \
+ break; \
+ } \
+ }
+
+/* REMOVE_ESCAPE_CHARS:
+ * Compresses the arg string to remove all of the '\' escape chars.
+ * The final argv strings should not have any extra escape chars in it.
+ */
+#define REMOVE_ESCAPE_CHARSA(C, D, E) \
+ E = 0; \
+ while(*D) { \
+ if (!E && *D == '\\') { \
+ E = 1; \
+ } \
+ else { \
+ E = 0; \
+ *C++ = *D; \
+ } \
+ ++D; \
+ } \
+ *C = 0
+
+ cp = cmdline;
+ SKIP_WHITESPACEA(cp);
+ exps = x_strdup(cp);
+ if (!exps)
+ return -1;
+ exps = _strexpand(exps);
+ ct = exps;
+
+ /* This is ugly and expensive, but if anyone wants to figure a
+ * way to support any number of args without counting and
+ * allocating, please go ahead and change the code.
+ *
+ * Must account for the trailing NULL arg.
+ */
+ numargs = 1;
+ while (*ct != '\0') {
+ CHECK_QUOTATIONA(ct, isquoted);
+ DETERMINE_NEXTSTRINGA(ct, isquoted);
+ if (*ct != '\0') {
+ ct++;
+ }
+ numargs++;
+ SKIP_WHITESPACEA(ct);
+ }
+ if (!argv) {
+ x_free(exps);
+ return numargs;
+ }
+ offset = ACR_ALIGN_DEFAULT(numargs * sizeof(char*));
+ args = x_malloc(offset + strlen(exps) + 1);
+ if (!args) {
+ x_free(exps);
+ return -1;
+ }
+ *argv = (char **)args;
+ args += offset;
+ strcpy(args, exps);
+ x_free(exps);
+ /* determine first argument */
+ for (argnum = 0; argnum < (numargs-1); argnum++) {
+ SKIP_WHITESPACEA(args);
+ CHECK_QUOTATIONA(args, isquoted);
+ argp = args;
+ DETERMINE_NEXTSTRINGA(args, isquoted);
+ args++;
+ (*argv)[argnum] = argp;
+ (*argv)[argnum][args - argp - 1] = '\0';
+
+ cleaned = dirty = (*argv)[argnum];
+ REMOVE_ESCAPE_CHARSA(cleaned, dirty, escaped);
+ }
+ /* Always NULL terminate the array */
+ (*argv)[argnum] = NULL;
+
+ return argnum;
+}
+
+#if defined(WIN32)
+/* Wide char versions make sense on Windows only
+ */
+static wchar_t *wcspbrk_s(const wchar_t *s1, const wchar_t *s2)
+{
+ const wchar_t *scanp;
+ int c, sc, pc = *s1;
+
+ /* Some early sanity check */
+ if (!s1 || !*s1)
+ return NULL;
+ while ((c = *s1++) != 0) {
+ for (scanp = s2; (sc = *scanp++) != 0;) {
+ if (sc == c && pc != L'\'')
+ return (wchar_t *)(s1 - 1);
+ }
+ /* Don't update the previous marker if it was \' already
+ * In that case we have escaped single quote.
+ */
+ if (pc == L'\\' && c == L'\'')
+ pc = 0;
+ else
+ pc = c;
+ }
+ return NULL;
+}
+
+static wchar_t * _wcsexpand(wchar_t *str)
+{
+ wchar_t *var_pos;
+ wchar_t *var_end;
+ wchar_t *var_ptr;
+ wchar_t *var_rep;
+ acr_wbuf_t sbuf;
+
+ var_ptr = str;
+
+ if (!var_ptr || !*var_ptr)
+ return str; /* Guard against zero input */
+ var_pos = wcspbrk_s(var_ptr, L"$");
+ if (!var_pos) {
+ wchar_t *buf;
+ DWORD siz;
+
+ siz = ExpandEnvironmentStringsW(str, NULL, 0);
+ if (siz) {
+ buf = s_malloc(wchar_t, siz);
+ if (buf == NULL)
+ return str;
+ siz = ExpandEnvironmentStringsW(str, buf, siz);
+ if (!siz) {
+ x_free(buf);
+ return str;
+ }
+ x_free(str);
+ return buf;
+ }
+ return str;
+ }
+ acr_wbuf_new(&sbuf, NULL, wcslen(str), ACR_SBUF_AUTOEXTEND);
+ /* Loop for each unescaped $ */
+ while (var_pos) {
+ int wch = 0;
+ var_end = NULL;
+ var_rep = NULL;
+ if (*(var_pos + 1) == L'(') {
+ var_end = wcspbrk(var_pos + 1, L" })");
+ wch = L')';
+ }
+ else if (*(var_pos + 1) == L'{') {
+ var_end = wcspbrk(var_pos + 1, L" })");
+ wch = L'}';
+ }
+ if (var_end && *var_end == wch) {
+ *var_pos++ = L'\0';
+ *var_pos++ = L'\0';
+ *var_end++ = L'\0';
+ /* Add the string before $ */
+ acr_wbuf_cat(&sbuf, var_ptr);
+ /* var_pos holds the variable name */
+ var_rep = acr_EnvGetW(var_pos);
+ if (var_rep) {
+ acr_wbuf_cat(&sbuf, var_rep);
+ x_free(var_rep);
+ }
+ else {
+ acr_wbuf_putc(&sbuf, L'$');
+ if (wch == L'}')
+ acr_wbuf_putc(&sbuf, L'{');
+ else
+ acr_wbuf_putc(&sbuf, L'(');
+ acr_wbuf_cat(&sbuf, var_pos);
+ acr_wbuf_putc(&sbuf, wch);
+ }
+ var_ptr = var_end;
+ var_pos = wcspbrk_s(var_ptr, L"$");
+ }
+ else {
+ *var_pos++ = L'\0';
+ acr_wbuf_cat(&sbuf, var_ptr);
+ acr_wbuf_putc(&sbuf, L'$');
+ var_ptr = var_pos;
+ var_pos = wcspbrk_s(var_ptr, L"$");
+ }
+ }
+ /* Add what's left from the original string */
+ acr_wbuf_cat(&sbuf, var_ptr);
+ acr_wbuf_finish(&sbuf);
+ x_free(str);
+
+ str = acr_wbuf_data(&sbuf);
+ return str;
+}
+
+ACR_DECLARE(int) ACR_StringToArgvW(const wchar_t *cmdline,
+ wchar_t ***argv)
+{
+ const wchar_t *cp;
+ const wchar_t *ct;
+ wchar_t *cleaned, *dirty;
+ wchar_t *args;
+ wchar_t *argp;
+ wchar_t *exps;
+ int escaped;
+ int isquoted, numargs = 0, argnum;
+ size_t offset;
+#define SKIP_WHITESPACEW(C) \
+ for ( ; *C == L' ' || *C == L'\t'; ) { \
+ C++; \
+ };
+
+#define CHECK_QUOTATIONW(C, Q) \
+ Q = 0; \
+ if (*C == L'"') { \
+ Q = 1; \
+ C++; \
+ } \
+ else if (*C == L'\'') { \
+ Q = 2; \
+ C++; \
+ }
+
+/* DETERMINE_NEXTSTRING:
+ * At exit, cp will point to one of the following: NULL, SPACE, TAB or QUOTE.
+ * NULL implies the argument string has been fully traversed.
+ */
+#define DETERMINE_NEXTSTRINGW(C, Q) \
+ for ( ; *C != L'\0'; C++) { \
+ if ((*C == L'\\' && (*(C+1) == L' ' || *(C+1) == L'\t' || \
+ *(C+1) == L'"' || *(C+1) == L'\''))) { \
+ C++; \
+ continue; \
+ } \
+ if ((!Q && (*C == L' ' || *C == L'\t')) \
+ || (Q == 1 && *C == L'"') \
+ || (Q == 2 && *C == L'\'')) { \
+ break; \
+ } \
+ }
+
+/* REMOVE_ESCAPE_CHARS:
+ * Compresses the arg string to remove all of the '\' escape chars.
+ * The final argv strings should not have any extra escape chars in it.
+ */
+#define REMOVE_ESCAPE_CHARSW(C, D, E) \
+ E = 0; \
+ while(*D) { \
+ if (!E && *D == L'\\') { \
+ E = 1; \
+ } \
+ else { \
+ E = 0; \
+ *C++ = *D; \
+ } \
+ ++D; \
+ } \
+ *C = 0
+
+ cp = cmdline;
+ SKIP_WHITESPACEW(cp);
+ exps = x_wcsdup(cp);
+ if (!exps)
+ return -1;
+ exps = _wcsexpand(exps);
+ ct = exps;
+
+ /* This is ugly and expensive, but if anyone wants to figure a
+ * way to support any number of args without counting and
+ * allocating, please go ahead and change the code.
+ *
+ * Must account for the trailing NULL arg.
+ */
+ numargs = 1;
+ while (*ct != L'\0') {
+ CHECK_QUOTATIONW(ct, isquoted);
+ DETERMINE_NEXTSTRINGW(ct, isquoted);
+ if (*ct != L'\0') {
+ ct++;
+ }
+ numargs++;
+ SKIP_WHITESPACEW(ct);
+ }
+ if (!argv) {
+ x_free(exps);
+ return numargs;
+ }
+ offset = ACR_ALIGN_DEFAULT(numargs * sizeof(wchar_t*));
+ args = x_malloc(offset + ((wcslen(exps) + 1) * sizeof(wchar_t)));
+ if (!args) {
+ x_free(exps);
+ return -1;
+ }
+ *argv = (wchar_t **)args;
+ args += (offset / sizeof(wchar_t));
+ wcscpy(args, exps);
+ x_free(exps);
+ /* determine first argument */
+ for (argnum = 0; argnum < (numargs-1); argnum++) {
+ SKIP_WHITESPACEW(args);
+ CHECK_QUOTATIONW(args, isquoted);
+ argp = args;
+ DETERMINE_NEXTSTRINGW(args, isquoted);
+ args++;
+ (*argv)[argnum] = argp;
+ (*argv)[argnum][args - argp - 1] = L'\0';
+
+ cleaned = dirty = (*argv)[argnum];
+ REMOVE_ESCAPE_CHARSW(cleaned, dirty, escaped);
+ }
+ /* Always NULL terminate the array */
+ (*argv)[argnum] = NULL;
+
+ return argnum;
+}
+
+#endif /* WIN32 */
+
+ACR_DECLARE(char **) ACR_DuplicateArgsA(const char *const *argv)
+{
+ size_t arglen;
+ size_t argnum = 1;
+ size_t length = 0;
+ char *buffer;
+ char **dupargv = NULL;
+ const char *const *ap = argv;
+
+ while (*ap) {
+ ++argnum;
+ length += (strlen(*ap) + 1);
+ ap++;
+ }
+ if (!length) {
+ /* Nothing to duplicate
+ */
+ return NULL;
+ }
+ arglen = ACR_ALIGN_DEFAULT(argnum * sizeof(char *));
+ buffer = x_malloc(arglen + length + 1);
+ if (!buffer)
+ return NULL;
+ argnum = 0;
+ ap = argv;
+ dupargv = (char **)buffer;
+ buffer += arglen;
+ while (*ap) {
+ size_t len = strlen(*ap) + 1;
+ memcpy(buffer, *ap, len);
+ dupargv[argnum++] = buffer;
+ buffer += len;
+ ap++;
+ }
+ *buffer = '\0';
+ dupargv[argnum] = NULL;
+
+ return dupargv;
+}
+
+ACR_DECLARE(wchar_t **) ACR_DuplicateArgsW(const wchar_t *const *argv)
+{
+ size_t arglen;
+ size_t argnum = 1;
+ size_t length = 0;
+ wchar_t *buffer;
+ wchar_t **dupargv = NULL;
+ const wchar_t *const *ap = argv;
+
+ while (*ap) {
+ ++argnum;
+ length += (wcslen(*ap) + 1);
+ ap++;
+ }
+ if (!length) {
+ /* Nothing to duplicate
+ */
+ return NULL;
+ }
+ arglen = ACR_ALIGN_DEFAULT(argnum * sizeof(wchar_t *));
+ buffer = x_malloc(arglen + ((length + 3) * sizeof(wchar_t)));
+ if (!buffer)
+ return NULL;
+ argnum = 0;
+ ap = argv;
+ dupargv = (wchar_t **)buffer;
+ buffer += (arglen / sizeof(wchar_t));
+ while (*ap) {
+ size_t len = wcslen(*ap) + 1;
+ if (argnum == 0 && wcspbrk(*ap, L" \t")) {
+ buffer[0] = L'"';
+ memcpy(buffer + 1, *ap, len * sizeof(wchar_t));
+ buffer[len + 1] = L'"';
+ }
+ else
+ memcpy(buffer, *ap, len * sizeof(wchar_t));
+ dupargv[argnum++] = buffer;
+ buffer += len;
+ ap++;
+ }
+ /* Add double zero termination.
+ * dupargv[0] can be used as zero separated
+ * double zero terminated string
+ */
+ *buffer = L'\0';
+ dupargv[argnum] = NULL;
+
+ return dupargv;
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/args.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Mon Jan 4 08:33:31 2010
@@ -27,9 +27,9 @@
acr_size_t size;
acr_size_t ppos;
char *buff;
- acr_size_t dyn_size;
- acr_size_t dyn_ppos;
- void **dyn_buff;
+ acr_size_t dsiz;
+ acr_size_t dpos;
+ void **dbuf;
};
ACR_DECLARE(void *) ACR_Malloc(JNIEnv *_E, const char *file, int line,
@@ -104,9 +104,9 @@
else {
if (!size) {
#if (CC_SIZEOF_VOIDP == 8)
- size = 2048;
+ size = 32 * 1024;
#else
- size = 1024;
+ size = 16 * 1024;
#endif
}
else {
@@ -119,7 +119,10 @@
ACR_SET_OS_ERROR(ACR_EINVAL);
return NULL;
}
- size = ACR_ALIGN_DEFAULT(sbhs + size);
+ if (size < sbhs)
+ size = sbhs;
+ else
+ size = ACR_ALIGN_DEFAULT(sbhs + size);
}
if (!(base = ACR_Calloc(_E, file, line, size)))
return NULL;
@@ -142,27 +145,27 @@
{
void *mem;
- if (sbh->dyn_size == sbh->dyn_ppos) {
+ if (sbh->dsiz == sbh->dpos) {
/* Extend dynamic slot array */
- size_t ns = sbh->dyn_size ? (sbh->dyn_size << 1) : 16;
+ size_t ns = sbh->dsiz ? (sbh->dsiz << 1) : 16;
void **nd = (void **)ACR_Malloc(_E, file, line, ns * sizeof(void *));
if (nd) {
- if (sbh->dyn_buff) {
+ if (sbh->dbuf) {
/* Copy old dynamic slots */
- memcpy(nd, sbh->dyn_buff, sbh->dyn_size * sizeof(void *));
- x_free(sbh->dyn_buff);
+ memcpy(nd, sbh->dbuf, sbh->dsiz * sizeof(void *));
+ x_free(sbh->dbuf);
}
- sbh->dyn_buff = nd;
- sbh->dyn_size = ns;
+ sbh->dbuf = nd;
+ sbh->dsiz = ns;
}
else
return NULL;
}
/* Allocate the real memory */
- mem = sbh->dyn_buff[sbh->dyn_ppos] = ACR_Malloc(_E, file, line, size);
- if (sbh->dyn_buff[sbh->dyn_ppos])
- sbh->dyn_ppos++;
+ mem = sbh->dbuf[sbh->dpos] = ACR_Malloc(_E, file, line, size);
+ if (sbh->dbuf[sbh->dpos])
+ sbh->dpos++;
return mem;
}
@@ -225,14 +228,14 @@
ACR_EISNULL);
return;
}
- if (sbh->dyn_ppos && sbh->dyn_buff) {
+ if (sbh->dpos && sbh->dbuf) {
size_t i;
- for (i = 0; i < sbh->dyn_ppos; i++) {
- x_free(sbh->dyn_buff[i]);
+ for (i = 0; i < sbh->dpos; i++) {
+ x_free(sbh->dbuf[i]);
}
}
- sbh->dyn_ppos = 0;
+ sbh->dpos = 0;
sbh->ppos = 0;
}
@@ -248,7 +251,7 @@
return;
}
ACR_SbhReset(_E, file, line, sbh);
- x_free(sbh->dyn_buff);
+ x_free(sbh->dbuf);
if (sbh->owns)
x_free(sbh);
}
@@ -860,3 +863,4 @@
(*_E)->GetBooleanArrayRegion(_E, src, (jsize)off, (jsize)len, p);
}
+
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon Jan 4 08:33:31 2010
@@ -1980,58 +1980,6 @@
return ptr;
}
-static char *_qtoken(char *s)
-{
- int quoting = 0;
- char *t = s;
-
- while (*t && (quoting || !acr_isspace(*t))) {
- if (*t != '\'') {
- *s++ = *t++;
- continue;
- }
- t++;
- if (!quoting) {
- quoting = 1;
- continue;
- }
- /* Check for double quotes */
- if (*t != '\'') {
- /* end of quoted section; absorb closing quote */
- quoting = 0;
- continue;
- }
- /* doubled quote; fold one quote into two */
- *s++ = *t++;
- }
- if (*s) {
- /* Terminate the token */
- *s = '\0';
- if (t == s) {
- /* More tokens to follow */
- t++;
- }
- }
- return t;
-}
-
-ACR_DECLARE(size_t) ACR_StrTokenize(char *s, char **args, size_t maxargs)
-{
- size_t nargs;
-
- for (nargs = 0; nargs < maxargs; nargs++) {
- /* Skip leading spaces */
- while (*s && acr_isspace(*s))
- s++;
- if (*s == '\0')
- break;
- args[nargs] = s;
- s = _qtoken(s);
- }
-
- return nargs;
-}
-
static int _strcompare(const void *arg1, const void *arg2)
{
/* Compare all of both strings: */
@@ -2044,7 +1992,7 @@
return wcscasecmp(*(wchar_t **)arg1, *(wchar_t **)arg2);
}
-ACR_DECLARE(void) ACR_StrSortA(char ***args)
+ACR_DECLARE(void) ACR_StrArraySortA(char ***args)
{
size_t len = 0;
char **sa = *args;
@@ -2054,7 +2002,7 @@
qsort((void *)&args, len, sizeof(char *), _strcompare);
}
-ACR_DECLARE(void) ACR_StrSortW(wchar_t ***args)
+ACR_DECLARE(void) ACR_StrArraySortW(wchar_t ***args)
{
size_t len = 0;
wchar_t **sa = *args;
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=895576&r1=895575&r2=895576&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Mon Jan 4 08:33:31 2010
@@ -41,6 +41,8 @@
#include "acr_signals.h"
#include "acr_time.h"
#include "acr_version.h"
+#include "acr_sbuf.h"
+#include "acr_exec.h"
#if defined (WIN32)
#include <io.h>
@@ -565,6 +567,24 @@
return 0;
}
+static int test_exec1(int argc, const char *const argv[])
+{
+ int rc;
+ acr_exec_t *exe;
+ if (argc < 1) {
+ return ACR_EINVAL;
+ }
+ exe = ACR_ExecNew(0);
+ rc = ACR_ShellExec(exe, argv[0]);
+
+ 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",
+ exe->exitwhy, exe->exitval);
+ ACR_ExecFree(exe);
+ return 0;
+}
+
int main(int argc, const char *const argv[])
{
int rv = 0;
@@ -650,6 +670,9 @@
else if (!strcasecmp(run_test, "signal")) {
rv = test_signal(argc, argv);
}
+ else if (!strcasecmp(run_test, "shexe")) {
+ rv = test_exec1(argc, argv);
+ }
}
cleanup: