Port psyTerm to macOS and package a native app bundle
This commit is contained in:
+9
-35
@@ -175,7 +175,7 @@ impl Outbox {
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the headless server. The owner supplies a server-managed GUI zygote callback.
|
||||
/// Run the headless server. The caller handles platform-specific window launches.
|
||||
pub fn run(socket: &Path, open_window: impl FnMut(Option<String>) -> Result<()>) -> Result<()> {
|
||||
run_with_shell(socket, open_window, None)
|
||||
}
|
||||
@@ -200,7 +200,7 @@ fn run_with_shell(
|
||||
break;
|
||||
}
|
||||
};
|
||||
if !same_user(&stream) {
|
||||
if crate::launcher::verify_peer(&stream).is_err() {
|
||||
continue;
|
||||
}
|
||||
let reader = match stream.try_clone() {
|
||||
@@ -346,7 +346,7 @@ impl Server {
|
||||
{
|
||||
client
|
||||
.output
|
||||
.reliable(ServerMessage::Error(error.to_string()));
|
||||
.reliable(ServerMessage::Error(format!("{error:#}")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1092,34 +1092,6 @@ fn bind_socket(socket: &Path) -> Result<(SocketGuard, UnixListener)> {
|
||||
))
|
||||
}
|
||||
|
||||
fn same_user(stream: &UnixStream) -> bool {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let mut credentials = libc::ucred {
|
||||
pid: 0,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
};
|
||||
let mut len = std::mem::size_of_val(&credentials) as libc::socklen_t;
|
||||
// SAFETY: arguments point to initialized writable storage of the given length.
|
||||
let result = unsafe {
|
||||
libc::getsockopt(
|
||||
stream.as_raw_fd(),
|
||||
libc::SOL_SOCKET,
|
||||
libc::SO_PEERCRED,
|
||||
(&mut credentials as *mut libc::ucred).cast(),
|
||||
&mut len,
|
||||
)
|
||||
};
|
||||
result == 0 && credentials.uid == unsafe { libc::geteuid() }
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
let _ = stream;
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -1133,7 +1105,7 @@ mod tests {
|
||||
impl TestServer {
|
||||
fn start() -> Self {
|
||||
let directory = std::env::temp_dir().join(format!(
|
||||
"psyterm-server-test-{}-{}",
|
||||
"pt-s-{:x}-{:x}",
|
||||
std::process::id(),
|
||||
NEXT_TEST.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
@@ -1153,7 +1125,7 @@ mod tests {
|
||||
thread: Some(thread),
|
||||
};
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
while !test.socket.exists() {
|
||||
while UnixStream::connect(&test.socket).is_err() {
|
||||
assert!(Instant::now() < deadline);
|
||||
thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
@@ -1865,8 +1837,10 @@ mod tests {
|
||||
#[test]
|
||||
fn cwd_program_and_manual_names_follow_precedence_and_survive_detach() {
|
||||
let server = TestServer::start();
|
||||
let first_dir = server.socket.parent().unwrap().join("first");
|
||||
let second_dir = server.socket.parent().unwrap().join("second");
|
||||
// The OS reports the physical cwd; macOS TMPDIR typically starts with the /var symlink.
|
||||
let parent = fs::canonicalize(server.socket.parent().unwrap()).unwrap();
|
||||
let first_dir = parent.join("first");
|
||||
let second_dir = parent.join("second");
|
||||
fs::create_dir(&first_dir).unwrap();
|
||||
fs::create_dir(&second_dir).unwrap();
|
||||
let mut client = server.client();
|
||||
|
||||
Reference in New Issue
Block a user