mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
shmmonitor: allow getting shmids based on session/userid
This commit is contained in:
parent
2c7c46f2fd
commit
30e81d58f8
|
@ -195,9 +195,9 @@ struct RegionBlock
|
||||||
|
|
||||||
// find id for unique shmem name:
|
// find id for unique shmem name:
|
||||||
// a hash of user id + session id, truncated to 8 characters (to accommodate for name size limit on some systems (MacOS)).
|
// a hash of user id + session id, truncated to 8 characters (to accommodate for name size limit on some systems (MacOS)).
|
||||||
inline std::string makeShmIdStr(const std::string& sessionId)
|
inline std::string makeShmIdStr(const std::string& sessionId, const std::string& userId)
|
||||||
{
|
{
|
||||||
std::string seed((std::to_string(geteuid()) + sessionId));
|
std::string seed(userId + sessionId);
|
||||||
// generate a 8-digit hex value out of sha256 hash
|
// generate a 8-digit hex value out of sha256 hash
|
||||||
std::vector<unsigned char> hash(4);
|
std::vector<unsigned char> hash(4);
|
||||||
picosha2::hash256(seed.begin(), seed.end(), hash.begin(), hash.end());
|
picosha2::hash256(seed.begin(), seed.end(), hash.begin(), hash.end());
|
||||||
|
@ -205,6 +205,11 @@ inline std::string makeShmIdStr(const std::string& sessionId)
|
||||||
return picosha2::bytes_to_hex_string(hash.begin(), hash.end());
|
return picosha2::bytes_to_hex_string(hash.begin(), hash.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string makeShmIdStr(const std::string& sessionId)
|
||||||
|
{
|
||||||
|
return makeShmIdStr(sessionId, std::to_string(geteuid()));
|
||||||
|
}
|
||||||
|
|
||||||
inline uint64_t makeShmIdUint64(const std::string& sessionId)
|
inline uint64_t makeShmIdUint64(const std::string& sessionId)
|
||||||
{
|
{
|
||||||
std::string shmId = makeShmIdStr(sessionId);
|
std::string shmId = makeShmIdStr(sessionId);
|
||||||
|
|
|
@ -80,6 +80,8 @@ int main(int argc, char** argv)
|
||||||
bool runAsDaemon = false;
|
bool runAsDaemon = false;
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
bool cleanOnExit = false;
|
bool cleanOnExit = false;
|
||||||
|
bool getShmId = false;
|
||||||
|
int userId = -1;
|
||||||
|
|
||||||
options_description desc("Options");
|
options_description desc("Options");
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
|
@ -94,6 +96,8 @@ int main(int argc, char** argv)
|
||||||
("debug,b" , value<bool>(&debug)->implicit_value(true), "Debug - Print a list of messages)")
|
("debug,b" , value<bool>(&debug)->implicit_value(true), "Debug - Print a list of messages)")
|
||||||
("clean-on-exit,e", value<bool>(&cleanOnExit)->implicit_value(true), "Perform cleanup on exit")
|
("clean-on-exit,e", value<bool>(&cleanOnExit)->implicit_value(true), "Perform cleanup on exit")
|
||||||
("interval" , value<unsigned int>(&intervalInMS)->default_value(100), "Output interval for interactive/view-only mode")
|
("interval" , value<unsigned int>(&intervalInMS)->default_value(100), "Output interval for interactive/view-only mode")
|
||||||
|
("get-shmid" , value<bool>(&getShmId)->implicit_value(true), "Translate given session id and user id to a shmem id (uses current user id if none provided)")
|
||||||
|
("user-id" , value<int>(&userId)->default_value(-1), "User id")
|
||||||
("help,h", "Print help");
|
("help,h", "Print help");
|
||||||
|
|
||||||
variables_map vm;
|
variables_map vm;
|
||||||
|
@ -110,7 +114,18 @@ int main(int argc, char** argv)
|
||||||
daemonize();
|
daemonize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shmId == "") {
|
if (getShmId) {
|
||||||
|
if (userId == -1) {
|
||||||
|
cout << "shmem id for session '" << sessionName << "' and current user id " << geteuid()
|
||||||
|
<< " is: " << makeShmIdStr(sessionName) << endl;
|
||||||
|
} else {
|
||||||
|
cout << "shmem id for session '" << sessionName << "' and user id " << userId
|
||||||
|
<< " is: " << makeShmIdStr(sessionName, to_string(userId)) << endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shmId.empty()) {
|
||||||
shmId = makeShmIdStr(sessionName);
|
shmId = makeShmIdStr(sessionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user