mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #5733 from sylvestre/getegid_geteuid
use our getegid & geteuid wrappers function instead of libc calls
This commit is contained in:
commit
179f0a7c3c
4 changed files with 11 additions and 11 deletions
|
@ -19,7 +19,6 @@ use uucore::mode::get_umask;
|
|||
use uucore::perms::{wrap_chown, Verbosity, VerbosityLevel};
|
||||
use uucore::{format_usage, help_about, help_usage, show, show_error, show_if_err, uio_error};
|
||||
|
||||
use libc::{getegid, geteuid};
|
||||
use std::error::Error;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::fs;
|
||||
|
@ -29,6 +28,8 @@ use std::os::unix::fs::MetadataExt;
|
|||
use std::os::unix::prelude::OsStrExt;
|
||||
use std::path::{Path, PathBuf, MAIN_SEPARATOR};
|
||||
use std::process;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use uucore::process::{getegid, geteuid};
|
||||
|
||||
const DEFAULT_MODE: u32 = 0o755;
|
||||
const DEFAULT_STRIP_PROGRAM: &str = "strip";
|
||||
|
@ -959,12 +960,10 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> UResult<bool> {
|
|||
}
|
||||
} else {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
unsafe {
|
||||
if to_meta.uid() != geteuid() || to_meta.gid() != getegid() {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !diff(from.to_str().unwrap(), to.to_str().unwrap()) {
|
||||
return Ok(true);
|
||||
|
|
|
@ -17,7 +17,7 @@ path = "src/test.rs"
|
|||
[dependencies]
|
||||
clap = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
uucore = { workspace = true }
|
||||
uucore = { workspace = true, features = ["process"] }
|
||||
|
||||
[target.'cfg(target_os = "redox")'.dependencies]
|
||||
redox_syscall = { workspace = true }
|
||||
|
|
|
@ -17,6 +17,8 @@ use std::fs;
|
|||
use std::os::unix::fs::MetadataExt;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{UResult, USimpleError};
|
||||
#[cfg(not(windows))]
|
||||
use uucore::process::{getegid, geteuid};
|
||||
use uucore::{format_usage, help_about, help_section};
|
||||
|
||||
const ABOUT: &str = help_about!("test.md");
|
||||
|
@ -276,7 +278,7 @@ fn path(path: &OsStr, condition: &PathCondition) -> bool {
|
|||
|
||||
let geteuid = || {
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
let euid = unsafe { libc::geteuid() };
|
||||
let euid = geteuid();
|
||||
#[cfg(target_os = "redox")]
|
||||
let euid = syscall::geteuid().unwrap() as u32;
|
||||
|
||||
|
@ -285,7 +287,7 @@ fn path(path: &OsStr, condition: &PathCondition) -> bool {
|
|||
|
||||
let getegid = || {
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
let egid = unsafe { libc::getegid() };
|
||||
let egid = getegid();
|
||||
#[cfg(target_os = "redox")]
|
||||
let egid = syscall::getegid().unwrap() as u32;
|
||||
|
||||
|
|
|
@ -7,10 +7,9 @@ use std::ffi::OsString;
|
|||
use std::io;
|
||||
|
||||
use uucore::entries::uid2usr;
|
||||
use uucore::process::geteuid;
|
||||
|
||||
pub fn get_username() -> io::Result<OsString> {
|
||||
// SAFETY: getuid() does nothing with memory and is always successful.
|
||||
let uid = unsafe { libc::geteuid() };
|
||||
// uid2usr should arguably return an OsString but currently doesn't
|
||||
uid2usr(uid).map(Into::into)
|
||||
uid2usr(geteuid()).map(Into::into)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue