What changed, and why it matters
This change lets the Monero wallet RPC program reopen its log file when it receives a special Unix signal (SIGUSR1). This is a convenience feature for log rotation, matching behavior already present in the main Monero daemon. It is not a security fix and does not appear to introduce a meaningful vulnerability.
No security action required. This is a feature addition for operational log rotation. Operators may optionally use SIGUSR1 to rotate monero-wallet-rpc logs.
Security signals we found
New signal handler added (SIGUSR1)
Atomic flag used for async-safe signal notification
Background thread performs actual log reopening
Signal handler is restored on scope exit via scope_guard
Evidence from the diff
The commit adds a SIGUSR1 signal handler to monero-wallet-rpc that sets an atomic flag, and a background thread that calls mlog_reopen() when the flag is set. It also updates the README to document log rotation for both monerod and monero-wallet-rpc. The implementation uses sigaction with SA_RESTART, restores the previous handler on scope exit, and joins the watcher thread on shutdown.
Changed components
src/wallet/wallet_rpc_server.cppREADME.mdInspect captured patch +55 / −2
### README.md
@@ -540,12 +540,14 @@ To run in background:
./bin/monerod --log-file monerod.log --detach
```
-On POSIX systems, send `SIGUSR1` to `monerod` after externally renaming its log file to reopen the configured log path.
-
To run as a systemd service, copy [monerod.service](utils/systemd/monerod.service) to `/etc/systemd/system/` and [monerod.conf](utils/conf/monerod.conf) to `/etc/`. The [example service](utils/systemd/monerod.service) assumes that the user `monero` exists and its home is the data directory specified in the [example config](utils/conf/monerod.conf).
If you're on Mac, you may need to add the `--max-concurrency 1` option to monero-wallet-cli, and possibly monerod, if you get crashes refreshing.
+## Log rotation
+
+On POSIX systems, send `SIGUSR1` to `monerod` or `monero-wallet-rpc` after externally renaming its log file to reopen the configured log path.
+
## Using Tor
> There is a new, still experimental, [integration with Tor](docs/ANONYMITY_NETWORKS.md). The feature allows connecting over IPv4 and Tor simultaneously - IPv4 is used for relaying blocks and relaying transactions received by peers whereas Tor is used solely for relaying transactions received over local RPC. This provides privacy and better protection against surrounding node (sybil) attacks.
### src/wallet/wallet_rpc_server.cpp
@@ -33,8 +33,10 @@
#include <boost/algorithm/string.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <algorithm>
+#include <atomic>
#include <cstdint>
#include <chrono>
+#include <csignal>
#include <cstring>
#include <thread>
#include <unordered_set>
@@ -58,6 +60,7 @@
#include "rpc/core_rpc_server_commands_defs.h"
#include "daemonizer/daemonizer.h"
#include "fee_priority.h"
+#include "scope_guard.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
@@ -5225,6 +5228,19 @@ namespace tools
//------------------------------------------------------------------------------------------------------------------------------
}
+#ifndef _WIN32
+namespace
+{
+ std::atomic<bool> reopen_log_requested{false};
+ static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "SIGUSR1 requires a lock-free atomic flag");
+
+ void request_log_reopen(int)
+ {
+ reopen_log_requested.store(true, std::memory_order_relaxed);
+ }
+}
+#endif
+
class t_daemon
{
private:
@@ -5241,6 +5257,41 @@ class t_daemon
bool run()
{
+#ifndef _WIN32
+ reopen_log_requested.store(false, std::memory_order_relaxed);
+ struct sigaction reopen_action = {};
+ reopen_action.sa_handler = request_log_reopen;
+ reopen_action.sa_flags = SA_RESTART;
+ sigemptyset(&reopen_action.sa_mask);
+ struct sigaction previous_action = {};
+ const bool reopen_signal_installed = sigaction(SIGUSR1, &reopen_action, &previous_action) == 0;
+ const epee::scope_guard restore_reopen_signal([&] {
+ if (reopen_signal_installed)
+ sigaction(SIGUSR1, &previous_action, nullptr);
+ });
+ if (!reopen_signal_installed)
+ MWARNING("Failed to install SIGUSR1 log reopen handler");
+
+ std::atomic<bool> stop_reopen_thread{false};
+ std::thread reopen_thread([&] {
+ while (!stop_reopen_thread)
+ {
+ if (reopen_log_requested.exchange(false, std::memory_order_relaxed))
+ {
+ if (mlog_reopen())
+ MINFO("Reopened log file after SIGUSR1");
+ else
+ MERROR("Failed to reopen the log file after SIGUSR1");
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds{100});
+ }
+ });
+ const epee::scope_guard stop_reopen([&] {
+ stop_reopen_thread = true;
+ reopen_thread.join();
+ });
+#endif
+
std::unique_ptr<tools::wallet2> wal;
try
{Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.