Make shmid an 8-digit hex number

This commit is contained in:
Alexey Rybalchenko 2020-06-29 12:00:29 +02:00
parent afe2dcaa02
commit 6dd0a44308
2 changed files with 7 additions and 4 deletions

View File

@ -12,7 +12,6 @@
#include <atomic>
#include <string>
#include <unordered_map>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
@ -113,8 +112,11 @@ struct RegionBlock
inline std::string buildShmIdFromSessionIdAndUserId(const std::string& sessionId)
{
std::string seed((std::to_string(geteuid()) + sessionId));
std::string shmId = picosha2::hash256_hex_string(seed);
shmId.resize(10, '_');
// generate a 8-digit hex value out of sha256 hash
std::vector<unsigned char> hash(4);
picosha2::hash256(seed.begin(), seed.end(), hash.begin(), hash.end());
std::string shmId = picosha2::bytes_to_hex_string(hash.begin(), hash.end());
return shmId;
}

View File

@ -57,7 +57,7 @@ class TransportFactory final : public fair::mq::TransportFactory
int numIoThreads = 1;
std::string sessionName = "default";
size_t segmentSize = 2000000000;
size_t segmentSize = 2ULL << 30;
bool autolaunchMonitor = false;
bool throwOnBadAlloc = true;
if (config) {
@ -71,6 +71,7 @@ class TransportFactory final : public fair::mq::TransportFactory
}
fShmId = buildShmIdFromSessionIdAndUserId(sessionName);
LOG(debug) << "Generated shmid '" << fShmId << "' out of session id '" << sessionName << "'.";
try {
if (zmq_ctx_set(fZMQContext, ZMQ_IO_THREADS, numIoThreads) != 0) {