mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix rehash function
Use SendMessageTimeout instead of SendMessage which was causing the system to hang in some scenarios Use ctypes to access the dll directly instead of using pywin32 as this seems to actually work
This commit is contained in:
parent
9d14ad9ccf
commit
967b83940c
1 changed files with 17 additions and 4 deletions
|
@ -12,12 +12,12 @@ from __future__ import absolute_import
|
|||
import logging
|
||||
import re
|
||||
import os
|
||||
import ctypes
|
||||
from salt.ext.six.moves import map
|
||||
|
||||
# Third party libs
|
||||
try:
|
||||
from win32con import HWND_BROADCAST, WM_SETTINGCHANGE
|
||||
from win32api import SendMessage
|
||||
from win32con import HWND_BROADCAST, WM_SETTINGCHANGE, SMTO_ABORTIFHUNG
|
||||
HAS_WIN32 = True
|
||||
except ImportError:
|
||||
HAS_WIN32 = False
|
||||
|
@ -47,7 +47,15 @@ def _normalize_dir(string):
|
|||
|
||||
def rehash():
|
||||
'''
|
||||
Send a WM_SETTINGCHANGE Broadcast to Windows to refresh the Environment variables
|
||||
Send a WM_SETTINGCHANGE Broadcast to Windows to refresh the Environment
|
||||
variables for new processes.
|
||||
|
||||
.. note::
|
||||
This will only affect new processes that aren't launched by services. To
|
||||
apply changes to the path to services, the host must be restarted. The
|
||||
``salt-minion``, if running as a service, will not see changes to the
|
||||
environment until the system is restarted. See
|
||||
`MSDN Documentation <https://support.microsoft.com/en-us/help/821761/changes-that-you-make-to-environment-variables-do-not-affect-services>`
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -55,7 +63,12 @@ def rehash():
|
|||
|
||||
salt '*' win_path.rehash
|
||||
'''
|
||||
return bool(SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment'))
|
||||
broadcast_message = ctypes.create_unicode_buffer('Environment')
|
||||
user32 = ctypes.windll('user32', use_last_error=True)
|
||||
result = user32.SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
|
||||
broadcast_message, SMTO_ABORTIFHUNG,
|
||||
5000, 0)
|
||||
return result == 1
|
||||
|
||||
|
||||
def get_path():
|
||||
|
|
Loading…
Add table
Reference in a new issue