Skip to content

Commit

Permalink
CI: instead using libc crate
Browse files Browse the repository at this point in the history
  • Loading branch information
bxb100 committed Nov 16, 2024
1 parent b92fe97 commit 29df1c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 3 additions & 2 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ unicode-width = "0.2.0"
url = { version = "2.5.2", features = ["serde"] }
which = "6.0.3"
serde_json = "1.0.132"
libc = "0.2.162"

[dev-dependencies]
assert_fs = "1.1.2"
Expand Down
26 changes: 18 additions & 8 deletions src/languages/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use serde_json::Value;
use std::borrow::Cow;
use std::collections::HashMap;
use std::ffi::OsStr;
use std::panic::catch_unwind;
use std::path::Path;
use std::sync::Arc;
use tokio::process::Command;
Expand Down Expand Up @@ -105,9 +104,26 @@ impl Docker {
path.to_string_lossy()
}

/// This aim to run as non-root user
///
/// ## Windows:
///
/// no way, see <https://docs.docker.com/desktop/setup/install/windows-permission-requirements/>
///
/// ## Other Unix Platform
///
/// see <https://stackoverflow.com/questions/57951893/how-to-determine-the-effective-user-id-of-a-process-in-rust>
fn get_docker_user() -> Option<[String; 2]> {
catch_unwind(|| unsafe { ["-u".to_owned(), format!("{}:{}", geteuid(), getegid())] }).ok()
if cfg!(target_os = "windows") {
None
} else {
unsafe {
Some([
"-u".to_owned(),
format!("{}:{}", libc::geteuid(), libc::geteuid()),
])
}
}
}

fn get_docker_tty(color: bool) -> Option<String> {
Expand Down Expand Up @@ -139,12 +155,6 @@ impl Docker {
}
}

#[link(name = "c")]
extern "C" {
fn geteuid() -> u32;
fn getegid() -> u32;
}

impl LanguageImpl for Docker {
fn name(&self) -> Language {
Language::Docker
Expand Down

0 comments on commit 29df1c5

Please sign in to comment.