Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS support by removing system dependencies #82

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading