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 2011/04/30 08:26:36 UTC
svn commit: r1098046 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/platform/windows/RegistryKey.java
native/os/win32/arch_opts.h native/os/win32/exec.c native/os/win32/posix.c
native/os/win32/registry.c
Author: mturk
Date: Sat Apr 30 06:26:35 2011
New Revision: 1098046
URL: http://svn.apache.org/viewvc?rev=1098046&view=rev
Log:
Use common mutex for lib locking
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java?rev=1098046&r1=1098045&r2=1098046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java Sat Apr 30 06:26:35 2011
@@ -201,7 +201,7 @@ public class RegistryKey implements Clos
throws IOException, SystemException;
private static native long create0(long key, String name, int sam)
throws IOException, SystemException;
- private static native int info0(long key, String name, int[] info);
+ private static native int info0(long key, String name);
public RegistryKey open(String name, EnumSet<RegistryKeyAccessRights> mode)
throws NullPointerException, IOException, SystemException
@@ -262,12 +262,11 @@ public class RegistryKey implements Clos
throw new NullPointerException();
if (hKey == 0L || hKey == -1L)
throw new InvalidHandleException();
- int[] info = new int[2];
- int rc = info0(hKey, valueName, info);
- if (rc != 0) {
- throw new IOException(Status.describe(rc));
+ int rc = info0(hKey, valueName);
+ if (rc > 256) {
+ throw new IOException(Status.describe(rc - 256));
}
- return RegistryValueType.valueOf(info[0]);
+ return RegistryValueType.valueOf(rc);
}
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h?rev=1098046&r1=1098045&r2=1098046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h Sat Apr 30 06:26:35 2011
@@ -238,5 +238,6 @@ int AcrPipePair(HANDLE *rd, HANDLE *
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz);
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t siz);
const wchar_t *basename_w(const wchar_t *path);
+wchar_t *dirname_w(const wchar_t *path, wchar_t *dname, size_t dlen);
#endif /* _ACR_ARCH_OPTS_H_ */
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=1098046&r1=1098045&r2=1098046&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 Sat Apr 30 06:26:35 2011
@@ -22,6 +22,7 @@
#include "acr/sbuf.h"
#include "acr/string.h"
#include "acr/time.h"
+#include "acr/misc.h"
#include "arch_opts.h"
#define PROC_TIMEOUT_STEP 100
@@ -36,8 +37,6 @@
#define PIPE_COUNT 6
#define SIGKILL 9
-static CRITICAL_SECTION _procmgr_lock;
-
J_DECLARE_CLAZZ = {
INVALID_FIELD_OFFSET,
0,
@@ -55,20 +54,22 @@ J_DECLARE_M_ID(0000) = {
static jstring _procmgr_init(JNI_STDENV)
{
wchar_t b[PATH_MAX];
- wchar_t *shell;
- InitializeCriticalSection(&_procmgr_lock);
+ DWORD rc;
- shell = _wgetenv(L"COMSPEC");
- if (shell == 0) {
+ rc = GetEnvironmentVariableW(L"COMSPEC", b, PATH_MAX - 1);
+ if (rc > 0 && rc < PATH_MAX) {
+ /* Expand %SystemRoot% */
+ rc = ExpandEnvironmentStringsW(b, b, PATH_MAX);
+ }
+ if (rc == 0 || rc > PATH_MAX) {
UINT r;
r = GetSystemDirectoryW(b, PATH_MAX - 10);
if (r == 0 || r > (PATH_MAX - 10))
wcscpy(b, L"C:\\Windows\\System32\\cmd.exe");
else
wcscat(b, L"\\cmd.exe");
- shell = b;
}
- return AcrNewJavaStringW(env, shell);
+ return AcrNewJavaStringW(env, b);
}
static int _run_exec(const wchar_t *executable,
@@ -213,7 +214,7 @@ static int _run_exec(const wchar_t *exec
* Since we never inherit std handles directly, make sure their
* handle is non inherited.
*/
- EnterCriticalSection(&_procmgr_lock);
+ AcrLibLockAcquire();
if (IS_INVALID_HANDLE(stdhandles[0]) &&
GetHandleInformation(stdhandles[0], &stdhinfo[0]) && (stdhinfo[0] &= HANDLE_FLAG_INHERIT))
SetHandleInformation(stdhandles[0], HANDLE_FLAG_INHERIT, 0);
@@ -249,7 +250,7 @@ static int _run_exec(const wchar_t *exec
if (stdhinfo[2])
SetHandleInformation(GetStdHandle(STD_ERROR_HANDLE),
stdhinfo[2], stdhinfo[2]);
- LeaveCriticalSection(&_procmgr_lock);
+ AcrLibLockRelease();
if (rc != 0) {
/* Anything bellow this point is child error.
* This mimicks the posix fork behavior
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c?rev=1098046&r1=1098045&r2=1098046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c Sat Apr 30 06:26:35 2011
@@ -46,6 +46,55 @@ const wchar_t *basename_w(const wchar_t
return startp;
}
+wchar_t *dirname_w(const wchar_t *path, wchar_t *dname, size_t dlen)
+{
+ size_t len;
+ static wchar_t sbuf[ACR_PATH_MAX];
+ const wchar_t *endp;
+
+ if (!dname) {
+ dname = sbuf;
+ dlen = ACR_PATH_MAX;
+ }
+ /* Empty or 0 string gets treated as "." */
+ if (path == 0 || *path == L'\0') {
+ dname[0] = L'.';
+ dname[1] = L'\0';
+ return dname;
+ }
+
+ /* Strip any trailing slashes */
+ endp = path + wcslen(path) - 1;
+ while (endp > path && IS_PSW(*endp))
+ endp--;
+
+ /* Find the start of the dir */
+ while (endp > path && NO_PSW(*endp))
+ endp--;
+
+ /* Either the dir is "/" or there are no slashes */
+ if (endp == path) {
+ dname[0] = IS_PSW(*endp) ? L'/' : L'.';
+ dname[1] = L'\0';
+ return dname;
+ } else {
+ /* Move forward past the separating slashes */
+ do {
+ endp--;
+ } while (endp > path && IS_PSW(*endp));
+ }
+
+ len = endp - path + 1;
+ if (len >= dlen) {
+ ACR_SET_OS_ERROR(ACR_ENAMETOOLONG);
+ return 0;
+ }
+ memmove(dname, path, len * sizeof(wchar_t));
+ dname[len] = L'\0';
+
+ return dname;
+}
+
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
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=1098046&r1=1098045&r2=1098046&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 Sat Apr 30 06:26:35 2011
@@ -127,20 +127,19 @@ ACR_WIN_EXPORT(jlong, RegistryKey, creat
return P2J(skey);
}
-ACR_WIN_EXPORT(jint, RegistryKey, info0)(JNI_STDARGS, jlong key, jstring name,
- jintArray info)
+ACR_WIN_EXPORT(jint, RegistryKey, info0)(JNI_STDARGS, jlong key, jstring name)
{
- DWORD i[2] = { 0, 0};
- int rc = ACR_EINVAL;
- HKEY skey = 0;
- HKEY hkey = J2P(key, HKEY);
+ int v = 0;
+ int rc = ACR_EINVAL;
+ HKEY skey = 0;
+ HKEY hkey = J2P(key, HKEY);
WITH_WSTR(name) {
- rc = RegQueryValueExW(hkey, J2S(name), 0, &i[0], 0, &i[1]);
+ rc = RegQueryValueExW(hkey, J2S(name), 0, &v, 0, 0);
} DONE_WITH_STR(name);
if (rc == 0)
- (*env)->SetIntArrayRegion(env, info, 0, 2, i);
- return rc;
+ return v;
+ else
+ return rc + 256;
}
-