-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable utsname on MacOS #607
Comments
I see that |
@zsck try it and find out. If it does, submit a PR to enable it. Include in the PR a link to the relevant man page. |
utsname
in sys
" on macOS
I modified #[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
pub mod utsname; Now my program compiles and runs, however it terminates silently as soon as
I can see that my program terminated with status code Unfortunately I am not equipped to figure out how to resolve this issue. |
Interestingly, if I modify the wrapper for pub fn uname() -> UtsName {
unsafe {
let mut ret: UtsName = mem::uninitialized();
let retcode = ffi::uname(&mut ret as *mut UtsName);
println!("RETURN CODE: {}", retcode);
ret
}
} Then re-run my program, I now see the following output:
The value of |
@zsck Just wanted to point out that your documentation link is incorrect. It points to the docs for Linux (which is why that function exists). You really want to explore the docs here. Note the dropdown to select the Platform at the top of the page. This is common with multi-platform crates that have platform-specific functionality. Be sure to read the right docs! As to the actual issue, the proper place to bring this up actually isn't here, but in libc. As you've seen, nix just provides a safe wrapper around |
I am not 100% sure if this is in fact a problem with libc. I wrote the following code using libc, and it seems to work just fine. extern crate libc;
use std::mem;
fn main() {
println!("Getting name");
unsafe {
let mut name: libc::utsname = mem::uninitialized();
let ret_code = libc::uname(&mut name as *mut libc::utsname);
println!("RETCODE = {}", ret_code);
print!("version = ");
for i in 0..name.version.len() {
print!("{}", name.version[i] as u8 as char);
}
}
} The invocation of |
You didn't need to write code, just look at libc see and see where it's declared. What platforms do they support using it on? |
I don't see anything indicating that I don't see how it's a problem of libc's if I'm able to use |
There seems to be an assumption that |
@Somers You're probably right that the memory layout is incorrect in First off you can see that |
@Susurrus My concern isn't that libc's definition for OSX's |
Oh, man, our utsname code is completely wrong. We shouldn't have FFI definitions in our code. And really we should have a newtype and then pass that to the FFI function. As long as we specify it's |
Sorry, not completely wrong, but definitely not well written. |
I wish I could say that I would like to take care of this, but my use case for |
I'm doing a really quick experiment to try to invoke the
uname
function on macOS. Following the documentation, I wrote the code below.My
Cargo.toml
file points to version 0.8.1 ofnix
as a dependency. When I try to compile this program withcargo build
I get the following error:I'm running this on macOS 10.12.4 with rustc 1.17.0.
The text was updated successfully, but these errors were encountered: