allow an IPC socket to set which group it is owned by using SOCKET_GID similar to how STARTUP_UMASK is done.

This commit is contained in:
Jeff Becker 2020-09-08 13:15:11 -04:00 committed by Jason Rhinelander
parent 9467c4682c
commit 0c9eeeea43
2 changed files with 18 additions and 0 deletions

View File

@ -266,6 +266,10 @@ public:
*/
int STARTUP_UMASK = -1;
/** The gid that owns any sockets when constructed (same as umask)
*/
int SOCKET_GID = -1;
/// A special TaggedThreadID value that always refers to the proxy thread; the main use of this is
/// to direct very simple batch completion jobs to be executed directly in the proxy thread.
inline static constexpr TaggedThreadID run_in_proxy{-1};

View File

@ -12,6 +12,8 @@ extern "C" {
#ifndef _WIN32
extern "C" {
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
}
#endif
@ -384,6 +386,18 @@ void LokiMQ::proxy_loop() {
#ifndef _WIN32
if (saved_umask != -1)
umask(saved_umask);
// set socket gid if it is provided
if (SOCKET_GID != -1) {
for(size_t i = 0; i < bind.size(); i++) {
const address addr(bind[i].first);
if(addr.ipc()) {
if(chown(addr.socket.c_str(), -1, SOCKET_GID) == -1) {
throw std::runtime_error("cannot set group on " + addr.socket + ": " + strerror(errno));
}
}
}
}
#endif
pollitems_stale = true;