wallet_rpc_server: reopen log file on `SIGUSR1`
What changed, and why it matters
This change adds a feature to the Monero wallet RPC server that lets administrators rotate log files on Unix-like systems by sending a SIGUSR1 signal. It mirrors an existing log-rotation capability already present in the main Monero daemon. There is no indication in the commit that this fixes a security vulnerability; it is a usability/operational improvement.
No security action required. Treat as a normal feature addition. If reviewing further, verify that mlog_reopen() is thread-safe with respect to other logging calls and that SIGUSR1 was not previously used for another purpose in wallet_rpc_server.
Security signals we found
Signal handler uses only lock-free atomic store (async-signal-safe)
Actual log reopening is deferred to a dedicated thread, not run in the signal handler
Previous SIGUSR1 action is restored on shutdown via scope_guard
Static assertion requires lock-free atomic bool
Evidence from the diff
The patch installs a SIGUSR1 signal handler in monero-wallet-rpc that sets an atomic flag. A background thread checks the flag every 100 ms and calls mlog_reopen() to reopen the configured log file. A scope_guard restores the previous signal handler and stops/joins the thread on shutdown. The README is updated to document that SIGUSR1 works for both monerod and monero-wallet-rpc. The implementation is straightforward and does not introduce obvious memory-safety or concurrency bugs from the diff alone.
Changed components
src/wallet/wallet_rpc_server.cppmonero-wallet-rpc log rotation behaviorREADME.md documentationInspect captured patch +55 / −2
### README.md
@@ -536,12 +536,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>
@@ -57,6 +59,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"
@@ -5188,6 +5191,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:
@@ -5204,6 +5220,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 18/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.