diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-05-25 14:28:21 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-05-25 14:28:21 +0000 |
commit | d24b82805c046e41bf253df921547d954b877879 (patch) | |
tree | b9d7d70eda07829533de1842f3f9c62b8db34c71 /src/util/os_priority.c | |
parent | 70b173c768c3a43fc392507562df0ede641edbbe (diff) | |
download | gnunet-d24b82805c046e41bf253df921547d954b877879.tar.gz gnunet-d24b82805c046e41bf253df921547d954b877879.zip |
- LRN's patch
Diffstat (limited to 'src/util/os_priority.c')
-rw-r--r-- | src/util/os_priority.c | 107 |
1 files changed, 93 insertions, 14 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 9def6ca54..c46f29333 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -869,7 +869,10 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
869 | char *libdir; | 869 | char *libdir; |
870 | char *ptr; | 870 | char *ptr; |
871 | char *non_const_filename; | 871 | char *non_const_filename; |
872 | wchar_t wpath[MAX_PATH + 1], wcmd[32768]; | 872 | char win_path[MAX_PATH + 1]; |
873 | wchar_t *wpath, *wcmd; | ||
874 | size_t wpath_len, wcmd_len; | ||
875 | long lRet; | ||
873 | 876 | ||
874 | /* Search in prefix dir (hopefully - the directory from which | 877 | /* Search in prefix dir (hopefully - the directory from which |
875 | * the current module was loaded), bindir and libdir, then in PATH | 878 | * the current module was loaded), bindir and libdir, then in PATH |
@@ -901,7 +904,22 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
901 | else | 904 | else |
902 | GNUNET_asprintf (&non_const_filename, "%s", filename); | 905 | GNUNET_asprintf (&non_const_filename, "%s", filename); |
903 | 906 | ||
907 | /* It could be in POSIX form, convert it to a DOS path early on */ | ||
908 | if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path))) | ||
909 | { | ||
910 | SetErrnoFromWinError (lRet); | ||
911 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path", | ||
912 | non_const_filename); | ||
913 | GNUNET_free (non_const_filename); | ||
914 | GNUNET_free (pathbuf); | ||
915 | return NULL; | ||
916 | } | ||
917 | GNUNET_free (non_const_filename); | ||
918 | non_const_filename = GNUNET_strdup (win_path); | ||
904 | /* Check that this is the full path. If it isn't, search. */ | 919 | /* Check that this is the full path. If it isn't, search. */ |
920 | /* FIXME: convert it to wchar_t and use SearchPathW? | ||
921 | * Remember: arguments to _start_process() are technically in UTF-8... | ||
922 | */ | ||
905 | if (non_const_filename[1] == ':') | 923 | if (non_const_filename[1] == ':') |
906 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); | 924 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); |
907 | else if (!SearchPathA | 925 | else if (!SearchPathA |
@@ -996,16 +1014,36 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
996 | GNUNET_free_non_null (our_env[0]); | 1014 | GNUNET_free_non_null (our_env[0]); |
997 | GNUNET_free_non_null (our_env[1]); | 1015 | GNUNET_free_non_null (our_env[1]); |
998 | 1016 | ||
999 | if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath) | 1017 | wpath_len = 0; |
1000 | || ERROR_SUCCESS != plibc_conv_to_win_pathwconv(cmd, wcmd) | 1018 | if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len))) |
1001 | || !CreateProcessW | 1019 | { |
1002 | (wpath, wcmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, | 1020 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1003 | env_block, NULL, &start, &proc)) | 1021 | "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno); |
1022 | GNUNET_free (env_block); | ||
1023 | GNUNET_free (cmd); | ||
1024 | return NULL; | ||
1025 | } | ||
1026 | |||
1027 | wcmd_len = 0; | ||
1028 | if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len))) | ||
1029 | { | ||
1030 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1031 | "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno); | ||
1032 | GNUNET_free (env_block); | ||
1033 | GNUNET_free (cmd); | ||
1034 | free (wpath); | ||
1035 | return NULL; | ||
1036 | } | ||
1037 | |||
1038 | if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, | ||
1039 | DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc)) | ||
1004 | { | 1040 | { |
1005 | SetErrnoFromWinError (GetLastError ()); | 1041 | SetErrnoFromWinError (GetLastError ()); |
1006 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); | 1042 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); |
1007 | GNUNET_free (env_block); | 1043 | GNUNET_free (env_block); |
1008 | GNUNET_free (cmd); | 1044 | GNUNET_free (cmd); |
1045 | free (wpath); | ||
1046 | free (wcmd); | ||
1009 | return NULL; | 1047 | return NULL; |
1010 | } | 1048 | } |
1011 | 1049 | ||
@@ -1022,7 +1060,8 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
1022 | CloseHandle (proc.hThread); | 1060 | CloseHandle (proc.hThread); |
1023 | 1061 | ||
1024 | GNUNET_free (cmd); | 1062 | GNUNET_free (cmd); |
1025 | 1063 | free (wpath); | |
1064 | free (wcmd); | ||
1026 | return gnunet_proc; | 1065 | return gnunet_proc; |
1027 | #endif | 1066 | #endif |
1028 | } | 1067 | } |
@@ -1232,9 +1271,11 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
1232 | const struct GNUNET_DISK_FileHandle *lsocks_write_fd; | 1271 | const struct GNUNET_DISK_FileHandle *lsocks_write_fd; |
1233 | HANDLE lsocks_read; | 1272 | HANDLE lsocks_read; |
1234 | HANDLE lsocks_write; | 1273 | HANDLE lsocks_write; |
1235 | wchar_t wpath[MAX_PATH + 1], wcmd[32768]; | 1274 | wchar_t *wpath, *wcmd; |
1275 | size_t wpath_len, wcmd_len; | ||
1236 | int env_off; | 1276 | int env_off; |
1237 | int fail; | 1277 | int fail; |
1278 | long lRet; | ||
1238 | 1279 | ||
1239 | /* Search in prefix dir (hopefully - the directory from which | 1280 | /* Search in prefix dir (hopefully - the directory from which |
1240 | * the current module was loaded), bindir and libdir, then in PATH | 1281 | * the current module was loaded), bindir and libdir, then in PATH |
@@ -1271,7 +1312,22 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
1271 | else | 1312 | else |
1272 | GNUNET_asprintf (&non_const_filename, "%s", filename); | 1313 | GNUNET_asprintf (&non_const_filename, "%s", filename); |
1273 | 1314 | ||
1274 | /* Check that this is the full path. If it isn't, search. */ | 1315 | /* It could be in POSIX form, convert it to a DOS path early on */ |
1316 | if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path))) | ||
1317 | { | ||
1318 | SetErrnoFromWinError (lRet); | ||
1319 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path", | ||
1320 | non_const_filename); | ||
1321 | GNUNET_free (non_const_filename); | ||
1322 | GNUNET_free (pathbuf); | ||
1323 | return NULL; | ||
1324 | } | ||
1325 | GNUNET_free (non_const_filename); | ||
1326 | non_const_filename = GNUNET_strdup (win_path); | ||
1327 | /* Check that this is the full path. If it isn't, search. */ | ||
1328 | /* FIXME: convert it to wchar_t and use SearchPathW? | ||
1329 | * Remember: arguments to _start_process() are technically in UTF-8... | ||
1330 | */ | ||
1275 | if (non_const_filename[1] == ':') | 1331 | if (non_const_filename[1] == ':') |
1276 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); | 1332 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); |
1277 | else if (!SearchPathA | 1333 | else if (!SearchPathA |
@@ -1394,11 +1450,30 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
1394 | env_block = CreateCustomEnvTable (our_env); | 1450 | env_block = CreateCustomEnvTable (our_env); |
1395 | while (0 > env_off) | 1451 | while (0 > env_off) |
1396 | GNUNET_free_non_null (our_env[--env_off]); | 1452 | GNUNET_free_non_null (our_env[--env_off]); |
1397 | if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath) | 1453 | |
1398 | || ERROR_SUCCESS != plibc_conv_to_win_pathwconv(cmd, wcmd) | 1454 | wpath_len = 0; |
1399 | || !CreateProcessW | 1455 | if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len))) |
1400 | (wpath, wcmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, | 1456 | { |
1401 | env_block, NULL, &start, &proc)) | 1457 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1458 | "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno); | ||
1459 | GNUNET_free (env_block); | ||
1460 | GNUNET_free (cmd); | ||
1461 | return NULL; | ||
1462 | } | ||
1463 | |||
1464 | wcmd_len = 0; | ||
1465 | if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len))) | ||
1466 | { | ||
1467 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1468 | "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno); | ||
1469 | GNUNET_free (env_block); | ||
1470 | GNUNET_free (cmd); | ||
1471 | free (wpath); | ||
1472 | return NULL; | ||
1473 | } | ||
1474 | |||
1475 | if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, | ||
1476 | DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc)) | ||
1402 | { | 1477 | { |
1403 | SetErrnoFromWinError (GetLastError ()); | 1478 | SetErrnoFromWinError (GetLastError ()); |
1404 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); | 1479 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); |
@@ -1408,6 +1483,8 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
1408 | GNUNET_DISK_pipe_close (lsocks_pipe); | 1483 | GNUNET_DISK_pipe_close (lsocks_pipe); |
1409 | GNUNET_free (env_block); | 1484 | GNUNET_free (env_block); |
1410 | GNUNET_free (cmd); | 1485 | GNUNET_free (cmd); |
1486 | free (wpath); | ||
1487 | free (wcmd); | ||
1411 | return NULL; | 1488 | return NULL; |
1412 | } | 1489 | } |
1413 | 1490 | ||
@@ -1423,6 +1500,8 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
1423 | ResumeThread (proc.hThread); | 1500 | ResumeThread (proc.hThread); |
1424 | CloseHandle (proc.hThread); | 1501 | CloseHandle (proc.hThread); |
1425 | GNUNET_free (cmd); | 1502 | GNUNET_free (cmd); |
1503 | free (wpath); | ||
1504 | free (wcmd); | ||
1426 | 1505 | ||
1427 | if (lsocks == NULL || lsocks[0] == INVALID_SOCKET) | 1506 | if (lsocks == NULL || lsocks[0] == INVALID_SOCKET) |
1428 | return gnunet_proc; | 1507 | return gnunet_proc; |