Skip to content

Commit

Permalink
Bail if macOS version is 12 or lower
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Apr 8, 2024
1 parent 20be825 commit 33ec8cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions talpid-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ log = { workspace = true }
once_cell = { workspace = true }
parking_lot = "0.12.0"
rand = "0.8.5"
talpid-platform-metadata = { path = "../talpid-platform-metadata" }
talpid-routing = { path = "../talpid-routing" }
talpid-tunnel = { path = "../talpid-tunnel" }
talpid-tunnel-config-client = { path = "../talpid-tunnel-config-client" }
Expand Down
23 changes: 23 additions & 0 deletions talpid-core/src/split_tunnel/macos/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ use std::{
sync::{Arc, Mutex},
time::Duration,
};
use talpid_platform_metadata::MacosVersion;
use tokio::io::{AsyncBufReadExt, BufReader};

const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(3);
const EARLY_FAIL_TIMEOUT: Duration = Duration::from_millis(500);

#[derive(thiserror::Error, Debug)]
pub enum Error {
/// Failed to detect macOS version
#[error("Failed to detect macOS version")]
DetectMacosVersion(#[source] io::Error),
/// Only macOS 13 and later is supported
#[error("Unsupported macOS version")]
UnsupportedMacosVersion,
/// Failed to start eslogger listener
#[error("Failed to start eslogger")]
StartMonitor(#[source] io::Error),
Expand Down Expand Up @@ -57,6 +64,7 @@ pub struct ProcessMonitorHandle {

impl ProcessMonitor {
pub async fn spawn() -> Result<ProcessMonitorHandle, Error> {
check_os_version_support()?;
let states = ProcessStates::new()?;

let mut cmd = tokio::process::Command::new("/usr/bin/eslogger");
Expand Down Expand Up @@ -456,3 +464,18 @@ fn parse_eslogger_error(stderr_str: &str) -> Option<Error> {
None
}
}

/// Check whether the current macOS version is supported, and return an error otherwise
fn check_os_version_support() -> Result<(), Error> {
match MacosVersion::new().map_err(Error::DetectMacosVersion) {
Ok(version) => {
if version.major_version() <= 12 {
return Err(Error::UnsupportedMacosVersion);
}
}
Err(error) => {
log::error!("Failed to detect macOS version: {error}");
}
}
Ok(())
}

0 comments on commit 33ec8cd

Please sign in to comment.