This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/develop by this push:
new 7cd490a CELIX-410: Updates handling of thread prio/sched
configuration for ZMQ topics.
7cd490a is described below
commit 7cd490afaf8314c15e802c8c7d012eb168cc043c
Author: Pepijn Noltes <[email protected]>
AuthorDate: Tue Mar 19 12:46:20 2019 +0100
CELIX-410: Updates handling of thread prio/sched configuration for ZMQ
topics.
ZMQ will abort if a thread prio/sched is updated without permission. For
now check if user is root.
---
.../src/pubsub_zmq_topic_receiver.c | 35 ++++++++++++++++------
bundles/pubsub/test/meta_data/ping.properties | 5 ++--
2 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c
b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c
index c5c3530..7799f4c 100644
--- a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c
+++ b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c
@@ -740,26 +740,43 @@ static void
psa_zmq_initializeAllSubscribers(pubsub_zmq_topic_receiver_t *receiv
}
static void psa_zmq_setupZmqContext(pubsub_zmq_topic_receiver_t *receiver,
const celix_properties_t *topicProperties) {
+ //NOTE. ZMQ will abort when performing a sched_setscheduler without
permission.
+ //As result permission has to be checked first.
+ //TODO update this to use cap_get_pid and cap-get_flag instead of check
user is root (note adds dep to -lcap)
+ bool gotPermission = false;
+ if (getuid() == 0) {
+ gotPermission = true;
+ }
+
+
long prio = celix_properties_getAsLong(topicProperties,
PUBSUB_ZMQ_THREAD_REALTIME_PRIO, -1L);
if (prio > 0 && prio < 100) {
- zmq_ctx_set(receiver->zmqCtx, ZMQ_THREAD_PRIORITY, (int)prio);
+ if (gotPermission) {
+ zmq_ctx_set(receiver->zmqCtx, ZMQ_THREAD_PRIORITY, (int) prio);
+ } else {
+ L_INFO("Skipping configuration of thread prio to %i. No
permission\n", (int)prio);
+ }
}
- const char *shed = celix_properties_get(topicProperties,
PUBSUB_ZMQ_THREAD_REALTIME_SHED, NULL);
- if (shed != NULL) {
+ const char *sched = celix_properties_get(topicProperties,
PUBSUB_ZMQ_THREAD_REALTIME_SHED, NULL);
+ if (sched != NULL) {
int policy = ZMQ_THREAD_SCHED_POLICY_DFLT;
- if (strncmp("SCHED_OTHER", shed, 16) == 0) {
+ if (strncmp("SCHED_OTHER", sched, 16) == 0) {
policy = SCHED_OTHER;
- } else if (strncmp("SCHED_BATCH", shed, 16) == 0) {
+ } else if (strncmp("SCHED_BATCH", sched, 16) == 0) {
policy = SCHED_BATCH;
- } else if (strncmp("SCHED_IDLE", shed, 16) == 0) {
+ } else if (strncmp("SCHED_IDLE", sched, 16) == 0) {
policy = SCHED_IDLE;
- } else if (strncmp("SCHED_FIFO", shed, 16) == 0) {
+ } else if (strncmp("SCHED_FIFO", sched, 16) == 0) {
policy = SCHED_FIFO;
- } else if (strncmp("SCHED_RR", shed, 16) == 0) {
+ } else if (strncmp("SCHED_RR", sched, 16) == 0) {
policy = SCHED_RR;
}
- zmq_ctx_set(receiver->zmqCtx, ZMQ_THREAD_SCHED_POLICY, policy);
+ if (gotPermission) {
+ zmq_ctx_set(receiver->zmqCtx, ZMQ_THREAD_SCHED_POLICY, policy);
+ } else {
+ L_INFO("Skipping configuration of thread scheduling to %s. No
permission\n", sched);
+ }
}
}
diff --git a/bundles/pubsub/test/meta_data/ping.properties
b/bundles/pubsub/test/meta_data/ping.properties
index c9f48b7..96d2267 100644
--- a/bundles/pubsub/test/meta_data/ping.properties
+++ b/bundles/pubsub/test/meta_data/ping.properties
@@ -19,6 +19,7 @@ zmq.static.connect.urls=ipc:///tmp/pubsub-pingtest
udpmc.static.bind.port=50678
udpmc.static.connect.socket_addresses=224.100.0.1:50678
-#ZMQ aborts on not permitted -> thread.realtime.shed=SCHED_FIFO
-#thread.realtime.prio=50
+#note only effective if run as root
+thread.realtime.shed=SCHED_FIFO
+thread.realtime.prio=50