From 479157b69c9a7060791de3fe33d353c2ee7cea27 Mon Sep 17 00:00:00 2001 From: Martin Haimberger Date: Thu, 30 Jul 2015 02:52:11 -0700 Subject: [PATCH] winpr: WaitFor*Ojbect/s set lastError now --- winpr/libwinpr/synch/wait.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/winpr/libwinpr/synch/wait.c b/winpr/libwinpr/synch/wait.c index 8c0b8f22d..7891e85f4 100644 --- a/winpr/libwinpr/synch/wait.c +++ b/winpr/libwinpr/synch/wait.c @@ -210,6 +210,7 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) if (!winpr_Handle_GetInfo(hHandle, &Type, &Object)) { WLog_ERR(TAG, "invalid hHandle."); + SetLastError(ERROR_INVALID_HANDLE); return WAIT_FAILED; } @@ -221,6 +222,7 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) if (process->pid != waitpid(process->pid, &(process->status), 0)) { WLog_ERR(TAG, "waitpid failure [%d] %s", errno, strerror(errno)); + SetLastError(ERROR_INTERNAL_ERROR); return WAIT_FAILED; } @@ -255,13 +257,19 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) int status; int fd = winpr_Handle_getFd(Object); if (fd < 0) + { + WLog_ERR(TAG, "winpr_Handle_getFd did not return a fd!"); + SetLastError(ERROR_INVALID_HANDLE); return WAIT_FAILED; + } + status = waitOnFd(fd, Object->Mode, dwMilliseconds); if (status < 0) { WLog_ERR(TAG, "waitOnFd() failure [%d] %s", errno, strerror(errno)); + SetLastError(ERROR_INTERNAL_ERROR); return WAIT_FAILED; } @@ -271,6 +279,7 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) return winpr_Handle_cleanup(Object); } + SetLastError(ERROR_INTERNAL_ERROR); return WAIT_FAILED; } @@ -353,6 +362,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl if (!winpr_Handle_GetInfo(lpHandles[index], &Type, &Object)) { WLog_ERR(TAG, "invalid event file descriptor"); + SetLastError(ERROR_INVALID_HANDLE); return WAIT_FAILED; } @@ -361,6 +371,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl if (fd == -1) { WLog_ERR(TAG, "invalid file descriptor"); + SetLastError(ERROR_INVALID_HANDLE); return WAIT_FAILED; } @@ -419,6 +430,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl strerror(errno)); #endif winpr_log_backtrace(TAG, WLOG_ERROR, 20); + SetLastError(ERROR_INTERNAL_ERROR); return WAIT_FAILED; } @@ -450,6 +462,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl if (!winpr_Handle_GetInfo(lpHandles[idx], &Type, &Object)) { WLog_ERR(TAG, "invalid hHandle."); + SetLastError(ERROR_INVALID_HANDLE); return WAIT_FAILED; } @@ -458,6 +471,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl if (fd == -1) { WLog_ERR(TAG, "invalid file descriptor"); + SetLastError(ERROR_INVALID_HANDLE); return WAIT_FAILED; } @@ -500,6 +514,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl while (bWaitAll || !signal_handled); WLog_ERR(TAG, "failed (unknown error)"); + SetLastError(ERROR_INTERNAL_ERROR); return WAIT_FAILED; }