mirror of https://github.com/oxen-io/oxen-mq.git
Add support for setting umask when binding
This is needed to be able to control the permissions of any created ipc sockets.
This commit is contained in:
parent
719a9b0b58
commit
59a41943d4
|
@ -6,7 +6,7 @@ include(GNUInstallDirs)
|
|||
|
||||
set(LOKIMQ_VERSION_MAJOR 1)
|
||||
set(LOKIMQ_VERSION_MINOR 1)
|
||||
set(LOKIMQ_VERSION_PATCH 4)
|
||||
set(LOKIMQ_VERSION_PATCH 5)
|
||||
set(LOKIMQ_VERSION "${LOKIMQ_VERSION_MAJOR}.${LOKIMQ_VERSION_MINOR}.${LOKIMQ_VERSION_PATCH}")
|
||||
message(STATUS "lokimq v${LOKIMQ_VERSION}")
|
||||
|
||||
|
|
|
@ -246,6 +246,13 @@ public:
|
|||
/// Allows you to set options on the internal zmq context object. For advanced use only.
|
||||
int set_zmq_context_option(int option, int value);
|
||||
|
||||
/** The umask to apply when constructing sockets (which affects any new ipc:// listening sockets
|
||||
* that get created). Does nothing if set to -1 (the default), and does nothing on Windows.
|
||||
* Note that the umask is applied temporarily during `start()`, so may affect other threads that
|
||||
* create files/directories at the same time as the start() call.
|
||||
*/
|
||||
int STARTUP_UMASK = -1;
|
||||
|
||||
private:
|
||||
|
||||
/// The lookup function that tells us where to connect to a peer, or empty if not found.
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
#include "lokimq-internal.h"
|
||||
#include "hex.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
extern "C" {
|
||||
#include <sys/stat.h>
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace lokimq {
|
||||
|
||||
void LokiMQ::proxy_quit() {
|
||||
|
@ -330,6 +336,12 @@ void LokiMQ::proxy_loop() {
|
|||
if (!workers.empty())
|
||||
throw std::logic_error("Internal error: proxy thread started with active worker threads");
|
||||
|
||||
#ifndef _WIN32
|
||||
int saved_umask = -1;
|
||||
if (STARTUP_UMASK >= 0)
|
||||
saved_umask = umask(STARTUP_UMASK);
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < bind.size(); i++) {
|
||||
auto& b = bind[i].second;
|
||||
zmq::socket_t listener{context, zmq::socket_type::router};
|
||||
|
@ -354,6 +366,12 @@ void LokiMQ::proxy_loop() {
|
|||
incoming_conn_index[conn_id] = connections.size() - 1;
|
||||
b.index = connections.size() - 1;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
if (saved_umask != -1)
|
||||
umask(saved_umask);
|
||||
#endif
|
||||
|
||||
pollitems_stale = true;
|
||||
|
||||
// Also add an internal connection to self so that calling code can avoid needing to
|
||||
|
|
Loading…
Reference in New Issue