[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r21576 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r21576 - gnunet/src/util |
Date: |
Fri, 25 May 2012 16:28:21 +0200 |
Author: wachs
Date: 2012-05-25 16:28:21 +0200 (Fri, 25 May 2012)
New Revision: 21576
Modified:
gnunet/src/util/os_priority.c
Log:
- LRN's patch
Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c 2012-05-25 14:04:41 UTC (rev 21575)
+++ gnunet/src/util/os_priority.c 2012-05-25 14:28:21 UTC (rev 21576)
@@ -869,7 +869,10 @@
char *libdir;
char *ptr;
char *non_const_filename;
- wchar_t wpath[MAX_PATH + 1], wcmd[32768];
+ char win_path[MAX_PATH + 1];
+ wchar_t *wpath, *wcmd;
+ size_t wpath_len, wcmd_len;
+ long lRet;
/* Search in prefix dir (hopefully - the directory from which
* the current module was loaded), bindir and libdir, then in PATH
@@ -901,7 +904,22 @@
else
GNUNET_asprintf (&non_const_filename, "%s", filename);
+ /* It could be in POSIX form, convert it to a DOS path early on */
+ if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename,
win_path)))
+ {
+ SetErrnoFromWinError (lRet);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path",
+ non_const_filename);
+ GNUNET_free (non_const_filename);
+ GNUNET_free (pathbuf);
+ return NULL;
+ }
+ GNUNET_free (non_const_filename);
+ non_const_filename = GNUNET_strdup (win_path);
/* Check that this is the full path. If it isn't, search. */
+ /* FIXME: convert it to wchar_t and use SearchPathW?
+ * Remember: arguments to _start_process() are technically in UTF-8...
+ */
if (non_const_filename[1] == ':')
snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
else if (!SearchPathA
@@ -996,16 +1014,36 @@
GNUNET_free_non_null (our_env[0]);
GNUNET_free_non_null (our_env[1]);
- if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath)
- || ERROR_SUCCESS != plibc_conv_to_win_pathwconv(cmd, wcmd)
- || !CreateProcessW
- (wpath, wcmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED,
- env_block, NULL, &start, &proc))
+ wpath_len = 0;
+ if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL,
&wpath_len)))
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno);
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ return NULL;
+ }
+
+ wcmd_len = 0;
+ if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL,
&wcmd_len)))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno);
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ free (wpath);
+ return NULL;
+ }
+
+ if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE,
+ DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc))
+ {
SetErrnoFromWinError (GetLastError ());
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
GNUNET_free (env_block);
GNUNET_free (cmd);
+ free (wpath);
+ free (wcmd);
return NULL;
}
@@ -1022,7 +1060,8 @@
CloseHandle (proc.hThread);
GNUNET_free (cmd);
-
+ free (wpath);
+ free (wcmd);
return gnunet_proc;
#endif
}
@@ -1232,9 +1271,11 @@
const struct GNUNET_DISK_FileHandle *lsocks_write_fd;
HANDLE lsocks_read;
HANDLE lsocks_write;
- wchar_t wpath[MAX_PATH + 1], wcmd[32768];
+ wchar_t *wpath, *wcmd;
+ size_t wpath_len, wcmd_len;
int env_off;
int fail;
+ long lRet;
/* Search in prefix dir (hopefully - the directory from which
* the current module was loaded), bindir and libdir, then in PATH
@@ -1271,7 +1312,22 @@
else
GNUNET_asprintf (&non_const_filename, "%s", filename);
- /* Check that this is the full path. If it isn't, search. */
+ /* It could be in POSIX form, convert it to a DOS path early on */
+ if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename,
win_path)))
+ {
+ SetErrnoFromWinError (lRet);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path",
+ non_const_filename);
+ GNUNET_free (non_const_filename);
+ GNUNET_free (pathbuf);
+ return NULL;
+ }
+ GNUNET_free (non_const_filename);
+ non_const_filename = GNUNET_strdup (win_path);
+ /* Check that this is the full path. If it isn't, search. */
+ /* FIXME: convert it to wchar_t and use SearchPathW?
+ * Remember: arguments to _start_process() are technically in UTF-8...
+ */
if (non_const_filename[1] == ':')
snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
else if (!SearchPathA
@@ -1394,12 +1450,31 @@
env_block = CreateCustomEnvTable (our_env);
while (0 > env_off)
GNUNET_free_non_null (our_env[--env_off]);
- if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath)
- || ERROR_SUCCESS != plibc_conv_to_win_pathwconv(cmd, wcmd)
- || !CreateProcessW
- (wpath, wcmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED,
- env_block, NULL, &start, &proc))
+
+ wpath_len = 0;
+ if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL,
&wpath_len)))
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno);
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ return NULL;
+ }
+
+ wcmd_len = 0;
+ if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL,
&wcmd_len)))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno);
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ free (wpath);
+ return NULL;
+ }
+
+ if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE,
+ DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc))
+ {
SetErrnoFromWinError (GetLastError ());
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
if (NULL != control_pipe)
@@ -1408,6 +1483,8 @@
GNUNET_DISK_pipe_close (lsocks_pipe);
GNUNET_free (env_block);
GNUNET_free (cmd);
+ free (wpath);
+ free (wcmd);
return NULL;
}
@@ -1423,6 +1500,8 @@
ResumeThread (proc.hThread);
CloseHandle (proc.hThread);
GNUNET_free (cmd);
+ free (wpath);
+ free (wcmd);
if (lsocks == NULL || lsocks[0] == INVALID_SOCKET)
return gnunet_proc;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r21576 - gnunet/src/util,
gnunet <=