mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 21:17:46 +00:00
Merge pull request #495 from ebfe/fix-build-alpha
id, nice, nohup: fix build
This commit is contained in:
commit
ec44be6034
3 changed files with 45 additions and 46 deletions
67
src/id/id.rs
67
src/id/id.rs
|
@ -17,6 +17,7 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use std::ffi::c_str_to_bytes;
|
||||||
use std::ptr::read;
|
use std::ptr::read;
|
||||||
use libc::{
|
use libc::{
|
||||||
uid_t,
|
uid_t,
|
||||||
|
@ -136,8 +137,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
};
|
};
|
||||||
let gr = unsafe { getgrgid(id) };
|
let gr = unsafe { getgrgid(id) };
|
||||||
|
|
||||||
if nflag && gr.is_not_null() {
|
if nflag && !gr.is_null() {
|
||||||
let gr_name = unsafe { String::from_raw_buf(read(gr).gr_name as *const u8) };
|
let gr_name = unsafe { String::from_utf8_lossy(c_str_to_bytes(&read(gr).gr_name)).to_string() };
|
||||||
println!("{}", gr_name);
|
println!("{}", gr_name);
|
||||||
} else {
|
} else {
|
||||||
println!("{}", id);
|
println!("{}", id);
|
||||||
|
@ -155,9 +156,9 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
};
|
};
|
||||||
|
|
||||||
let pw = unsafe { getpwuid(id) };
|
let pw = unsafe { getpwuid(id) };
|
||||||
if nflag && pw.is_not_null() {
|
if nflag && !pw.is_null() {
|
||||||
let pw_name = unsafe {
|
let pw_name = unsafe {
|
||||||
String::from_raw_buf(read(pw).pw_name as *const u8)
|
String::from_utf8_lossy(c_str_to_bytes(&read(pw).pw_name)).to_string()
|
||||||
};
|
};
|
||||||
println!("{}", pw_name);
|
println!("{}", pw_name);
|
||||||
} else {
|
} else {
|
||||||
|
@ -195,26 +196,26 @@ fn pretty(possible_pw: Option<c_passwd>) {
|
||||||
if possible_pw.is_some() {
|
if possible_pw.is_some() {
|
||||||
let pw = possible_pw.unwrap();
|
let pw = possible_pw.unwrap();
|
||||||
|
|
||||||
let pw_name = unsafe { String::from_raw_buf(pw.pw_name as *const u8) };
|
let pw_name = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_name)).to_string() };
|
||||||
print!("uid\t{}\ngroups\t", pw_name);
|
print!("uid\t{}\ngroups\t", pw_name);
|
||||||
group(possible_pw, true);
|
group(possible_pw, true);
|
||||||
} else {
|
} else {
|
||||||
let login = unsafe { String::from_raw_buf(getlogin() as *const u8) };
|
let login = unsafe { String::from_utf8_lossy(c_str_to_bytes(&(getlogin() as *const i8))).to_string() };
|
||||||
let rid = unsafe { getuid() };
|
let rid = unsafe { getuid() };
|
||||||
let pw = unsafe { getpwuid(rid) };
|
let pw = unsafe { getpwuid(rid) };
|
||||||
|
|
||||||
let is_same_user = unsafe {
|
let is_same_user = unsafe {
|
||||||
String::from_raw_buf(read(pw).pw_name as *const u8) == login
|
String::from_utf8_lossy(c_str_to_bytes(&read(pw).pw_name)).to_string() == login
|
||||||
};
|
};
|
||||||
|
|
||||||
if pw.is_null() || is_same_user {
|
if pw.is_null() || is_same_user {
|
||||||
println!("login\t{}", login);
|
println!("login\t{}", login);
|
||||||
}
|
}
|
||||||
|
|
||||||
if pw.is_not_null() {
|
if !pw.is_null() {
|
||||||
println!(
|
println!(
|
||||||
"uid\t{}",
|
"uid\t{}",
|
||||||
unsafe { String::from_raw_buf(read(pw).pw_name as *const u8) })
|
unsafe { String::from_utf8_lossy(c_str_to_bytes(&read(pw).pw_name)).to_string() })
|
||||||
} else {
|
} else {
|
||||||
println!("uid\t{}\n", rid);
|
println!("uid\t{}\n", rid);
|
||||||
}
|
}
|
||||||
|
@ -222,10 +223,10 @@ fn pretty(possible_pw: Option<c_passwd>) {
|
||||||
let eid = unsafe { getegid() };
|
let eid = unsafe { getegid() };
|
||||||
if eid == rid {
|
if eid == rid {
|
||||||
let pw = unsafe { getpwuid(eid) };
|
let pw = unsafe { getpwuid(eid) };
|
||||||
if pw.is_not_null() {
|
if !pw.is_null() {
|
||||||
println!(
|
println!(
|
||||||
"euid\t{}",
|
"euid\t{}",
|
||||||
unsafe { String::from_raw_buf(read(pw).pw_name as *const u8) });
|
unsafe { String::from_utf8_lossy(c_str_to_bytes(&read(pw).pw_name)).to_string() });
|
||||||
} else {
|
} else {
|
||||||
println!("euid\t{}", eid);
|
println!("euid\t{}", eid);
|
||||||
}
|
}
|
||||||
|
@ -235,10 +236,10 @@ fn pretty(possible_pw: Option<c_passwd>) {
|
||||||
|
|
||||||
if rid != eid {
|
if rid != eid {
|
||||||
let gr = unsafe { getgrgid(rid) };
|
let gr = unsafe { getgrgid(rid) };
|
||||||
if gr.is_not_null() {
|
if !gr.is_null() {
|
||||||
println!(
|
println!(
|
||||||
"rgid\t{}",
|
"rgid\t{}",
|
||||||
unsafe { String::from_raw_buf(read(gr).gr_name as *const u8) });
|
unsafe { String::from_utf8_lossy(c_str_to_bytes(&read(gr).gr_name)).to_string() });
|
||||||
} else {
|
} else {
|
||||||
println!("rgid\t{}", rid);
|
println!("rgid\t{}", rid);
|
||||||
}
|
}
|
||||||
|
@ -257,12 +258,12 @@ fn pline(possible_pw: Option<c_passwd>) {
|
||||||
possible_pw.unwrap()
|
possible_pw.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let pw_name = unsafe { String::from_raw_buf(pw.pw_name as *const u8) };
|
let pw_name = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_name )).to_string()};
|
||||||
let pw_passwd = unsafe { String::from_raw_buf(pw.pw_passwd as *const u8) };
|
let pw_passwd = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_passwd)).to_string()};
|
||||||
let pw_class = unsafe { String::from_raw_buf(pw.pw_class as *const u8) };
|
let pw_class = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_class )).to_string()};
|
||||||
let pw_gecos = unsafe { String::from_raw_buf(pw.pw_gecos as *const u8) };
|
let pw_gecos = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_gecos )).to_string()};
|
||||||
let pw_dir = unsafe { String::from_raw_buf(pw.pw_dir as *const u8) };
|
let pw_dir = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_dir )).to_string()};
|
||||||
let pw_shell = unsafe { String::from_raw_buf(pw.pw_shell as *const u8) };
|
let pw_shell = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_shell )).to_string()};
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}:{}:{}:{}:{}:{}:{}:{}:{}:{}",
|
"{}:{}:{}:{}:{}:{}:{}:{}:{}:{}",
|
||||||
|
@ -286,11 +287,11 @@ fn pline(possible_pw: Option<c_passwd>) {
|
||||||
possible_pw.unwrap()
|
possible_pw.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let pw_name = unsafe { String::from_raw_buf(pw.pw_name as *const u8)};
|
let pw_name = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_name )).to_string()};
|
||||||
let pw_passwd = unsafe { String::from_raw_buf(pw.pw_passwd as *const u8)};
|
let pw_passwd = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_passwd)).to_string()};
|
||||||
let pw_gecos = unsafe { String::from_raw_buf(pw.pw_gecos as *const u8)};
|
let pw_gecos = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_gecos )).to_string()};
|
||||||
let pw_dir = unsafe { String::from_raw_buf(pw.pw_dir as *const u8)};
|
let pw_dir = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_dir )).to_string()};
|
||||||
let pw_shell = unsafe { String::from_raw_buf(pw.pw_shell as *const u8)};
|
let pw_shell = unsafe { String::from_utf8_lossy(c_str_to_bytes(&pw.pw_shell )).to_string()};
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}:{}:{}:{}:{}:{}:{}",
|
"{}:{}:{}:{}:{}:{}:{}",
|
||||||
|
@ -350,27 +351,27 @@ fn id_print(possible_pw: Option<c_passwd>,
|
||||||
print!(
|
print!(
|
||||||
"uid={}({})",
|
"uid={}({})",
|
||||||
uid,
|
uid,
|
||||||
unsafe { String::from_raw_buf(possible_pw.unwrap().pw_name as *const u8) });
|
unsafe { String::from_utf8_lossy(c_str_to_bytes(&possible_pw.unwrap().pw_name)).to_string() });
|
||||||
} else {
|
} else {
|
||||||
print!("uid={}", unsafe { getuid() });
|
print!("uid={}", unsafe { getuid() });
|
||||||
}
|
}
|
||||||
|
|
||||||
print!(" gid={}", gid);
|
print!(" gid={}", gid);
|
||||||
let gr = unsafe { getgrgid(gid) };
|
let gr = unsafe { getgrgid(gid) };
|
||||||
if gr.is_not_null() {
|
if !gr.is_null() {
|
||||||
print!(
|
print!(
|
||||||
"({})",
|
"({})",
|
||||||
unsafe { String::from_raw_buf(read(gr).gr_name as *const u8) });
|
unsafe { String::from_utf8_lossy(c_str_to_bytes(&read(gr).gr_name)).to_string() });
|
||||||
}
|
}
|
||||||
|
|
||||||
let euid = unsafe { geteuid() };
|
let euid = unsafe { geteuid() };
|
||||||
if p_euid && (euid != uid) {
|
if p_euid && (euid != uid) {
|
||||||
print!(" euid={}", euid);
|
print!(" euid={}", euid);
|
||||||
let pw = unsafe { getpwuid(euid) };
|
let pw = unsafe { getpwuid(euid) };
|
||||||
if pw.is_not_null() {
|
if !pw.is_null() {
|
||||||
print!(
|
print!(
|
||||||
"({})",
|
"({})",
|
||||||
unsafe { String::from_raw_buf(read(pw).pw_name as *const u8) });
|
unsafe { String::from_utf8_lossy(c_str_to_bytes(&read(pw).pw_name)).to_string() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,8 +380,8 @@ fn id_print(possible_pw: Option<c_passwd>,
|
||||||
print!(" egid={}", egid);
|
print!(" egid={}", egid);
|
||||||
unsafe {
|
unsafe {
|
||||||
let grp = getgrgid(egid);
|
let grp = getgrgid(egid);
|
||||||
if grp.is_not_null() {
|
if !grp.is_null() {
|
||||||
print!("({})", String::from_raw_buf(read(grp).gr_name as *const u8));
|
print!("({})", String::from_utf8_lossy(c_str_to_bytes(&read(grp).gr_name)).to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,9 +394,9 @@ fn id_print(possible_pw: Option<c_passwd>,
|
||||||
if !first { print!(",") }
|
if !first { print!(",") }
|
||||||
print!("{}", gr);
|
print!("{}", gr);
|
||||||
let group = unsafe { getgrgid(gr) };
|
let group = unsafe { getgrgid(gr) };
|
||||||
if group.is_not_null() {
|
if !group.is_null() {
|
||||||
let name = unsafe {
|
let name = unsafe {
|
||||||
String::from_raw_buf(read(group).gr_name as *const u8)
|
String::from_utf8_lossy(c_str_to_bytes(&read(group).gr_name)).to_string()
|
||||||
};
|
};
|
||||||
print!("({})", name);
|
print!("({})", name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use std::ffi::CString;
|
||||||
use std::io::IoError;
|
use std::io::IoError;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -101,12 +102,10 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
show_warning!("{}", IoError::last_error());
|
show_warning!("{}", IoError::last_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
let cstrs : Vec<CString> = matches.free.iter().map(|x| CString::from_slice(x.as_bytes())).collect();
|
||||||
let executable = matches.free[0].to_c_str().into_inner();
|
let mut args : Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
|
||||||
let mut args: Vec<*const i8> = matches.free.iter().map(|x| x.to_c_str().into_inner()).collect();
|
args.push(0 as *const c_char);
|
||||||
args.push(ptr::null());
|
unsafe { execvp(args[0], args.as_mut_ptr()); }
|
||||||
execvp(executable as *const c_char, args.as_ptr() as *mut *const c_char);
|
|
||||||
}
|
|
||||||
|
|
||||||
show_error!("{}", IoError::last_error());
|
show_error!("{}", IoError::last_error());
|
||||||
if os::errno() as c_int == libc::ENOENT { 127 } else { 126 }
|
if os::errno() as c_int == libc::ENOENT { 127 } else { 126 }
|
||||||
|
|
|
@ -13,9 +13,11 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use getopts::{optflag, getopts, usage};
|
use getopts::{optflag, getopts, usage};
|
||||||
|
use std::ffi::CString;
|
||||||
use std::io::stdio::{stdin_raw, stdout_raw, stderr_raw};
|
use std::io::stdio::{stdin_raw, stdout_raw, stderr_raw};
|
||||||
use std::io::{File, Open, Read, Append, Write};
|
use std::io::{File, Open, Read, Append, Write};
|
||||||
use std::os::unix::prelude::*;
|
use std::os::unix::prelude::*;
|
||||||
|
use libc::c_char;
|
||||||
use libc::funcs::posix88::unistd::{dup2, execvp};
|
use libc::funcs::posix88::unistd::{dup2, execvp};
|
||||||
use libc::consts::os::posix88::SIGHUP;
|
use libc::consts::os::posix88::SIGHUP;
|
||||||
use libc::funcs::posix01::signal::signal;
|
use libc::funcs::posix01::signal::signal;
|
||||||
|
@ -66,13 +68,10 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
|
|
||||||
if unsafe { _vprocmgr_detach_from_console(0) } != std::ptr::null() { crash!(2, "Cannot detach from console")};
|
if unsafe { _vprocmgr_detach_from_console(0) } != std::ptr::null() { crash!(2, "Cannot detach from console")};
|
||||||
|
|
||||||
unsafe {
|
let cstrs : Vec<CString> = opts.free.iter().map(|x| CString::from_slice(x.as_bytes())).collect();
|
||||||
// we ignore the memory leak here because it doesn't matter anymore
|
let mut args : Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
|
||||||
let executable = opts.free[0].as_slice().to_c_str().into_inner();
|
args.push(std::ptr::null());
|
||||||
let mut args: Vec<*const i8> = opts.free.iter().map(|x| x.to_c_str().into_inner()).collect();
|
unsafe { execvp(args[0], args.as_mut_ptr()) as isize }
|
||||||
args.push(std::ptr::null());
|
|
||||||
execvp(executable as *const libc::c_char, args.as_ptr() as *mut *const libc::c_char) as int
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_fds() {
|
fn replace_fds() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue