Changeset 47232 in vbox for trunk/src/VBox
- Timestamp:
- Jul 18, 2013 12:00:49 PM (11 years ago)
- Location:
- trunk/src/VBox/Additions
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp
r47212 r47232 124 124 StringCchPrintf(szErr, sizeof(szErr), "0"); 125 125 pushstring(szErr); 126 } 127 128 /** 129 * Connects to VBoxTray IPC under the behalf of the user running 130 * in the current thread context. 131 * 132 * @return IPRT status code. 133 * @param phSession Where to store the IPC session. 134 */ 135 static int vboxConnectToVBoxTray(RTLOCALIPCSESSION hSession) 136 { 137 int rc = VINF_SUCCESS; 138 139 RTUTF16 wszUserName[255]; 140 DWORD cchUserName = sizeof(wszUserName) / sizeof(RTUTF16); 141 BOOL fRc = GetUserNameW(wszUserName, &cchUserName); 142 if (!fRc) 143 rc = RTErrConvertFromWin32(GetLastError()); 144 145 if (RT_SUCCESS(rc)) 146 { 147 char *pszUserName; 148 rc = RTUtf16ToUtf8(wszUserName, &pszUserName); 149 if (RT_SUCCESS(rc)) 150 { 151 char szPipeName[255]; 152 if (RTStrPrintf(szPipeName, sizeof(szPipeName), "%s%s", 153 VBOXTRAY_IPC_PIPE_PREFIX, pszUserName)) 154 { 155 rc = RTLocalIpcSessionConnect(&hSession, szPipeName, 0 /* Flags */); 156 } 157 else 158 rc = VERR_NO_MEMORY; 159 160 RTStrFree(pszUserName); 161 } 162 } 163 164 return rc; 126 165 } 127 166 … … 437 476 { 438 477 RTLOCALIPCSESSION hSession; 439 int rc = RTLocalIpcSessionConnect(&hSession, VBOXTRAY_IPC_PIPENAME, 0 /* Flags */);478 int rc = vboxConnectToVBoxTray(hSession); 440 479 if (RT_SUCCESS(rc)) 441 480 { -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.cpp
r47211 r47232 110 110 int rc = VINF_SUCCESS; 111 111 112 /* Note: This only works up to 49.7 days (= 2^32, 32-bit counter) 113 since Windows was started. */ 112 114 LASTINPUTINFO lastInput; 113 115 lastInput.cbSize = sizeof(LASTINPUTINFO); … … 116 118 { 117 119 VBOXTRAYIPCRES_USERLASTINPUT ipcRes; 118 ipcRes.u TickCount = lastInput.dwTime; /** @sa GetTickCount(). */120 ipcRes.uLastInputMs = GetTickCount() - lastInput.dwTime; 119 121 rc = RTLocalIpcSessionWrite(hSession, &ipcRes, sizeof(ipcRes)); 120 122 } … … 143 145 *pfStartThread = false; 144 146 145 gCtx.pEnv = pEnv;146 gCtx.hServer = NIL_RTLOCALIPCSERVER;147 148 147 int rc = RTCritSectInit(&gCtx.CritSect); 149 148 if (RT_SUCCESS(rc)) 150 149 { 151 rc = RTLocalIpcServerCreate(&gCtx.hServer, VBOXTRAY_IPC_PIPENAME, 152 RTLOCALIPC_FLAGS_MULTI_SESSION); 153 if (RT_FAILURE(rc)) 154 { 155 LogRelFunc(("Creating local IPC server failed with rc=%Rrc\n", rc)); 156 return rc; 157 } 158 159 RTListInit(&gCtx.SessionList); 160 161 *pfStartThread = true; 162 } 163 150 RTUTF16 wszUserName[255]; 151 DWORD cchUserName = sizeof(wszUserName) / sizeof(RTUTF16); 152 BOOL fRc = GetUserNameW(wszUserName, &cchUserName); 153 if (!fRc) 154 rc = RTErrConvertFromWin32(GetLastError()); 155 156 if (RT_SUCCESS(rc)) 157 { 158 char *pszUserName; 159 rc = RTUtf16ToUtf8(wszUserName, &pszUserName); 160 if (RT_SUCCESS(rc)) 161 { 162 char szPipeName[255]; 163 if (RTStrPrintf(szPipeName, sizeof(szPipeName), "%s%s", 164 VBOXTRAY_IPC_PIPE_PREFIX, pszUserName)) 165 { 166 rc = RTLocalIpcServerCreate(&gCtx.hServer, szPipeName, 167 RTLOCALIPC_FLAGS_MULTI_SESSION); 168 if (RT_SUCCESS(rc)) 169 { 170 RTStrFree(pszUserName); 171 172 gCtx.pEnv = pEnv; 173 RTListInit(&gCtx.SessionList); 174 175 *ppInstance = &gCtx; 176 *pfStartThread = true; 177 178 LogRelFunc(("Local IPC server now running at \"%s\"\n", 179 szPipeName)); 180 return VINF_SUCCESS; 181 } 182 183 } 184 else 185 rc = VERR_NO_MEMORY; 186 187 RTStrFree(pszUserName); 188 } 189 } 190 191 RTCritSectDelete(&gCtx.CritSect); 192 } 193 194 LogRelFunc(("Creating local IPC server failed with rc=%Rrc\n", rc)); 164 195 return rc; 165 196 } -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTrayMsg.h
r47213 r47232 19 19 #define ___VBOXTRAY_MSG_H 20 20 21 #define VBOXTRAY_IPC_PIPE NAME "VBoxTrayIPCSvc"21 #define VBOXTRAY_IPC_PIPE_PREFIX "VBoxTrayIPC-" 22 22 23 23 enum VBOXTRAYIPCMSGTYPE … … 29 29 /** Retrieves the current user's last input 30 30 * time. This will be the user VBoxTray is running 31 * under. */ 31 * under. No actual message for this command 32 * required. */ 32 33 VBOXTRAYIPCMSGTYPE_USERLASTINPUT = 120 33 34 }; … … 36 37 typedef struct VBOXTRAYIPCHEADER 37 38 { 39 /** @todo Add magic? */ 38 40 /** Header version, must be 0 by now. */ 39 41 uint32_t uHdrVersion; … … 84 86 typedef struct VBOXTRAYIPCRES_USERLASTINPUT 85 87 { 86 uint32_t uTickCount; 88 /** Last occurred user input event (in ms). */ 89 uint32_t uLastInputMs; 87 90 } VBOXTRAYIPCRES_USERLASTINPUT, *PVBOXTRAYIPCRES_USERLASTINPUT; 88 91 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
r46593 r47232 31 31 #include <iprt/assert.h> 32 32 #include <iprt/ldr.h> 33 #include <iprt/localipc.h> 33 34 #include <iprt/mem.h> 34 35 #include <iprt/thread.h> … … 40 41 #include "VBoxServiceInternal.h" 41 42 #include "VBoxServiceUtils.h" 43 #include "../../WINNT/VBoxTray/VBoxTrayMsg.h" /* For IPC. */ 42 44 43 45 static uint32_t s_uGuestPropClientID = 0; … … 90 92 int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount); 91 93 void VBoxServiceVMInfoWinProcessesFree(DWORD cProcs, PVBOXSERVICEVMINFOPROC paProcs); 94 int vboxServiceVMInfoWinWriteLastInput(char *pszUser); 92 95 93 96 typedef BOOL WINAPI FNQUERYFULLPROCESSIMAGENAME(HANDLE, DWORD, LPTSTR, PDWORD); … … 805 808 806 809 810 static int vboxServiceVMInfoWinWriteLastInput(char *pszUser) 811 { 812 AssertPtrReturn(pszUser, VERR_INVALID_POINTER); 813 814 int rc = VINF_SUCCESS; 815 816 char szPipeName[255]; 817 if (RTStrPrintf(szPipeName, sizeof(szPipeName), "%s%s", 818 VBOXTRAY_IPC_PIPE_PREFIX, pszUser)) 819 { 820 RTLOCALIPCSESSION hSession; 821 rc = RTLocalIpcSessionConnect(&hSession, szPipeName, 0 /* Flags */); 822 if (RT_SUCCESS(rc)) 823 { 824 VBOXTRAYIPCHEADER ipcHdr = { 0 /* Header version */, 825 VBOXTRAYIPCMSGTYPE_USERLASTINPUT, 0 /* No msg */ }; 826 827 rc = RTLocalIpcSessionWrite(hSession, &ipcHdr, sizeof(ipcHdr)); 828 829 VBOXTRAYIPCRES_USERLASTINPUT ipcRes; 830 if (RT_SUCCESS(rc)) 831 rc = RTLocalIpcSessionRead(hSession, &ipcRes, sizeof(ipcRes), 832 NULL /* Exact read */); 833 if (RT_SUCCESS(rc)) 834 { 835 if (ipcRes.uLastInputMs) 836 VBoxServiceVerbose(4, "User \"%s\" is idle for %RU32ms\n", 837 pszUser, ipcRes.uLastInputMs); 838 } 839 #ifdef DEBUG 840 VBoxServiceVerbose(4, "Querying last input for user \"%s\" ended with rc=%Rrc\n", 841 pszUser, rc); 842 #endif 843 int rc2 = RTLocalIpcSessionClose(hSession); 844 if (RT_SUCCESS(rc)) 845 rc = rc2; 846 } 847 else 848 { 849 switch (rc) 850 { 851 case VERR_FILE_NOT_FOUND: 852 /* No VBoxTray (or too old version which does not support IPC) running 853 for the given user. Not much we can do then. */ 854 VBoxServiceVerbose(4, "User \"%s\" not logged in, no last input available\n", 855 pszUser); 856 break; 857 858 default: 859 VBoxServiceVerbose(4, "Error querying last input for user \"%s\", rc=%Rrc\n", 860 pszUser, rc); 861 break; 862 } 863 864 rc = VINF_SUCCESS; 865 } 866 } 867 868 return rc; 869 } 870 871 807 872 /** 808 873 * Retrieves the currently logged in users and stores their names along with the … … 995 1060 *pcUsersInList += 1; 996 1061 997 char *psz Temp;998 int rc2 = RTUtf16ToUtf8(pUserInfo[i].wszUser, &psz Temp);1062 char *pszUser; 1063 int rc2 = RTUtf16ToUtf8(pUserInfo[i].wszUser, &pszUser); 999 1064 if (RT_SUCCESS(rc2)) 1000 1065 { 1001 rc = RTStrAAppend(ppszUserList, pszTemp); 1002 RTMemFree(pszTemp); 1066 rc = RTStrAAppend(ppszUserList, pszUser); 1067 if (RT_SUCCESS(rc)) 1068 rc = vboxServiceVMInfoWinWriteLastInput(pszUser); 1069 RTMemFree(pszUser); 1003 1070 } 1004 1071 else
Note:
See TracChangeset
for help on using the changeset viewer.