Skip to content

Commit

Permalink
Merge pull request #82 from t-koba/macos
Browse files Browse the repository at this point in the history
macOS support by removing system dependencies
  • Loading branch information
ryuichiueda authored Dec 17, 2023
2 parents 29b76cd + 7b54240 commit ca5c937
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/elements/command/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::env;

use nix::unistd::{execvpe, fork, ForkResult, Pid};
use nix::unistd::{execve, fork, ForkResult, Pid};
use nix::unistd;
use std::ffi::CString;
use std::process::exit;
Expand Down Expand Up @@ -222,7 +222,7 @@ impl SimpleCommand {
.map(|a| CString::new(a.to_string()).unwrap())
.collect();

let _ = execvpe(&cargs[0], &cargs, &envs);
let _ = execve(&cargs[0], &cargs, &envs);

eprintln!("Command not found: {:?}", &cargs[0]);
exit(127);
Expand Down
25 changes: 11 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ mod utils;
mod feeder;
mod debuginfo;

use std::{env, process, path};
use std::os::linux::fs::MetadataExt;
use std::{env, process};
use std::fs::{File,OpenOptions};
use std::io::Read;
use nix::libc;
use nix::unistd::isatty;
use nix::sys::utsname::uname;

use crate::core::ShellCore;
use crate::core::proc;
Expand All @@ -26,10 +27,9 @@ use crate::elements::script::Script;
use crate::file_descs::FileDescs;
use std::os::unix::io::IntoRawFd;

fn is_interactive(pid: u32) -> bool {
let std_path = format!("/proc/{}/fd/0", pid);
match path::Path::new(&std_path).metadata() {
Ok(metadata) => metadata.st_mode() == 8592,
fn is_interactive() -> bool {
match isatty(libc::STDIN_FILENO) {
Ok(atty) => atty,
Err(err) => panic!("{}", err),
}
}
Expand All @@ -44,12 +44,9 @@ fn read_bashrc(core: &mut ShellCore){
}

fn get_hostname() -> String{
if let Ok(mut file) = File::open("/etc/hostname") {

let mut fullname = String::new();
if let Ok(_) = file.read_to_string(&mut fullname) {
return fullname.trim_end().to_string();
}
if let Ok(uts) = uname() {
let fullname = uts.nodename().to_string_lossy();
return fullname.to_string();
}

"unknown".to_string()
Expand Down Expand Up @@ -121,7 +118,7 @@ fn main() {
core.set_var("HOSTNAME", &get_hostname());
core.set_var("SHELL", "rustybash");
core.set_var("BASH", &core.args[0].to_string());
if is_interactive(pid) {
if is_interactive() {
core.flags += "i";
}

Expand Down

0 comments on commit ca5c937

Please sign in to comment.