Skip to content

Commit 2ef0ed7

Browse files
ChristianBelloniChristian Belloni
andauthored
added set_bootstrap_prefix (#426)
Co-authored-by: Christian Belloni <[email protected]>
1 parent 900f272 commit 2ef0ed7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ pub mod router;
4040
mod test;
4141

4242
pub use bincode::{Error, ErrorKind};
43+
#[cfg(all(not(feature = "force-inprocess"), target_os = "macos"))]
44+
pub use platform::set_bootstrap_prefix;

src/platform/macos/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::mem;
2727
use std::ops::Deref;
2828
use std::ptr;
2929
use std::slice;
30-
use std::sync::RwLock;
30+
use std::sync::{OnceLock, RwLock};
3131
use std::time::Duration;
3232

3333
mod mach_sys;
@@ -36,8 +36,14 @@ mod mach_sys;
3636
/// this, we retry and spill to the heap.
3737
const SMALL_MESSAGE_SIZE: usize = 4096;
3838

39+
pub fn set_bootstrap_prefix(prefix: impl Into<String>) {
40+
BOOTSTRAP_PREFIX
41+
.set(prefix.into())
42+
.expect("set_bootstrap_prefix can only be called once")
43+
}
44+
3945
/// A string to prepend to our bootstrap ports.
40-
static BOOTSTRAP_PREFIX: &str = "org.rust-lang.ipc-channel.";
46+
pub(crate) static BOOTSTRAP_PREFIX: OnceLock<String> = OnceLock::new();
4147

4248
const BOOTSTRAP_NAME_IN_USE: kern_return_t = 1101;
4349
const BOOTSTRAP_SUCCESS: kern_return_t = 0;
@@ -265,7 +271,14 @@ impl OsIpcReceiver {
265271
let mut os_result;
266272
let mut name;
267273
loop {
268-
name = format!("{}{}", BOOTSTRAP_PREFIX, rand::rng().random::<i64>());
274+
name = format!(
275+
"{}{}",
276+
BOOTSTRAP_PREFIX
277+
.get()
278+
.map(AsRef::as_ref)
279+
.unwrap_or_else(|| "org.rust-lang.ipc-channel."),
280+
rand::rng().random::<i64>()
281+
);
269282
let c_name = CString::new(name.clone()).unwrap();
270283
os_result = bootstrap_register2(bootstrap_port, c_name.as_ptr(), right, 0);
271284
if os_result == BOOTSTRAP_NAME_IN_USE {

src/platform/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ mod macos;
3636
mod os {
3737
pub use super::macos::*;
3838
}
39+
#[cfg(all(not(feature = "force-inprocess"), target_os = "macos"))]
40+
pub use macos::set_bootstrap_prefix;
3941

4042
#[cfg(all(not(feature = "force-inprocess"), target_os = "windows"))]
4143
mod windows;

0 commit comments

Comments
 (0)