Skip to content
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

Add the GetPlatformInfo action #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ proc-mounts = { version = "0.2.4", optional = true }
# [1]: https://github.com/rust-lang/cargo/issues/1596
fuse = { version = "0.3.1", optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
cocoa = { git = "https://github.com/servo/core-foundation-rs.git", rev = "786895643140fa0ee4f913d7b4aeb0c4626b2085", optional = true }
objc = { version = "0.2", optional = true }
Comment on lines +49 to +50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem like a quite heavy dependencies, I wonder if there is a way to avoid these. Moreover, I would prefer not to depend on anything that is not on crates.io because of our internal build infrastructure.


[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_System_Diagnostics_Debug", "Win32_Storage_FileSystem", "Win32_System_LibraryLoader", "Win32_System_SystemInformation"], optional = true }
winreg = { version = "0.7.0", optional = true }

[dev-dependencies]
rand = { version = "0.8.5" }
tempfile = { version = "3.3.0" }

[target.'cfg(target_os = "linux")'.build-dependencies]
cc = { version = "1.0", optional = true }

[features]
default = [
"action-insttime",
Expand All @@ -62,6 +70,7 @@ default = [
"action-memsize",
"action-metadata",
"action-network",
"action-platform-info",
"action-stat",
"action-timeline",
]
Expand All @@ -74,6 +83,7 @@ action-listdir = []
action-memsize = ["dep:sysinfo"]
action-metadata = []
action-network = ["dep:netstat2", "dep:sysinfo"]
action-platform-info = ["dep:cc", "dep:cocoa", "dep:objc", "dep:windows"]
action-stat = []
action-timeline = ["dep:flate2", "dep:sha2"]

Expand Down
10 changes: 10 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
#[cfg(all(target_os = "linux", feature = "action-platform-info"))]
{
println!("cargo:rerun-if-changed=src/action/libc_version.c");

cc::Build::new()
.file("src/action/libc_version.c")
.compile("liblibc_version.a");
}
}
Comment on lines +1 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am affraid build script is not an option — this does not play well with our internal build infrastructure (for rrg-proto I already have to do some awkward workarounds).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can scrap the build script. The libc::gnu_get_libc_version function is now available in the standard library.

8 changes: 8 additions & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub mod memsize;
#[cfg(feature = "action-finder")]
pub mod finder;

#[cfg(feature = "action-platform-info")]
pub mod platform_info;

pub use error::{ParseArgsError, ParseArgsErrorKind, DispatchError};

/// Dispatches the given `request` to an appropriate action handler.
Expand All @@ -73,6 +76,11 @@ where
handle(session, request, self::metadata::handle)
}

#[cfg(feature = "action-platform-info")]
"GetPlatformInfo" => {
handle(session, request, self::platform_info::handle)
}

#[cfg(feature = "action-listdir")]
"ListDirectory" => {
handle(session, request, self::listdir::handle)
Expand Down
6 changes: 3 additions & 3 deletions src/action/insttime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ mod e2fs_utils {
///
/// This function returns `None` in case of errors.
#[cfg(target_os = "linux")]
fn get_install_time() -> Option<SystemTime> {
pub fn get_install_time() -> Option<SystemTime> {
// First, check the creation time of the root. Rust implementation of
// `Metadata::created()` on Linux utilizes `statx` syscall, so this
// method will work only on kernels >= 4.11.
Expand Down Expand Up @@ -221,7 +221,7 @@ fn get_install_time() -> Option<SystemTime> {
///
/// This function returns `None` in case of errors.
#[cfg(target_os = "macos")]
fn get_install_time() -> Option<SystemTime> {
pub fn get_install_time() -> Option<SystemTime> {
// Here, we use the same way as Python version of GRR client does. We just
// check the modification time for some of the paths.
const CANDIDATES: [&str; 3] = [
Expand All @@ -239,7 +239,7 @@ fn get_install_time() -> Option<SystemTime> {
///
/// This function returns `None` in case of errors.
#[cfg(target_os = "windows")]
fn get_install_time() -> Option<SystemTime> {
pub fn get_install_time() -> Option<SystemTime> {
use winreg::RegKey;

// Don't use winreg::enums::KEY_WOW64_64KEY since it breaks on Windows 2000.
Expand Down
14 changes: 14 additions & 0 deletions src/action/libc_version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <features.h>
#ifdef __GNU_LIBRARY__
#include <gnu/libc-version.h>
#else
#include <stddef.h>
#endif

const char *libc_version(void) {
#ifdef __GNU_LIBRARY__
return gnu_get_libc_version();
#else
return NULL;
#endif
}
Comment on lines +1 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit over libc::gnu_get_libc_version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, excellent. I did not know that the gnu_get_* APIs were added recently

rust-lang/libc@f415078

Loading