From 5c8bcbe6db2d6c38f85f4c9790897f07e4808758 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 10 Feb 2015 16:21:34 +0100 Subject: [PATCH 4/5] Minor optimization in _dbus_getsid(). MSDN recommands to use GetCurrentProcess() for current process. --- dbus/dbus-sysdeps-win.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 526db8e..5025815 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -981,7 +981,7 @@ static BOOL is_winxp_sp3_or_lower() /** Gets our SID * @param sid points to sid buffer, need to be freed with LocalFree() - * @param process_id the process id for which the sid should be returned + * @param process_id the process id for which the sid should be returned (use 0 for current process) * @returns process sid */ dbus_bool_t @@ -993,7 +993,13 @@ _dbus_getsid(char **sid, dbus_pid_t process_id) PSID psid; int retval = FALSE; - HANDLE process_handle = OpenProcess(is_winxp_sp3_or_lower() ? PROCESS_QUERY_INFORMATION : PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id); + HANDLE process_handle; + if (process_id == 0) + process_handle = GetCurrentProcess(); + else if (is_winxp_sp3_or_lower()) + process_handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, process_id); + else + process_handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id); if (!OpenProcessToken (process_handle, TOKEN_QUERY, &process_token)) { -- 1.8.4.5