1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

chmod, chroot, comm: fix build

This commit is contained in:
Arcterus 2015-01-09 16:51:51 -08:00
parent 4e0360c495
commit a12fd89cb2
8 changed files with 46 additions and 33 deletions

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "deps/time"] [submodule "deps/time"]
path = deps/time path = deps/time
url = https://github.com/rust-lang/time url = https://github.com/rust-lang/time
[submodule "deps/regex"]
path = deps/regex
url = https://github.com/rust-lang/regex

View file

@ -4,6 +4,7 @@ ENABLE_STRIP ?= n
# Binaries # Binaries
RUSTC ?= rustc RUSTC ?= rustc
CARGO ?= cargo
RM := rm RM := rm
# Install directories # Install directories
@ -177,7 +178,7 @@ define CRATE_BUILD
-include $(BUILDDIR)/$(1).d -include $(BUILDDIR)/$(1).d
$(BUILDDIR)/$($(1)_RLIB): $(SRCDIR)/$(1)/$(1).rs | $(BUILDDIR) deps $(BUILDDIR)/$($(1)_RLIB): $(SRCDIR)/$(1)/$(1).rs | $(BUILDDIR) deps
$(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --crate-type rlib --dep-info $(BUILDDIR)/$(1).d $$< --out-dir $(BUILDDIR) $(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --extern regex=$(BUILDDIR)/libregex.rlib --crate-type rlib --dep-info $(BUILDDIR)/$(1).d $$< --out-dir $(BUILDDIR)
endef endef
# Aliases build rule # Aliases build rule
@ -199,7 +200,7 @@ test_$(1): $(TEMPDIR)/$(1)/$(1)_test $(BUILDDIR)/$(1)
$(call command,cp $(BUILDDIR)/$(1) $(TEMPDIR)/$(1) && cd $(TEMPDIR)/$(1) && $$<) $(call command,cp $(BUILDDIR)/$(1) $(TEMPDIR)/$(1) && cd $(TEMPDIR)/$(1) && $$<)
$(TEMPDIR)/$(1)/$(1)_test: $(TESTDIR)/$(1).rs | $(TEMPDIR)/$(1) $(TEMPDIR)/$(1)/$(1)_test: $(TESTDIR)/$(1).rs | $(TEMPDIR)/$(1)
$(call command,$(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --test -o $$@ $$<) $(call command,$(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --extern regex=$(BUILDDIR)/libregex.rlib --test -o $$@ $$<)
$(TEMPDIR)/$(1): | $(TEMPDIR) $(TEMPDIR)/$(1): | $(TEMPDIR)
$(call command,cp -r $(TESTDIR)/fixtures/$(1) $$@ || mkdir $$@) $(call command,cp -r $(TESTDIR)/fixtures/$(1) $$@ || mkdir $$@)
@ -222,15 +223,21 @@ $(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS
# Dependencies # Dependencies
$(BUILDDIR)/.rust-crypto: $(BUILDDIR)/.rust-time | $(BUILDDIR) $(BUILDDIR)/.rust-crypto: $(BUILDDIR)/.rust-time | $(BUILDDIR)
cd $(BASEDIR)/deps/rust-crypto && cargo build --release cd $(BASEDIR)/deps/rust-crypto && $(CARGO) build --release
cp -r $(BASEDIR)/deps/rust-crypto/target/release/libcrypto*.rlib $(BUILDDIR)/libcrypto.rlib cp -r $(BASEDIR)/deps/rust-crypto/target/release/libcrypto*.rlib $(BUILDDIR)/libcrypto.rlib
@touch $@ @touch $@
$(BUILDDIR)/.rust-time: $(BUILDDIR)/.rust-time:
cd $(BASEDIR)/deps/time && cargo build --release cd $(BASEDIR)/deps/time && $(CARGO) build --release
cp -r $(BASEDIR)/deps/time/target/release/libtime*.rlib $(BUILDDIR)/libtime.rlib cp -r $(BASEDIR)/deps/time/target/release/libtime*.rlib $(BUILDDIR)/libtime.rlib
@touch $@ @touch $@
$(BUILDDIR)/.rust-regex:
cd $(BASEDIR)/deps/regex/regex_macros && $(CARGO) build --release
cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/libregex_macros* $(BUILDDIR)
cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/deps/libregex*.rlib $(BUILDDIR)/libregex.rlib
@touch $@
$(BUILDDIR)/mkmain: mkmain.rs | $(BUILDDIR) $(BUILDDIR)/mkmain: mkmain.rs | $(BUILDDIR)
$(RUSTC) $(RUSTCFLAGS) $< -o $@ $(RUSTC) $(RUSTCFLAGS) $< -o $@
@ -240,7 +247,7 @@ $(BUILDDIR)/mkuutils: mkuutils.rs | $(BUILDDIR)
$(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs $(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs
cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-time $(SRCDIR)/cksum/crc_table.rs deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-time $(BUILDDIR)/.rust-regex $(SRCDIR)/cksum/crc_table.rs
crates: crates:
echo $(EXES) echo $(EXES)

1
deps/regex vendored Submodule

@ -0,0 +1 @@
Subproject commit 094a68530a6550d5158988ec37afea75b95bbac9

View file

@ -10,12 +10,14 @@
*/ */
#![allow(unused_variables)] // only necessary while the TODOs still exist #![allow(unused_variables)] // only necessary while the TODOs still exist
#![feature(plugin)]
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
extern crate regex; extern crate regex;
#[macro_use] extern crate regex_macros; #[plugin] extern crate regex_macros;
use std::ffi::CString;
use std::io::fs; use std::io::fs;
use std::io::fs::PathExtensions; use std::io::fs::PathExtensions;
use std::io::IoError; use std::io::IoError;
@ -30,7 +32,7 @@ mod util;
const NAME: &'static str = "chmod"; const NAME: &'static str = "chmod";
const VERSION: &'static str = "1.0.0"; const VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int { pub fn uumain(args: Vec<String>) -> isize {
let program = args[0].clone(); let program = args[0].clone();
let opts = [ let opts = [
@ -88,7 +90,7 @@ Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
}); });
let cmode = let cmode =
if fmode.is_none() { if fmode.is_none() {
let mode = matches.free.remove(0).unwrap(); // there are at least two elements let mode = matches.free.remove(0);
match verify_mode(mode.as_slice()) { match verify_mode(mode.as_slice()) {
Ok(_) => Some(mode), Ok(_) => Some(mode),
Err(f) => { Err(f) => {
@ -143,7 +145,7 @@ fn verify_mode(mode: &str) -> Result<(), String> {
Ok(()) Ok(())
} }
fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve_root: bool, recursive: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), int> { fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve_root: bool, recursive: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), isize> {
let mut r = Ok(()); let mut r = Ok(());
for filename in files.iter() { for filename in files.iter() {
@ -179,8 +181,8 @@ fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve
r r
} }
fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), int> { fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), isize> {
let path = name.to_c_str(); let path = CString::from_slice(name.as_bytes());
match fmode { match fmode {
Some(mode) => { Some(mode) => {
if unsafe { libc::chmod(path.as_ptr(), mode) } == 0 { if unsafe { libc::chmod(path.as_ptr(), mode) } == 0 {
@ -210,7 +212,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
if levels.len() == 0 { if levels.len() == 0 {
levels = "a"; levels = "a";
} }
let change_str = cap.at(3).to_string() + "+"; let change_str = cap.at(3).unwrap().to_string() + "+";
let change = change_str.as_slice(); let change = change_str.as_slice();
let mut action = change.char_at(0); let mut action = change.char_at(0);
let mut rwx = 0; let mut rwx = 0;

View file

@ -14,7 +14,7 @@ extern crate libc;
use getopts::{optflag, optopt, getopts, usage}; use getopts::{optflag, optopt, getopts, usage};
use c_types::{get_pw_from_args, get_group}; use c_types::{get_pw_from_args, get_group};
use libc::funcs::posix88::unistd::{execvp, setuid, setgid}; use libc::funcs::posix88::unistd::{execvp, setuid, setgid};
use std::ffi::c_str_to_bytes; use std::ffi::{c_str_to_bytes, CString};
use std::io::fs::PathExtensions; use std::io::fs::PathExtensions;
use std::iter::FromIterator; use std::iter::FromIterator;
@ -38,7 +38,7 @@ extern {
static NAME: &'static str = "chroot"; static NAME: &'static str = "chroot";
static VERSION: &'static str = "1.0.0"; static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int { pub fn uumain(args: Vec<String>) -> isize {
let program = &args[0]; let program = &args[0];
let options = [ let options = [
@ -93,10 +93,10 @@ pub fn uumain(args: Vec<String>) -> int {
set_context(&newroot, &opts); set_context(&newroot, &opts);
unsafe { unsafe {
let executable = command[0].as_slice().to_c_str().into_inner(); let executable = CString::from_slice(command[0].as_bytes()).as_slice_with_nul().as_ptr();
let mut command_parts: Vec<*const i8> = command.iter().map(|x| x.to_c_str().into_inner()).collect(); let mut command_parts: Vec<*const i8> = command.iter().map(|x| CString::from_slice(x.as_bytes()).as_slice_with_nul().as_ptr()).collect();
command_parts.push(std::ptr::null()); command_parts.push(std::ptr::null());
execvp(executable as *const libc::c_char, command_parts.as_ptr() as *mut *const libc::c_char) as int execvp(executable as *const libc::c_char, command_parts.as_ptr() as *mut *const libc::c_char) as isize
} }
} }
@ -129,7 +129,7 @@ fn enter_chroot(root: &Path) {
let root_str = root.display(); let root_str = root.display();
std::os::change_dir(root).unwrap(); std::os::change_dir(root).unwrap();
let err = unsafe { let err = unsafe {
chroot(".".to_c_str().into_inner() as *const libc::c_char) chroot(CString::from_slice(b".").as_slice_with_nul().as_ptr() as *const libc::c_char)
}; };
if err != 0 { if err != 0 {
crash!(1, "cannot chroot to {}: {}", root_str, strerror(err).as_slice()) crash!(1, "cannot chroot to {}: {}", root_str, strerror(err).as_slice())

View file

@ -28,11 +28,11 @@ static VERSION: &'static str = "1.0.0";
#[inline] #[inline]
fn crc_update(crc: u32, input: u8) -> u32 { fn crc_update(crc: u32, input: u8) -> u32 {
(crc << 8) ^ CRC_TABLE[((crc >> 24) as uint ^ input as uint) & 0xFF] (crc << 8) ^ CRC_TABLE[((crc >> 24) as usize ^ input as usize) & 0xFF]
} }
#[inline] #[inline]
fn crc_final(mut crc: u32, mut length: uint) -> u32 { fn crc_final(mut crc: u32, mut length: usize) -> u32 {
while length != 0 { while length != 0 {
crc = crc_update(crc, length as u8); crc = crc_update(crc, length as u8);
length >>= 8; length >>= 8;
@ -42,7 +42,7 @@ fn crc_final(mut crc: u32, mut length: uint) -> u32 {
} }
#[inline] #[inline]
fn cksum(fname: &str) -> IoResult<(u32, uint)> { fn cksum(fname: &str) -> IoResult<(u32, usize)> {
let mut crc = 0u32; let mut crc = 0u32;
let mut size = 0u; let mut size = 0u;
@ -74,7 +74,7 @@ fn cksum(fname: &str) -> IoResult<(u32, uint)> {
} }
} }
pub fn uumain(args: Vec<String>) -> int { pub fn uumain(args: Vec<String>) -> isize {
let opts = [ let opts = [
getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"), getopts::optflag("V", "version", "output version information and exit"),

View file

@ -20,7 +20,7 @@ use std::path::Path;
static NAME : &'static str = "comm"; static NAME : &'static str = "comm";
static VERSION : &'static str = "1.0.0"; static VERSION : &'static str = "1.0.0";
fn mkdelim(col: uint, opts: &getopts::Matches) -> String { fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
let mut s = String::new(); let mut s = String::new();
let delim = match opts.opt_str("output-delimiter") { let delim = match opts.opt_str("output-delimiter") {
Some(d) => d.clone(), Some(d) => d.clone(),
@ -52,8 +52,8 @@ enum LineReader {
impl LineReader { impl LineReader {
fn read_line(&mut self) -> IoResult<String> { fn read_line(&mut self) -> IoResult<String> {
match self { match self {
&LineReader::Stdin(ref mut r) => r.read_line(), &mut LineReader::Stdin(ref mut r) => r.read_line(),
&LineReader::FileIn(ref mut r) => r.read_line(), &mut LineReader::FileIn(ref mut r) => r.read_line(),
} }
} }
} }
@ -107,7 +107,7 @@ fn open_file(name: &str) -> IoResult<LineReader> {
} }
} }
pub fn uumain(args: Vec<String>) -> int { pub fn uumain(args: Vec<String>) -> isize {
let opts = [ let opts = [
getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"), getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"),
getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"), getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"),

View file

@ -167,15 +167,15 @@ pub fn get_group(groupname: &str) -> Option<c_group> {
pub fn get_group_list(name: *const c_char, gid: gid_t) -> Vec<gid_t> { pub fn get_group_list(name: *const c_char, gid: gid_t) -> Vec<gid_t> {
let mut ngroups: c_int = 32; let mut ngroups: c_int = 32;
let mut groups: Vec<gid_t> = Vec::with_capacity(ngroups as uint); let mut groups: Vec<gid_t> = Vec::with_capacity(ngroups as usize);
if unsafe { get_group_list_internal(name, gid, groups.as_mut_ptr(), &mut ngroups) } == -1 { if unsafe { get_group_list_internal(name, gid, groups.as_mut_ptr(), &mut ngroups) } == -1 {
groups.reserve(ngroups as uint); groups.reserve(ngroups as usize);
unsafe { get_group_list_internal(name, gid, groups.as_mut_ptr(), &mut ngroups); } unsafe { get_group_list_internal(name, gid, groups.as_mut_ptr(), &mut ngroups); }
} else { } else {
groups.truncate(ngroups as uint); groups.truncate(ngroups as usize);
} }
unsafe { groups.set_len(ngroups as uint); } unsafe { groups.set_len(ngroups as usize); }
groups groups
} }
@ -199,18 +199,18 @@ unsafe fn get_group_list_internal(name: *const c_char, gid: gid_t, groups: *mut
} }
} }
pub fn get_groups() -> Result<Vec<gid_t>, uint> { pub fn get_groups() -> Result<Vec<gid_t>, usize> {
let ngroups = unsafe { getgroups(0, null_mut()) }; let ngroups = unsafe { getgroups(0, null_mut()) };
if ngroups == -1 { if ngroups == -1 {
return Err(os::errno()); return Err(os::errno());
} }
let mut groups : Vec<gid_t>= repeat(0).take(ngroups as uint).collect(); let mut groups : Vec<gid_t>= repeat(0).take(ngroups as usize).collect();
let ngroups = unsafe { getgroups(ngroups, groups.as_mut_ptr()) }; let ngroups = unsafe { getgroups(ngroups, groups.as_mut_ptr()) };
if ngroups == -1 { if ngroups == -1 {
Err(os::errno()) Err(os::errno())
} else { } else {
groups.truncate(ngroups as uint); groups.truncate(ngroups as usize);
Ok(groups) Ok(groups)
} }
} }