Skip to content

Commit

Permalink
Merge pull request #4 from zevweiss/add-hostname-to-etc-hosts
Browse files Browse the repository at this point in the history
Add guest hostname to /etc/hosts
  • Loading branch information
Andrea Righi authored Nov 19, 2023
2 parents d359e95 + a1eb25c commit 6b4f5c1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,24 @@ fn generate_sudoers() -> io::Result<()> {
Ok(())
}

fn generate_hosts() -> io::Result<()> {
if let Ok(hostname) = env::var("virtme_hostname") {
std::fs::copy("/etc/hosts", "/tmp/hosts")?;
let mut h = OpenOptions::new()
.write(true)
.append(true)
.open("/tmp/hosts")?;
writeln!(h, "\n127.0.0.1 {}\n::1 {}", hostname, hostname)?;
utils::do_mount("/tmp/hosts", "/etc/hosts", "", libc::MS_BIND as usize, "");
}
Ok(())
}

fn override_system_files() {
generate_fstab().ok();
generate_shadow().ok();
generate_sudoers().ok();
generate_hosts().ok();
}

fn set_cwd() {
Expand Down

0 comments on commit 6b4f5c1

Please sign in to comment.