Merge pull request #396 from ebfe/freebsd

FreeBSD support
This commit is contained in:
Heather 2014-09-23 17:53:15 +04:00
commit 23c8581d95
8 changed files with 62 additions and 1 deletions

View file

@ -25,6 +25,7 @@ extern {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
extern { extern {
fn setgroups(size: libc::c_int, list: *const libc::gid_t) -> libc::c_int; fn setgroups(size: libc::c_int, list: *const libc::gid_t) -> libc::c_int;
} }
@ -151,6 +152,7 @@ fn set_main_group(group: &str) {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
fn set_groups(groups: Vec<libc::gid_t>) -> libc::c_int { fn set_groups(groups: Vec<libc::gid_t>) -> libc::c_int {
unsafe { unsafe {
setgroups(groups.len() as libc::c_int, setgroups(groups.len() as libc::c_int,

View file

@ -8,7 +8,12 @@ use self::libc::{
uid_t, uid_t,
gid_t, gid_t,
}; };
#[cfg(target_os = "macos")] use self::libc::{int32_t, time_t}; #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
use self::libc::time_t;
#[cfg(target_os = "macos")]
use self::libc::int32_t;
use self::libc::funcs::posix88::unistd::getgroups; use self::libc::funcs::posix88::unistd::getgroups;
use std::vec::Vec; use std::vec::Vec;
@ -18,6 +23,7 @@ use std::ptr::{null_mut, read};
use std::string::raw::from_buf; use std::string::raw::from_buf;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[repr(C)] #[repr(C)]
pub struct c_passwd { pub struct c_passwd {
pub pw_name: *const c_char, /* user name */ pub pw_name: *const c_char, /* user name */
@ -45,6 +51,7 @@ pub struct c_passwd {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[repr(C)] #[repr(C)]
pub struct utsname { pub struct utsname {
pub sysname: [c_char, ..256], pub sysname: [c_char, ..256],
@ -164,6 +171,7 @@ pub fn get_group_list(name: *const c_char, gid: gid_t) -> Vec<gid_t> {
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[inline(always)] #[inline(always)]
unsafe fn get_group_list_internal(name: *const c_char, gid: gid_t, groups: *mut gid_t, grcnt: *mut c_int) -> c_int { unsafe fn get_group_list_internal(name: *const c_char, gid: gid_t, groups: *mut gid_t, grcnt: *mut c_int) -> c_int {
getgrouplist(name, gid, groups, grcnt) getgrouplist(name, gid, groups, grcnt)

View file

@ -105,6 +105,7 @@ No Name Default Action Description
*/ */
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub static ALL_SIGNALS:[Signal<'static>, ..31] = [ pub static ALL_SIGNALS:[Signal<'static>, ..31] = [
Signal{ name: "HUP", value:1 }, Signal{ name: "HUP", value:1 },
Signal{ name: "INT", value:2 }, Signal{ name: "INT", value:2 },

View file

@ -91,3 +91,36 @@ mod utmpx {
} }
} }
#[cfg(target_os = "freebsd")]
mod utmpx {
use super::libc;
pub static DEFAULT_FILE : &'static str = "";
pub static UT_LINESIZE : uint = 16;
pub static UT_NAMESIZE : uint = 32;
pub static UT_IDSIZE : uint = 8;
pub static UT_HOSTSIZE : uint = 128;
pub static EMPTY : libc::c_short = 0;
pub static BOOT_TIME : libc::c_short = 1;
pub static OLD_TIME : libc::c_short = 2;
pub static NEW_TIME : libc::c_short = 3;
pub static USER_PROCESS : libc::c_short = 4;
pub static INIT_PROCESS : libc::c_short = 5;
pub static LOGIN_PROCESS : libc::c_short = 6;
pub static DEAD_PROCESS : libc::c_short = 7;
pub static SHUTDOWN_TIME : libc::c_short = 8;
#[repr(C)]
pub struct c_utmp {
pub ut_type : libc::c_short,
pub ut_tv : libc::timeval,
pub ut_id : [libc::c_char, ..UT_IDSIZE],
pub ut_pid : libc::pid_t,
pub ut_user : [libc::c_char, ..UT_NAMESIZE],
pub ut_line : [libc::c_char, ..UT_LINESIZE],
pub ut_host : [libc::c_char, ..UT_HOSTSIZE],
pub ut_spare : [libc::c_char, ..64],
}
}

View file

@ -32,6 +32,7 @@ extern {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
extern { extern {
fn sethostname(name: *const libc::c_char, namelen: libc::c_int) -> libc::c_int; fn sethostname(name: *const libc::c_char, namelen: libc::c_int) -> libc::c_int;
} }
@ -148,6 +149,7 @@ fn xgethostname() -> String {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
fn xsethostname(name: &str) { fn xsethostname(name: &str) {
let vec_name: Vec<libc::c_char> = name.bytes().map(|c| c as libc::c_char).collect(); let vec_name: Vec<libc::c_char> = name.bytes().map(|c| c as libc::c_char).collect();

View file

@ -249,6 +249,7 @@ fn pretty(possible_pw: Option<c_passwd>) {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
fn pline(possible_pw: Option<c_passwd>) { fn pline(possible_pw: Option<c_passwd>) {
let pw = if possible_pw.is_none() { let pw = if possible_pw.is_none() {
unsafe { read(getpwuid(getuid())) } unsafe { read(getpwuid(getuid())) }

View file

@ -43,9 +43,16 @@ extern {
fn setutxent(); fn setutxent();
fn endutxent(); fn endutxent();
#[cfg(target_os = "linux")]
#[cfg(target_os = "macs")]
fn utmpxname(file: *const c_char) -> c_int; fn utmpxname(file: *const c_char) -> c_int;
} }
#[cfg(target_os = "freebsd")]
unsafe extern fn utmpxname(_file: *const c_char) -> c_int {
0
}
pub fn uumain(args: Vec<String>) -> int { pub fn uumain(args: Vec<String>) -> int {
let program = args[0].clone(); let program = args[0].clone();
let opts = [ let opts = [

View file

@ -41,9 +41,16 @@ extern {
fn setutxent(); fn setutxent();
fn endutxent(); fn endutxent();
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
fn utmpxname(file: *const libc::c_char) -> libc::c_int; fn utmpxname(file: *const libc::c_char) -> libc::c_int;
} }
#[cfg(target_os = "freebsd")]
unsafe extern fn utmpxname(_file: *const libc::c_char) -> libc::c_int {
0
}
static NAME: &'static str = "users"; static NAME: &'static str = "users";
pub fn uumain(args: Vec<String>) -> int { pub fn uumain(args: Vec<String>) -> int {