mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 11:23:26 +01:00
Merge pull request #2112
76043b17
monero-wallet-cli: hang on exit in readline code (#2117) (moneromooo-monero)a73a42a6
monero-wallet-cli: hang on exit in readline code (#2117) (moneromooo-monero)be9d4f04
Fix multiline wallet cli output with readline (Jethro Grassie)
This commit is contained in:
commit
7995dcff94
@ -5,6 +5,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
static int process_input();
|
static int process_input();
|
||||||
static void install_line_handler();
|
static void install_line_handler();
|
||||||
@ -12,7 +13,7 @@ static void remove_line_handler();
|
|||||||
|
|
||||||
static std::string last_line;
|
static std::string last_line;
|
||||||
static std::string last_prompt;
|
static std::string last_prompt;
|
||||||
std::mutex line_mutex, sync_mutex;
|
std::mutex line_mutex, sync_mutex, process_mutex;
|
||||||
std::condition_variable have_line;
|
std::condition_variable have_line;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -21,6 +22,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
rdln::suspend_readline::suspend_readline()
|
rdln::suspend_readline::suspend_readline()
|
||||||
|
: m_buffer(NULL), m_restart(false)
|
||||||
{
|
{
|
||||||
m_buffer = current;
|
m_buffer = current;
|
||||||
if(!m_buffer)
|
if(!m_buffer)
|
||||||
@ -46,6 +48,7 @@ rdln::readline_buffer::readline_buffer()
|
|||||||
|
|
||||||
void rdln::readline_buffer::start()
|
void rdln::readline_buffer::start()
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(process_mutex);
|
||||||
if(m_cout_buf != NULL)
|
if(m_cout_buf != NULL)
|
||||||
return;
|
return;
|
||||||
m_cout_buf = std::cout.rdbuf();
|
m_cout_buf = std::cout.rdbuf();
|
||||||
@ -55,6 +58,7 @@ void rdln::readline_buffer::start()
|
|||||||
|
|
||||||
void rdln::readline_buffer::stop()
|
void rdln::readline_buffer::stop()
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(process_mutex);
|
||||||
if(m_cout_buf == NULL)
|
if(m_cout_buf == NULL)
|
||||||
return;
|
return;
|
||||||
std::cout.rdbuf(m_cout_buf);
|
std::cout.rdbuf(m_cout_buf);
|
||||||
@ -80,9 +84,17 @@ void rdln::readline_buffer::set_prompt(const std::string& prompt)
|
|||||||
|
|
||||||
int rdln::readline_buffer::process()
|
int rdln::readline_buffer::process()
|
||||||
{
|
{
|
||||||
|
process_mutex.lock();
|
||||||
if(m_cout_buf == NULL)
|
if(m_cout_buf == NULL)
|
||||||
|
{
|
||||||
|
process_mutex.unlock();
|
||||||
|
boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 ));
|
||||||
return 0;
|
return 0;
|
||||||
return process_input();
|
}
|
||||||
|
int count = process_input();
|
||||||
|
process_mutex.unlock();
|
||||||
|
boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 ));
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rdln::readline_buffer::sync()
|
int rdln::readline_buffer::sync()
|
||||||
@ -114,19 +126,18 @@ int rdln::readline_buffer::sync()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fd_set fds;
|
|
||||||
|
|
||||||
static int process_input()
|
static int process_input()
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
|
fd_set fds;
|
||||||
|
|
||||||
t.tv_sec = 0;
|
t.tv_sec = 0;
|
||||||
t.tv_usec = 1000;
|
t.tv_usec = 1000;
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(STDIN_FILENO, &fds);
|
FD_SET(STDIN_FILENO, &fds);
|
||||||
count = select(FD_SETSIZE, &fds, NULL, NULL, &t);
|
count = select(STDIN_FILENO + 1, &fds, NULL, NULL, &t);
|
||||||
if (count < 1)
|
if (count < 1)
|
||||||
{
|
{
|
||||||
return count;
|
return count;
|
||||||
|
@ -62,6 +62,15 @@
|
|||||||
#include "wallet/wallet_args.h"
|
#include "wallet/wallet_args.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#ifdef HAVE_READLINE
|
||||||
|
#include "readline_buffer.h"
|
||||||
|
#define PAUSE_READLINE() \
|
||||||
|
rdln::suspend_readline pause_readline; \
|
||||||
|
std::cout << std::endl
|
||||||
|
#else
|
||||||
|
#define PAUSE_READLINE()
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace epee;
|
using namespace epee;
|
||||||
using namespace cryptonote;
|
using namespace cryptonote;
|
||||||
@ -1831,6 +1840,8 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PAUSE_READLINE();
|
||||||
|
|
||||||
tools::wallet2::transfer_container transfers;
|
tools::wallet2::transfer_container transfers;
|
||||||
m_wallet->get_transfers(transfers);
|
m_wallet->get_transfers(transfers);
|
||||||
|
|
||||||
@ -1891,6 +1902,8 @@ bool simple_wallet::show_payments(const std::vector<std::string> &args)
|
|||||||
|
|
||||||
LOCK_IDLE_SCOPE();
|
LOCK_IDLE_SCOPE();
|
||||||
|
|
||||||
|
PAUSE_READLINE();
|
||||||
|
|
||||||
message_writer() << boost::format("%68s%68s%12s%21s%16s") %
|
message_writer() << boost::format("%68s%68s%12s%21s%16s") %
|
||||||
tr("payment") % tr("transaction") % tr("height") % tr("amount") % tr("unlock time");
|
tr("payment") % tr("transaction") % tr("height") % tr("amount") % tr("unlock time");
|
||||||
|
|
||||||
@ -3716,6 +3729,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
|||||||
|
|
||||||
std::multimap<uint64_t, std::pair<bool,std::string>> output;
|
std::multimap<uint64_t, std::pair<bool,std::string>> output;
|
||||||
|
|
||||||
|
PAUSE_READLINE();
|
||||||
|
|
||||||
if (in) {
|
if (in) {
|
||||||
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
|
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
|
||||||
m_wallet->get_payments(payments, min_height, max_height);
|
m_wallet->get_payments(payments, min_height, max_height);
|
||||||
|
Loading…
Reference in New Issue
Block a user