Skip to content

Commit 58c4e5a

Browse files
committed
[#460] Add dev_permissions feature flag
1 parent ca22976 commit 58c4e5a

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
123123

124124
let publisher = service.publisher_builder().create()?;
125125

126-
while node.wait(CYCLE_TIME) != WaitEvent::TerminationRequest {
126+
while node.wait(CYCLE_TIME).is_ok() {
127127
let sample = publisher.loan_uninit()?;
128128
let sample = sample.write_payload(1234);
129129
sample.send()?;
@@ -150,7 +150,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
150150

151151
let subscriber = service.subscriber_builder().create()?;
152152

153-
while node.wait(CYCLE_TIME) != WaitEvent::TerminationRequest {
153+
while node.wait(CYCLE_TIME).is_ok() {
154154
while let Some(sample) = subscriber.receive()? {
155155
println!("received: {:?}", *sample);
156156
}
@@ -200,7 +200,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
200200
let notifier = event.notifier_builder().create()?;
201201

202202
let id = EventId::new(12);
203-
while node.wait(CYCLE_TIME) != WaitEvent::TerminationRequest {
203+
while node.wait(CYCLE_TIME).is_ok() {
204204
notifier.notify_with_custom_event_id(id)?;
205205

206206
println!("Trigger event with id {:?} ...", id);
@@ -227,7 +227,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
227227

228228
let listener = event.listener_builder().create()?;
229229

230-
while node.wait(Duration::ZERO) != WaitEvent::TerminationRequest {
230+
while node.wait(Duration::ZERO).is_ok() {
231231
if let Ok(Some(event_id)) = listener.timed_wait_one(CYCLE_TIME) {
232232
println!("event was triggered with id: {:?}", event_id);
233233
}
@@ -254,7 +254,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
254254

255255
let listener = event.listener_builder().create()?;
256256

257-
while node.wait(Duration::ZERO) != WaitEvent::TerminationRequest {
257+
while node.wait(Duration::ZERO).is_ok() {
258258
listener.timed_wait_all(
259259
|event_id| {
260260
println!("event was triggered with id: {:?}", event_id);

iceoryx2-cal/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ repository = { workspace = true }
1010
rust-version = { workspace = true }
1111
version = { workspace = true }
1212

13+
[features]
14+
# The permissions of all resources will be set to read, write, execute for everyone.
15+
# This shall not be used in production and is meant to be enabled in a docker environment
16+
# with inconsistent user configuration.
17+
dev_permissions = []
18+
1319
[dependencies]
1420
iceoryx2-bb-posix = { workspace = true }
1521
iceoryx2-bb-container = { workspace = true }

iceoryx2-cal/src/communication_channel/message_queue.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ pub struct Channel<T: Copy> {
3535
_phantom_data: PhantomData<T>,
3636
}
3737

38+
const INIT_PERMISSIONS: Permission = Permission::OWNER_WRITE;
39+
40+
#[cfg(not(feature = "dev_permissions"))]
41+
const FINAL_PERMISSIONS: Permission = Permission::OWNER_ALL;
42+
43+
#[cfg(feature = "dev_permissions")]
44+
const FINAL_PERMISSIONS: Permission = Permission::ALL;
45+
3846
impl<T: Copy + Debug> NamedConceptMgmt for Channel<T> {
3947
type Configuration = Configuration;
4048

@@ -257,7 +265,7 @@ impl<T: Copy + Debug> CommunicationChannelCreator<T, Channel<T>> for Creator<T>
257265

258266
let mut _shared_memory = match SharedMemoryBuilder::new(&full_name)
259267
.creation_mode(CreationMode::CreateExclusive)
260-
.permission(Permission::OWNER_WRITE)
268+
.permission(INIT_PERMISSIONS)
261269
.size(std::mem::size_of::<SharedConfiguration>())
262270
.create()
263271
{
@@ -281,9 +289,7 @@ impl<T: Copy + Debug> CommunicationChannelCreator<T, Channel<T>> for Creator<T>
281289
};
282290

283291
// we are finished with the setup and we open the channel for others to connect
284-
_shared_memory
285-
.set_permission(Permission::OWNER_READ | Permission::OWNER_WRITE)
286-
.unwrap();
292+
_shared_memory.set_permission(FINAL_PERMISSIONS).unwrap();
287293

288294
Ok(Receiver {
289295
name: self.channel_name,

iceoryx2-cal/src/dynamic_storage/posix_shared_memory.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ use std::sync::atomic::Ordering;
5959

6060
use self::dynamic_storage_configuration::DynamicStorageConfiguration;
6161

62+
const INIT_PERMISSIONS: Permission = Permission::OWNER_WRITE;
63+
64+
#[cfg(not(feature = "dev_permissions"))]
6265
const FINAL_PERMISSIONS: Permission = Permission::OWNER_ALL;
6366

67+
#[cfg(feature = "dev_permissions")]
68+
const FINAL_PERMISSIONS: Permission = Permission::ALL;
69+
6470
/// The builder of [`Storage`].
6571
#[derive(Debug)]
6672
pub struct Builder<'builder, T: Send + Sync + Debug> {
@@ -257,7 +263,7 @@ impl<'builder, T: Send + Sync + Debug> Builder<'builder, T> {
257263
// posix shared memory is always aligned to the greatest possible value (PAGE_SIZE)
258264
// therefore we do not have to add additional alignment space for T
259265
.size(std::mem::size_of::<Data<T>>() + self.supplementary_size)
260-
.permission(Permission::OWNER_WRITE)
266+
.permission(INIT_PERMISSIONS)
261267
.zero_memory(false)
262268
.has_ownership(self.has_ownership)
263269
.create()

iceoryx2/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ version = { workspace = true }
1616
logger_log = ["iceoryx2-bb-log/logger_log"]
1717
# Enables https://crates.io/crates/tracing as default logger
1818
logger_tracing = ["iceoryx2-bb-log/logger_tracing"]
19+
# The permissions of all resources will be set to read, write, execute for everyone.
20+
# This shall not be used in production and is meant to be enabled in a docker environment
21+
# with inconsistent user configuration.
22+
dev_permissions = ["iceoryx2-cal/dev_permissions"]
1923

2024
[dependencies]
2125
iceoryx2-bb-container = { workspace = true }

iceoryx2/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@
267267
//!
268268
//! # Feature Flags
269269
//!
270+
//! * `dev_permissions` - The permissions of all resources will be set to read, write, execute
271+
//! for everyone. This shall not be used in production and is meant to be enabled in a docker
272+
//! environment with inconsistent user configuration.
270273
//! * `logger_log` - Uses the [log crate](https://crates.io/crates/log) as default log backend
271274
//! * `logger_tracing` - Uses the [tracing crate](https://crates.io/crates/tracing) as default log
272275
//! backend

0 commit comments

Comments
 (0)