Changeset View
Changeset View
Standalone View
Standalone View
src/qt/winshutdownmonitor.cpp
// Copyright (c) 2014-2016 The Bitcoin Core developers | // Copyright (c) 2014-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <qt/winshutdownmonitor.h> | #include <qt/winshutdownmonitor.h> | ||||
#if defined(Q_OS_WIN) | #if defined(Q_OS_WIN) | ||||
#include <shutdown.h> | #include <shutdown.h> | ||||
#include <util/system.h> | |||||
#include <openssl/rand.h> | |||||
#include <QDebug> | #include <QDebug> | ||||
#include <windows.h> | #include <windows.h> | ||||
// If we don't want a message to be processed by Qt, return true and set result | // If we don't want a message to be processed by Qt, return true and set result | ||||
// to the value that the window procedure should return. Otherwise return false. | // to the value that the window procedure should return. Otherwise return false. | ||||
bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, | bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, | ||||
void *pMessage, long *pnResult) { | void *pMessage, long *pnResult) { | ||||
Q_UNUSED(eventType); | Q_UNUSED(eventType); | ||||
MSG *pMsg = static_cast<MSG *>(pMessage); | MSG *pMsg = static_cast<MSG *>(pMessage); | ||||
// Seed OpenSSL PRNG with Windows event data (e.g. mouse movements and | |||||
// other user interactions) | |||||
if (RAND_event(pMsg->message, pMsg->wParam, pMsg->lParam) == 0) { | |||||
// Warn only once as this is performance-critical | |||||
static bool warned = false; | |||||
if (!warned) { | |||||
LogPrintf("%s: OpenSSL RAND_event() failed to seed OpenSSL PRNG " | |||||
"with enough data.\n", | |||||
__func__); | |||||
warned = true; | |||||
} | |||||
} | |||||
switch (pMsg->message) { | switch (pMsg->message) { | ||||
case WM_QUERYENDSESSION: { | case WM_QUERYENDSESSION: { | ||||
// Initiate a client shutdown after receiving a WM_QUERYENDSESSION | // Initiate a client shutdown after receiving a WM_QUERYENDSESSION | ||||
// and block | // and block | ||||
// Windows session end until we have finished client shutdown. | // Windows session end until we have finished client shutdown. | ||||
StartShutdown(); | StartShutdown(); | ||||
*pnResult = FALSE; | *pnResult = FALSE; | ||||
return true; | return true; | ||||
Show All 30 Lines |