aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-02-11 18:01:24 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2012-02-11 21:59:39 +0100
commitaa625ed6ed0ec7060859225cf9d43799eed5a799 (patch)
tree854df8f389ae02d33ad806fea22e9d0d067af7f9
parentb0529ffd951fdaa7ecc823381a6a7b0c88b5b2b0 (diff)
Extra wallet locking fixes
* Fix sign error in calculation of seconds to sleep * Do not mix GetTime() (seconds) and Sleep() (milliseconds) * Do not sleep forever if walletlock() is called * Do locking within critical section
-rw-r--r--src/bitcoinrpc.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 8f98135617..cf5bc64bb9 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -353,7 +353,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
if (pwalletMain->IsCrypted())
- obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
+ obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
@@ -1537,7 +1537,7 @@ void ThreadTopUpKeyPool(void* parg)
void ThreadCleanWalletPassphrase(void* parg)
{
- int64 nMyWakeTime = GetTime() + *((int*)parg);
+ int64 nMyWakeTime = GetTimeMillis() + *((int*)parg) * 1000;
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
@@ -1545,17 +1545,25 @@ void ThreadCleanWalletPassphrase(void* parg)
{
nWalletUnlockTime = nMyWakeTime;
- while (GetTime() < nWalletUnlockTime)
+ do
{
- int64 nToSleep = GetTime() - nWalletUnlockTime;
+ if (nWalletUnlockTime==0)
+ break;
+ int64 nToSleep = nWalletUnlockTime - GetTimeMillis();
+ if (nToSleep <= 0)
+ break;
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
Sleep(nToSleep);
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
- }
- nWalletUnlockTime = 0;
- pwalletMain->Lock();
+ } while(1);
+
+ if (nWalletUnlockTime)
+ {
+ nWalletUnlockTime = 0;
+ pwalletMain->Lock();
+ }
}
else
{
@@ -1653,9 +1661,9 @@ Value walletlock(const Array& params, bool fHelp)
if (!pwalletMain->IsCrypted())
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
- pwalletMain->Lock();
CRITICAL_BLOCK(cs_nWalletUnlockTime)
{
+ pwalletMain->Lock();
nWalletUnlockTime = 0;
}