cli: add new control server messages for wsl (#180438)

* cli: add new control server messages for wsl

* support cwd in spawn
This commit is contained in:
Connor Peet
2023-04-20 15:19:05 -07:00
committed by GitHub
parent fd5ccc856c
commit cedf1eaa25
4 changed files with 108 additions and 11 deletions

39
cli/src/util/os.rs Normal file
View File

@@ -0,0 +1,39 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
#[cfg(windows)]
pub fn os_release() -> Result<String, std::io::Error> {
// The windows API *had* nice GetVersionEx/A APIs, but these were deprecated
// in Winodws 8 and there's no newer win API to get version numbers. So
// instead read the registry.
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
let key = RegKey::predef(HKEY_LOCAL_MACHINE)
.open_subkey(r"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?;
let major: u32 = key.get_value("CurrentMajorVersionNumber")?;
let minor: u32 = key.get_value("CurrentMinorVersionNumber")?;
let build: String = key.get_value("CurrentBuild")?;
Ok(format!("{}.{}.{}", major, minor, build))
}
#[cfg(unix)]
pub fn os_release() -> Result<String, std::io::Error> {
use std::{ffi::CStr, mem};
unsafe {
let mut ret = mem::MaybeUninit::zeroed();
if libc::uname(ret.as_mut_ptr()) != 0 {
return Err(std::io::Error::last_os_error());
}
let ret = ret.assume_init();
let c_str: &CStr = CStr::from_ptr(ret.release.as_ptr());
Ok(c_str.to_string_lossy().into_owned())
}
}