Fix compile on x86_64
Co-authored-by: weishu <twsxtd@gmail.com> Signed-off-by: Tools-app <localhost.hutao@gmail.com>
This commit is contained in:
@@ -8,7 +8,12 @@ use libc::c_int;
|
|||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::{env, ffi::CStr, path::PathBuf, process::Command};
|
use std::{
|
||||||
|
env,
|
||||||
|
ffi::{CStr, CString},
|
||||||
|
path::PathBuf,
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use crate::ksucalls::get_wrapped_fd;
|
use crate::ksucalls::get_wrapped_fd;
|
||||||
@@ -230,10 +235,9 @@ pub fn root_shell() -> Result<()> {
|
|||||||
if free_idx < matches.free.len() {
|
if free_idx < matches.free.len() {
|
||||||
let name = &matches.free[free_idx];
|
let name = &matches.free[free_idx];
|
||||||
uid = unsafe {
|
uid = unsafe {
|
||||||
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
|
let pw = CString::new(name.as_str())
|
||||||
let pw = libc::getpwnam(name.as_ptr()).as_ref();
|
.ok()
|
||||||
#[cfg(target_arch = "x86_64")]
|
.and_then(|c_name| libc::getpwnam(c_name.as_ptr()).as_ref());
|
||||||
let pw = libc::getpwnam(name.as_ptr() as *const i8).as_ref();
|
|
||||||
|
|
||||||
pw.map_or_else(|| name.parse::<u32>().unwrap_or(0), |pw| pw.pw_uid)
|
pw.map_or_else(|| name.parse::<u32>().unwrap_or(0), |pw| pw.pw_uid)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user