ipc, refactor: Add ProcessId type alias and use it
What changed, and why it matters
This is a straightforward code cleanup that renames the type used for process IDs from plain 'int' to a new 'ProcessId' alias. It makes the code compatible with a future library update that will support Windows, but does not change any actual behavior or fix any security issue.
No security action required; this is a benign refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces an ipc/util.h header defining mp::ProcessId as an alias for int when libmultiprocess is older than v14, and updates Process::spawn, Process::waitSpawned, and their implementations to use mp::ProcessId instead of int. This is a type-alias refactor in preparation for a future libmultiprocess version that will add Windows support. No functional logic is altered.
Changed components
src/ipc/interfaces.cppsrc/ipc/process.cppsrc/ipc/process.hsrc/ipc/util.hInspect captured patch +27 / −5
diff --git a/src/ipc/interfaces.cpp b/src/ipc/interfaces.cpp
index 71f1f4ee..73a616bf 100644
--- a/src/ipc/interfaces.cpp
+++ b/src/ipc/interfaces.cpp
@@ -62,7 +62,7 @@ public:
}
std::unique_ptr<interfaces::Init> spawnProcess(const char* new_exe_name) override
{
- int pid;
+ mp::ProcessId pid;
int fd = m_process->spawn(new_exe_name, m_process_argv0, pid);
LogDebug(::BCLog::IPC, "Process %s pid %i launched\n", new_exe_name, pid);
auto init = m_protocol->connect(fd);
diff --git a/src/ipc/process.cpp b/src/ipc/process.cpp
index dcde50e2..ec658a9a 100644
--- a/src/ipc/process.cpp
+++ b/src/ipc/process.cpp
@@ -32,7 +32,7 @@ namespace {
class ProcessImpl : public Process
{
public:
- int spawn(const std::string& new_exe_name, const fs::path& argv0_path, int& pid) override
+ int spawn(const std::string& new_exe_name, const fs::path& argv0_path, mp::ProcessId& pid) override
{
return mp::SpawnProcess(pid, [&](int fd) {
fs::path path = argv0_path;
@@ -41,7 +41,7 @@ public:
return std::vector<std::string>{fs::PathToString(path), "-ipcfd", strprintf("%i", fd)};
});
}
- int waitSpawned(int pid) override { return mp::WaitProcess(pid); }
+ int waitSpawned(mp::ProcessId pid) override { return mp::WaitProcess(pid); }
bool checkSpawned(int argc, char* argv[], int& fd) override
{
// If this process was not started with a single -ipcfd argument, it is
diff --git a/src/ipc/process.h b/src/ipc/process.h
index 67c69593..13a004d7 100644
--- a/src/ipc/process.h
+++ b/src/ipc/process.h
@@ -8,6 +8,7 @@
#include <util/fs.h>
#include <memory>
+#include <ipc/util.h>
#include <string>
namespace ipc {
@@ -25,10 +26,10 @@ public:
//! Spawn process and return socket file descriptor for communicating with
//! it.
- virtual int spawn(const std::string& new_exe_name, const fs::path& argv0_path, int& pid) = 0;
+ virtual int spawn(const std::string& new_exe_name, const fs::path& argv0_path, mp::ProcessId& pid) = 0;
//! Wait for spawned process to exit and return its exit code.
- virtual int waitSpawned(int pid) = 0;
+ virtual int waitSpawned(mp::ProcessId pid) = 0;
//! Parse command line and determine if current process is a spawned child
//! process. If so, return true and a file descriptor for communicating
diff --git a/src/ipc/util.h b/src/ipc/util.h
new file mode 100644
index 00000000..58912a85
--- /dev/null
+++ b/src/ipc/util.h
@@ -0,0 +1,21 @@
+// Copyright (c) The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_IPC_UTIL_H
+#define BITCOIN_IPC_UTIL_H
+
+#include <cstdint>
+#include <mp/util.h>
+#include <mp/version.h>
+
+namespace mp {
+// Definitions that can be deleted when libmultiprocess subtree is updated to
+// v14. Having these allows Bitcoin Core changes to be decoupled from
+// libmultiprocess changes so they don't have to be reviewed in a single PR.
+#if MP_MAJOR_VERSION < 14
+using ProcessId = int;
+#endif
+} // namespace mp
+
+#endif // BITCOIN_IPC_UTIL_H
Why this scored 15/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.