Author: mturk
Date: Thu Sep 10 06:52:15 2009
New Revision: 813261
URL: http://svn.apache.org/viewvc?rev=813261&view=rev
Log:
Add common pipe name generator
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=813261&r1=813260&r2=813261&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Thu Sep 10 06:52:15 2009
@@ -187,6 +187,9 @@
* Utility functions from wutil.c
*/
wchar_t *res_name_from_filenamew(int, wchar_t *, const wchar_t *);
+wchar_t *res_name_from_uuid(wchar_t *, const wchar_t *);
+wchar_t *pipe_name_from_pid(wchar_t *, int, int);
+
int utf8_to_unicode_path(wchar_t *, size_t, const char *);
int unicode_to_utf8_path(char *, size_t, const wchar_t *);
wchar_t *x_wcsdup_utf8(const char *);
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=813261&r1=813260&r2=813261&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Thu Sep 10
06:52:15 2009
@@ -53,7 +53,7 @@
PSID acr_ownerusr_sid = NULL;
PSID acr_ownergrp_sid = NULL;
-static acr_thread_local_t _null_tlsd = { {NULL, NULL}, NULL, 0 };
+static acr_thread_local_t _null_tlsd;
static void acr_thread_key_destructor(void *data)
{
acr_tlsd_data_t *p;
@@ -102,6 +102,7 @@
HeapDestroy(dll_heap_handle);
return FALSE;
}
+ ZeroMemory(&_null_tlsd, sizeof(acr_thread_local_t));
if ((dll_tls_index = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
/* No point to continue if we cannot have TLSD */
return FALSE;
@@ -110,6 +111,9 @@
/** The attached process creates a new thread.
*/
case DLL_THREAD_ATTACH:
+ /* Make sure we have initialized the slot.
+ */
+ TlsSetValue(dll_tls_index, NULL);
break;
/** The thread of the attached process terminates.
*/
@@ -385,6 +389,8 @@
return &_null_tlsd;
tlsd = (acr_thread_local_t *)TlsGetValue(dll_tls_index);
if (tlsd == NULL) {
+ if (GetLastError() != ERROR_SUCCESS)
+ return &_null_tlsd;
tlsd = ACR_HeapCalloc(sizeof(acr_thread_local_t));
if (tlsd == NULL) {
memset(&_null_tlsd, 0, sizeof(acr_thread_local_t));
@@ -410,6 +416,8 @@
}
tlsd = (acr_thread_local_t *)TlsGetValue(dll_tls_index);
if (tlsd == NULL) {
+ if (GetLastError() != ERROR_SUCCESS)
+ return ACR_GET_OS_ERROR();
tlsd = ACR_HeapCalloc(sizeof(acr_thread_local_t));
if (tlsd == NULL) {
return ACR_ENOMEM;
@@ -455,6 +463,10 @@
return NULL;
}
tlsd = ACR_TLSD();
+ if (tlsd == &_null_tlsd) {
+ /* Errno is already set */
+ return NULL;
+ }
if (tlsd->env == NULL) {
if ((*acr_pvm)->GetEnv(acr_pvm, &epp,
JNI_VERSION_1_4) == JNI_EDETACHED) {
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c?rev=813261&r1=813260&r2=813261&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c Thu Sep 10
06:52:15 2009
@@ -47,7 +47,7 @@
/* Use upper 24 bits for object name.
*/
#if _MSC_VER >= 1300
- swprintf(pname, 16,
+ swprintf(pname, sizeof(pname),
#else
swprintf(pname,
#endif
@@ -90,6 +90,26 @@
return rname;
}
+/**
+ * Common pipe resource name
+ * MD5 in UUID form of pid and id (see the code).
+ */
+wchar_t *pipe_name_from_pid(wchar_t *rname, int pid, int id)
+{
+ DWORD rc = 0;
+ wchar_t pname[64];
+
+ wcscpy(rname, L"\\\\.\\pipe\\");
+#if _MSC_VER >= 1300
+ swprintf(pname, sizeof(pname),
+#else
+ swprintf(pname,
+#endif
+ L"apache-commons-pipe-%08x-%08x", pid, id);
+ ACR_MD5EncUuidW(pname, wcslen(pname), rname + 9);
+ return rname;
+}
+
int utf8_to_unicode_path(wchar_t* retstr, size_t retlen,
const char* srcstr)
{